A command-line tool for cleaning up your Outlook/Microsoft 365 inbox using customizable rules.
- Authenticate with Microsoft Graph API using device code flow
- Define rules to process emails based on sender and/or subject patterns
- Actions include: archiving, deleting, or marking as read
- Interactive confirmation before applying changes
- Batch processing for better performance
- Cross-platform: works on Windows, macOS, and Linux
The easiest way to install Mailsweep is to download the pre-built binaries from the latest release page.
Choose the appropriate binary for your platform:
- Windows:
mailsweep-windows-amd64.exe
- macOS (Intel):
mailsweep-macos-amd64
- macOS (Apple Silicon):
mailsweep-macos-arm64
- Linux:
mailsweep-linux-amd64
After downloading, you may need to make the binary executable on macOS/Linux:
chmod +x mailsweep-macos-arm64
If you prefer to build from source, you'll need Rust installed:
# Clone the repository
git clone https://github.com/mortenscheel/mailsweep.git
cd mailsweep
# Build and install
cargo install --path .
-
Authenticate with your Microsoft account:
mailsweep auth login
Follow the instructions to complete the authentication flow.
-
Create your first rule:
# Add a rule to archive newsletters mailsweep rules add --name "Archive newsletters" --action archive --sender "newsletter" --sender "updates"
-
Process your inbox:
mailsweep clean
Review the matches and confirm to apply the actions.
Mailsweep stores rules and tokens in your user configuration directory:
- Linux/macOS:
~/.config/mailsweep/
- Windows:
%APPDATA%\mailsweep\
The rules file is stored as YAML in rules.yaml
.
# Archive emails from newsletters
- name: Archive newsletters
sender_contains:
- newsletter
- updates
action: archive
# Delete promotional emails
- name: Delete promotions
subject_contains:
- discount
- sale
- offer
action: delete
# Archive tech updates from company domain (requires both to match)
- name: Archive tech updates
sender_contains:
- @company.com
subject_contains:
- tech update
- technology news
action: archive
- Each rule must have at least one pattern for sender or subject (or both)
- Patterns are matched case-insensitively using a "contains" strategy
- If both
sender_contains
andsubject_contains
are specified, a message must match at least one pattern from each for the rule to apply - The first matching rule determines the action to take on a message
- Rules are processed in the order they appear in the file
# Start authentication flow with Microsoft Graph
mailsweep auth login
# Check if you're authenticated and view account info
mailsweep auth status
# Log out and remove stored tokens
mailsweep auth logout
# Display all current rules
mailsweep rules show
# Open rules in your default editor
mailsweep rules edit
# Get the path to your rules file
mailsweep rules path
# Validate your rules for errors
mailsweep rules check
# Reset rules to default (with confirmation)
mailsweep rules reset
# Reset without confirmation prompt
mailsweep rules reset --force
The rules add
command lets you create rules without editing the YAML file directly:
# Basic usage
mailsweep rules add --name "Rule name" --action <action> [--sender <pattern>...] [--subject <pattern>...]
# Available actions
# - archive
# - delete
# - mark_read (or markread)
# Examples:
# Archive newsletters
mailsweep rules add --name "Archive newsletters" --action archive --sender "newsletter" --sender "updates"
# Delete promotions
mailsweep rules add --name "Delete promotions" --action delete --subject "discount" --subject "sale"
# Mark as read (with both sender and subject patterns)
mailsweep rules add --name "Mark company announcements" --action mark_read --sender "@company.com" --subject "announcement"
You can specify multiple --sender
and --subject
patterns. Each parameter adds one pattern to the list.
# Process inbox with interactive confirmation
mailsweep clean
# Process inbox with a specific number of messages per page
# (Pagination still applies to fetch all messages)
mailsweep clean --max-messages 50
# Process inbox without confirmation prompt (for automation)
mailsweep clean --yes
-
Setup (first time only):
mailsweep auth login
-
Create Rules (either using the editor or command line):
# Edit rules in your editor mailsweep rules edit # Or add rules via command line mailsweep rules add --name "Archive newsletters" --action archive --sender "newsletter"
-
Validate Rules:
mailsweep rules check
-
Process Inbox:
mailsweep clean
-
Review and Confirm:
- Mailsweep will display matching messages with their actions
- Confirm to proceed or cancel to make changes
The rules file includes a YAML header with a schema reference for enhanced editing features:
# yaml-language-server: $schema=/path/to/your/config/dir/rules.schema.json
For VS Code users:
- Install the "YAML" extension by Red Hat
- Open your rules file (
mailsweep rules edit
) - The editor will provide auto-completion, validation, and documentation
- If you encounter authentication errors, try
mailsweep auth logout
followed bymailsweep auth login
- Check your account permissions for mail access
- Verify your rules with
mailsweep rules check
- Ensure that your rules match the expected email patterns
- Check that you have messages matching your rule criteria
- Ensure that the binary is in your PATH
- For Windows users, you may need to use
mailsweep.exe
instead ofmailsweep
MIT