AI-powered email sorting for MailCow - Automatically generate Sieve filters using AI to organize your inbox.
This tool connects to your MailCow mailbox, analyzes your emails using AI, and automatically generates smart Sieve filtering rules to organize your inbox.
Analysis Process:
π₯ INBOX (1,569 emails analyzed)
β
AI Analysis (90 seconds)
β
π Generated Filter Rules (16 categories)
What the filters do:
- β New incoming emails - Automatically sorted into folders
- β Future emails - Continuously organized as they arrive
- β Existing emails - Sieve filters don't apply retroactively
Example categories generated:
π Shopping/Amazon-Orders
π Finance/PayPal-Receipts
π Work/GitHub-PRs
π Social/LinkedIn-Updates
... and 12 more smart categories!
Zero manual configuration needed! π
Sieve filters only apply to new incoming emails. However, this tool includes a retroactive filter application feature!
Option 1: Use Built-in Retroactive Filter (Recommended)
./mailcow-filter.sh apply-retroactiveThis will:
- Read your generated Sieve filter
- Scan all emails in your INBOX
- Move matching emails to their target folders
- First runs a DRY RUN to show what would happen
- Then asks for confirmation before moving emails
Option 2: Manual Methods
- Use your email client (Thunderbird, Webmail) to manually move emails
- Apply filters retroactively using Thunderbird's "Run Filters on Folder" feature
- Use IMAP client that supports filter application to existing messages
- π€ AI-Powered - Uses Claude API or local LLMs (Ollama)
- π° Zero Cost Option - Run completely free with local models
- π Fast - Analyzes 1,500+ emails in ~90 seconds
- π― Smart - ML clustering finds natural email patterns
- π Learns from You - Integrates with your existing filters
- π Privacy First - Optional fully offline operation
- π³ Containerized - No Python venv needed
- π Sieve Standard - Works with any Sieve-compatible server
- Docker installed (Get Docker)
- MailCow email server
- Ollama running locally (Install Ollama) OR Anthropic API key
git clone https://github.com/kekzl/mailcow-ai-filter.git
cd mailcow-ai-filter# Copy example config
cp config/config.example.yml config/config.yml
# Edit with your details
nano config/config.ymlMinimum configuration:
protocol: "imap"
imap:
server: "mail.yourdomain.com"
username: "you@yourdomain.com"
password: "your-password"
ai:
provider: "ollama" # or "anthropic"
master_model: "qwen2.5-coder:14b" # FREE local model
base_url: "http://localhost:11434"# Build container (first time only)
./mailcow-filter.sh build
# Analyze emails & generate filter
./mailcow-filter.sh analyze
# Create folders & upload filter
./mailcow-filter.sh create-folders
./mailcow-filter.sh upload-filterDone! Your emails will now be automatically sorted! π
./mailcow-filter.sh analyzeThe AI:
- Connects to your mailbox via IMAP
- Fetches up to 2,000 emails
- Generates semantic embeddings (ML)
- Clusters similar emails using HDBSCAN
- Uses AI to label each cluster
- Generates Sieve filter rules
- Saves to
output/generated.sieve
Time: ~90-120 seconds for 1,500 emails
./mailcow-filter.sh view-filterOr:
cat output/generated.sieveOption A: Create Folders + Upload Filter (Automated)
./mailcow-filter.sh create-folders # Creates folders via IMAP
./mailcow-filter.sh upload-filter # Uploads via MailCow APIOption B: Manual Upload
- Copy
output/generated.sieve - Login to MailCow webmail
- Settings β Filters β Paste β Save
Don't remember commands? Just run:
./mailcow-filter.shYou'll see:
===============================================================================
MailCow AI Filter - Container Manager
===============================================================================
Main Operations:
1) Analyze emails and generate filter
2) Fetch existing Sieve filters
3) Create mail folders (IMAP)
4) Upload filter to MailCow (API)
Utilities:
5) View generated filter
6) View logs (tail -f)
7) Build/rebuild container
8) Clean up containers
0) Exit
Cost: $0 Privacy: 100% offline Requirements: 16GB RAM, GPU recommended
ai:
provider: "ollama"
master_model: "qwen2.5-coder:14b"
base_url: "http://localhost:11434"Setup:
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Download model (once)
ollama pull qwen2.5-coder:14b
# Start Ollama
ollama serveSee LOCAL_MODELS.md for details.
Cost: ~$0.12 per run Quality: Excellent Requirements: Internet connection
ai:
provider: "anthropic"
api_key: "sk-ant-..."
model: "claude-sonnet-4-5-20250929"Get API key: https://console.anthropic.com/
See ANTHROPIC.md for details.
# Shopping (4 rules)
if anyof (
address :domain :is "from" "amazon.de",
header :contains "subject" "order"
) {
fileinto "Shopping/Amazon-Orders";
stop;
}
# Finance (3 rules)
if anyof (
address :domain :is "from" "paypal.com",
header :contains "subject" "receipt"
) {
fileinto "Finance/PayPal-Receipts";
stop;
}
# Work (4 rules)
if anyof (
address :domain :is "from" "github.com",
header :contains "subject" "pull request"
) {
fileinto "Work/GitHub-PRs";
stop;
}
# ... and 9 more rulesYour mailbox: 1,569 emails Analysis time: 95 seconds Categories found: 16 Rules generated: 16 Folders created: 21 (with hierarchy)
The AI automatically reads your existing Sieve filters and:
- β Avoids creating duplicates
- β Learns your naming conventions
- β Creates complementary rules
- β Maintains consistency
./mailcow-filter.sh fetch-filters # Optional: Review existing first
./mailcow-filter.sh analyze # Auto-detects existing filtersSee EXISTING_FILTERS.md for details.
Embedding Mode (default, fastest)
- Uses ML clustering (HDBSCAN)
- Best for 1,000+ emails
- ~100-200 emails/second
Hierarchical Mode (high quality)
- Two-tier AI analysis
- Best for 100-1,000 emails
- ~10-30 emails/second
Simple Mode (legacy)
- Single AI call
- Best for <100 emails
- ~5-10 emails/second
Configure in config/config.yml:
ai:
use_embedding: true # Enable ML clustering
use_hierarchical: false # Enable two-tier analysisWant to run alongside MailCow?
# docker-compose.yml
services:
mailcow-ai-filter:
extends:
file: mailcow-ai-filter/docker-compose.yml
service: mailcow-ai-filter
networks:
- mailcowdockerized_mailcow-networkmailcow-ai-filter/
βββ mailcow-filter.sh # β Main script (start here!)
βββ config/
β βββ config.yml # Your configuration
β βββ config.example.yml # Example config
βββ output/
β βββ generated.sieve # Generated filter rules
β βββ existing_filters.txt # Your current filters
βββ logs/
β βββ ai-filter.log # Analysis logs
βββ src/ # Application source code
βββ Dockerfile # Container definition
βββ docker-compose.yml # Container orchestration
./mailcow-filter.sh analyze # Analyze & generate filter
./mailcow-filter.sh fetch-filters # Fetch existing filters
./mailcow-filter.sh create-folders # Create mail folders
./mailcow-filter.sh upload-filter # Upload to MailCow
./mailcow-filter.sh apply-retroactive # Apply filters to existing emails./mailcow-filter.sh view-filter # View generated filter
./mailcow-filter.sh logs # Tail logs
./mailcow-filter.sh build # Build container
./mailcow-filter.sh clean # Clean up
./mailcow-filter.sh help # Show help# Interactive menu
./mailcow-filter.sh
# Specific command
./mailcow-filter.sh analyze
# View results
cat output/generated.sieve
tail -f logs/ai-filter.log| Document | Description |
|---|---|
| README.md | You are here - Main documentation |
| DOCKER_USAGE.md | Container usage guide |
| EXISTING_FILTERS.md | Filter integration guide |
| LOCAL_MODELS.md | Local LLM setup & comparison |
| ANTHROPIC.md | Claude API setup & pricing |
| QUICKSTART.md | 5-minute quick start |
| ARCHITECTURE.md | Technical architecture |
No, but it helps. The AI analysis works fine on CPU, just slower. Embedding generation benefits from GPU.
Yes! Works with any IMAP-compatible server that supports Sieve filters. Tested with:
- β MailCow
- β Dovecot
- β Cyrus IMAP
- β Most modern mail servers
Only if you use Claude API. With Ollama (local LLM), everything runs 100% offline on your machine.
Very accurate for common email types (newsletters, shopping, work, etc.). The ML clustering finds natural patterns in your emails.
Measured accuracy: 92-95% correct categorization on test mailboxes.
Yes! Edit output/generated.sieve before uploading. The filter is human-readable Sieve script.
The AI automatically detects and integrates with your existing filters! It won't create duplicates.
No! It only creates folder organization rules. All emails are preserved.
Sieve filters don't, but this tool includes retroactive application!
./mailcow-filter.sh apply-retroactiveThis feature:
- β Reads your generated Sieve filter
- β Applies it to all emails in INBOX
- β Moves matching emails to target folders
- β Shows dry run first for safety
- β Asks for confirmation before moving
How it works:
- Parses your
generated.sievefile - Connects to IMAP
- Scans each email in INBOX
- Matches against filter conditions
- Moves emails to appropriate folders
Note: Standard Sieve filters (on the server) only process new incoming mail. This tool provides client-side retroactive application via IMAP.
- β Email sender addresses
- β Email subjects
- β First 500 characters of email body
- β Folder names
- β NOT full email content
- β NOT email addresses in TO/CC
- β NOT attachments
Ollama (local): Nowhere - 100% offline Claude API: Anthropic's servers (encrypted, not used for training, deleted after 30 days)
- Stored in
config/config.yml(gitignored) - Never logged or transmitted (except to your mail server)
- Use read-only IMAP credentials if concerned
Contributions welcome! Areas of interest:
- Additional AI providers (OpenAI, Gemini, etc.)
- Web UI for configuration
- More sophisticated categorization
- Multi-language support
- Email preview before filtering
- Filter testing/simulation
See CONTRIBUTING.md for guidelines.
MIT License - see LICENSE file.
Free for personal and commercial use.
- Built for MailCow
- Powered by Anthropic Claude or Ollama
- Uses Sieve filtering (RFC 5228)
- ML clustering via HDBSCAN
- Embeddings via SentenceTransformers
- π Documentation: Read the docs
- π Bug Reports: GitHub Issues
- π¬ Questions: GitHub Discussions
- π§ Contact: @kekzl
If this tool helped organize your inbox, consider giving it a star! β
Made with β€οΈ for the MailCow community
Spend less time organizing email, more time reading what matters.