Privacy-first newsletter & junk mail cleaner for Gmail, Proton Mail and IMAP
Project description
MailShift
Privacy-first newsletter & junk mail cleaner for Gmail and Proton Mail.
Screenshots
Welcome Screen
Fast/Pro Mode and AI Model Selection
Features
- Multi provider support: Gmail (IMAP + App Password), Proton Mail (Requires Proton Bridge and a paid account), and Custom IMAP servers
- Proton Bridge preflight check: Proton mode probes
127.0.0.1:1143before IMAP login and guides you to start Bridge with a retry prompt - Attachment protection: Emails with attachments are never deleted
- Phishing detection limitation: This tool is not designed to detect and delete phishing emails. LLM models cannot reliably distinguish between phishing and legitimate emails.
- Fast-mode safety guards: Premium lifecycle expiry notices, verification code (OTP) emails, and Google Drive/cloud storage fullness alerts are force-kept in Fast mode before junk checks
- Fast-mode false-positive reduction: Blacklist matching excludes the sender address so legitimate automated senders (e.g.
no-reply@github.com) never trigger a junk decision; whitelist and safety-guard still consider the full sender context - Turkish case normalization: Fast-mode text is normalized (Turkish İ → i) before heuristic matching, fixing missed matches on properly-capitalised Turkish subjects
- Two scan modes:
fast– heuristic keyword matching (blacklist/whitelist)pro– two-phase analysis: heuristic + local Ollama LLM for smarter detection- Phase 1: Fast heuristic scan
- Phase 2: LLM verification on suspicious messages
- Robust decision parser accepts
SIL/TUTtext or JSON-style outputs and normalizes TurkishSİL/SILvariants - Ollama call uses
/api/chatwith structured JSON decision output for better small-model reliability - Pro mode disables model "thinking" output and uses a larger generation budget to prevent empty decision responses on 2B/4B models
- Robust decision parser accepts
- LM Studio auto-download support: If no LM Studio model is loaded, interactive Pro mode can trigger LM Studio's download API (
/api/v1/models/download) and track progress via/api/v1/models/download/status - LM Studio install options: If LM Studio is missing, interactive Pro mode can offer Windows install via
winget install ElementLabs.LMStudioor direct download from the official website (https://lmstudio.ai) - LM Studio server lifecycle: If LM Studio is installed but local server is not running, MailShift can auto-run
lms server start; if it started the server itself, it attemptslms server stopduring cleanup
- Body preview in Pro mode: Fetches email body content for better LLM analysis
- Dry-run default – preview before any deletion
- Dry-run history logs: Dry-run candidate results are also saved under
logs/cleanup_log_*.jsonfor later review - OS Keyring (Windows Credential Manager) — stores provider-based credentials securely via the
keyringlibrary for the interactive "reuse previous credentials" prompt. No longer stored in plain-text JSON files. - Unsubscribe suggestions: After a scan, MailShift detects
List-Unsubscribeheaders and offers three options — auto-unsubscribe from all detected senders, pick individual senders from a numbered list, or export all unsubscribe links to a JSON/TXT file for manual processing. Available in both dry-run and live modes. - Delete options: Permanent delete or move to Trash
- Resilient IMAP deletion: Delete/trash chunks and expunge retry with exponential back-off and automatic IMAP reconnect on SSL/EOF disconnects
- Concurrent fetching – multi-threaded IMAP operations
- Auto worker calculation – automatically calculates optimal thread count based on hardware
- Detects NVIDIA GPUs and Intel/AMD GPUs on Windows for Pro mode worker sizing
- Intel/AMD integrated GPU VRAM may be estimated from shared system RAM when dedicated VRAM is not exposed by the driver
- Manual worker input is safety-clamped to a backend-aware upper limit (VRAM/RAM/CPU caps); CLI prints a clear warning when clamped
- Fast mode does not use worker parallelism for analysis; configuration panel shows workers as "not used" to avoid misleading UX
- Pro mode auto-worker can learn from previous phase-2 metrics (timeout/error/p95 latency) and warm-start the next run from local
worker_profiles.jsonrecommendations - Power users can enable a one-time hardware worker probe with
--power-worker-probe; this preference is persisted inpower_user_settings.jsonand reused in later runs
- Cache support – skip re-fetching headers on repeat scans
- Rich CLI UI – progress bars, tables, colored output with Turkish/English
- Progress status labels are sanitized and shortened to stay single-line on narrow terminals (prevents duplicated-looking bars)
- Live progress uses ASCII status tags (
SIL/TUT) for more stable rendering across Windows terminals
- Cleanup history – view past deletion reports
- Logging – detailed operation logs
- Console warnings/errors are written to stderr to reduce interference with live progress rendering
Install
# Base install (recommended for all users)
pip install -r requirements.txt
# Optional: NVIDIA GPU telemetry for improved Pro-mode worker sizing
pip install "nvidia-ml-py>=13.595.45"
# Optional (package/source install): enable NVIDIA extra
pip install ".[nvidia]"
Usage
# Interactive mode
python main.py
# Non-interactive
python main.py --provider gmail --mode fast \
--username you@gmail.com --password "app-password"
# Custom IMAP server
python main.py --provider custom --mode fast \
--username you@example.com --password "your-password" \
--host imap.example.com --port 993
# Pro mode with LLM (two-phase analysis)
python main.py --provider gmail --mode pro \
--username you@gmail.com --password "app-password"
# Real deletion (disable dry-run)
python main.py --provider gmail --mode pro \
--username you@gmail.com --password "app-password" --no-dry-run
# Scan only a date window (IMAP SINCE/BEFORE)
python main.py --provider gmail --mode fast \
--username you@gmail.com --password "app-password" \
--since 2025-01-01 --before 2026-01-01
# Move to Trash instead of permanent delete
# (select option 2 when prompted)
# View cleanup history
python main.py --history
# Export scan results to CSV (before deletion)
python main.py --provider gmail --mode fast \
--username you@gmail.com --password "app-password" \
--export results.csv
# Export to JSON
python main.py --provider gmail --mode fast \
--username you@gmail.com --password "app-password" \
--export results.json
# Custom Ollama settings
python main.py --provider gmail --mode pro \
--username you@gmail.com --password "app-password" \
--ollama-url http://localhost:11434 \
--ollama-model qwen3.5:2B
# Custom system prompt for LLM
python main.py --provider gmail --mode pro \
--username you@gmail.com --password "app-password" \
--ollama-prompt "Custom prompt here"
Options
| Flag | Description | Default |
|---|---|---|
--provider |
gmail, proton or custom |
prompt |
--mode |
fast or pro |
prompt |
--username |
IMAP email/username | prompt |
--password |
App Password / Bridge password | prompt |
--host |
Custom IMAP server host | - |
--port |
Custom IMAP server port | 993 |
--use-ssl |
Use SSL for IMAP | enabled |
--dry-run |
Preview only (no deletion) | enabled |
--no-dry-run |
Actually delete emails | - |
--scan-limit |
Max messages to scan | all |
--since |
Scan emails on/after date (YYYY-MM-DD or DD-Mon-YYYY) |
- |
--before |
Scan emails before date (YYYY-MM-DD or DD-Mon-YYYY) |
- |
--ollama-url |
Ollama API URL | http://localhost:11434 |
--ollama-model |
Ollama model | qwen3.5:2B |
--ollama-prompt |
Custom system prompt for LLM | default prompt |
--workers |
Manual worker hint (Pro mode); values above safe limit are auto-clamped | auto |
--power-worker-probe |
Enable persisted power-user hardware probe for worker auto tuning | saved preference |
--no-power-worker-probe |
Disable persisted power-user hardware probe | saved preference |
--history |
Show cleanup history | - |
--export |
Export results to CSV/JSON | - |
--uninstall |
Remove MailShift from system | - |
- In interactive credential flow, MailShift can store credentials securely in the OS Keyring (e.g. Windows Credential Manager) using the
keyringlibrary. - Security: Passwords and sensitive data are handled using Pydantic
SecretStrin memory and stored in the encrypted system vault on disk. They are never saved in plain text files or accidentally printed in logs. - On later runs, if saved credentials exist, it asks whether to reuse previous values from the secure vault.
- You can still override credentials anytime via
--usernameand--passwordflags.
Keyword Management
Manage whitelist and blacklist keywords directly from CLI:
# Add a keyword to whitelist
python main.py --add-whitelist "fatura"
# Remove a keyword from whitelist
python main.py --remove-whitelist "fatura"
# Add a keyword to blacklist
python main.py --add-blacklist "spam"
# Remove a keyword from blacklist
python main.py --remove-blacklist "spam"
# List all keywords
python main.py --list-keywords
How It Works
- Connect – IMAP authentication to inbox
- Fetch – retrieve email headers (concurrent), body for Pro mode
- Analyze:
- Fast: whitelist-first flow (
whitelist.jsonmatch =>TUT), then suspicious check viablacklist.json(SIL) - Plus built-in safety guards that force
TUTfor premium expiry lifecycle notices, verification-code mails, and Drive/cloud storage quota-full alerts - Pro: two-phase analysis
- Phase 1: heuristic scan to find suspicious messages
- Phase 2: run matched mail through Ollama LLM for verification
- Fast: whitelist-first flow (
- Review – table of messages marked for deletion
- Unsubscribe (optional) – after review, MailShift checks for
List-UnsubscribeHTTP URLs and offers:- Auto-unsubscribe from all detected senders at once
- Select individual senders from a numbered list
- Export all links to
logs/unsubscribe_links.json(or a custom path) for manual processing
- Delete – permanent delete or move to Trash (empty Trash to permanent delete)
- Delete/trash operations automatically retry transient IMAP/SSL socket failures and reconnect before retrying
Files
main.py CLI entry point
engine.py IMAP engine + cache
config.py Config models + keyword patterns
models.py Data classes
hardware.py System info + worker calculation
fast_analyzer.py Heuristic analysis
pro_analyzer.py LLM analysis (Ollama)
database.py Cache storage (SQLite)
history.py Cleanup history + export
logger.py Logging utilities
ui.py Rich UI components
cli_utils.py CLI helper functions
blacklist.json Keywords → mark for deletion
whitelist.json Keywords → always keep
Gmail App Password
- Enable 2-Factor Authentication
- Go to https://myaccount.google.com/apppasswords
- Generate 16-char password for Mail
Proton Bridge
Run Proton Bridge locally, then connect with bridge credentials.
If Bridge is closed, MailShift now checks 127.0.0.1:1143 first and prompts you to start Bridge before retrying IMAP login.
Requirements
- Python 3.10+
- IMAP access to your email provider
- For Pro mode: Ollama running locally.
- On Windows with Intel GPU, MailShift starts
ollama servewithOLLAMA_INTEL_GPU=1(when auto-start is used) and requests higher GPU layer offload in Pro mode to reduce unintended CPU-only inference. - Intel/AMD GPU acceleration still depends on Ollama backend support/driver stack; if Ollama cannot offload, inference can continue on CPU even when MailShift detects the GPU.
- Power User Tip: Set the
OLLAMA_NUM_PARALLELenvironment variable to increase concurrent workers (default is 4). - Note: To close Ollama completely on Windows, you must use the Task Manager as it often runs without a visible window or system tray icon.
- On Windows with Intel GPU, MailShift starts
Ollama Kurulduktan Sonra Ne Yapmalıyım?
Pro mode seçiminde Ollama yüklü değilse MailShift otomatik kurulum önerebilir. Kurulum bittiğinde Pro mode'a devam edebilmek için şu adımları izleyin:
- Terminali kapatıp yeniden açın (PATH güncellemesi için).
- Ollama servisini başlatın:
ollama serve - MailShift'i yeniden çalıştırıp Pro mode seçin.
- Model seçim ekranında eksik önerilen model otomatik indirilir (manuel
ollama pullgerekmez).
Not: Uygulama bu adımları ayrıca panel olarak da gösterir ve otomatik başlatma denemesi yapar. Otomatik başlatma başarısız olursa Fast mode'a güvenli şekilde geri döner.
Not: Önerilen modeller listesine qwen3.5:0.8B eklidir ve seçim ekranında %95 Accurate etiketiyle gösterilir.
Tests
- Run all tests with:
py -3.14 -m pytest tests/ - Gmail delete and move-to-trash flows are covered in
tests/test_google_delete_trash.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mailshift-1.0.1.tar.gz.
File metadata
- Download URL: mailshift-1.0.1.tar.gz
- Upload date:
- Size: 249.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b783fb057a313be68729e5f71c4c0c44a7d4d2b8f14578e8a9bdd942d4e7f37
|
|
| MD5 |
b68257c0d53c8d0a7089408f4ded08a9
|
|
| BLAKE2b-256 |
e19e67da7c3f1df2e6eca7b6390af6a542db9ee6069b1ae874a16befdf7bf883
|
File details
Details for the file mailshift-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mailshift-1.0.1-py3-none-any.whl
- Upload date:
- Size: 83.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee4bbd8c1bcc2b923692b3ee045c7b1c280c1646034e98c50b56967054fc7a93
|
|
| MD5 |
e8c9ae49dd66c75a75a7f2cdad882c6e
|
|
| BLAKE2b-256 |
fa2199adfd53cd3b4760b7463d838c6d03d6c42fc9cbcaeb617bd5c076ccbbc7
|