gmail-auto-label (Rust)
An automatic Gmail labeling tool built with gog + codex (Rust version).
This is the primary documentation.
๐ Languages: ๐บ๐ธ English ยท ๐จ๐ณ ็ฎไฝไธญๆ
Features
- Auto-scan inbox threads and classify emails into business-friendly labels
- Cache-first classification (memo + reusable rules) to reduce repeated LLM calls
- Codex fallback for uncached emails, then persist extracted rules for later reuse
- Auto-create missing Gmail labels and apply labels in batches
- Optional archive step (remove
INBOX) after labeling, with--keep-inboxsupport - Label compression when active labels exceed limit (
--max-labels+--merged-label) - Gmail rate-limit handling with automatic retry and exponential backoff
- Dry-run mode for safe preview without write operations
Prerequisites
gogis installed and authenticatedcodexCLI is installed (default command:codex exec)- Rust toolchain is installed
gog Setup
- Install
gogfor your operating system. - Sign in:
- Verify Gmail access:
- List local accounts (to confirm account names):
- For multiple accounts, pass account name when running this tool:
Note: all Gmail operations are executed through gog. If auth or permissions are missing, the tool will fail at runtime.
gog Troubleshooting
- Check current auth/session status:
- Quick Gmail API read test:
- Re-login if token/permission is invalid:
Build
Binary:
Install from crates.io (after publish)
Once this crate is published, install with:
Optional (pin a version):
Common Usage
- Single pass (default: 20 threads):
- Dry run (no write operations):
- Loop mode (every 5 minutes):
- Keep messages in inbox (label only, no archive):
Key Options
--limit: max threads per run, default20--loop: keep running until no pending threads--interval: loop sleep seconds, default300--dry-run: print actions only, no writes--codex-cmd: custom Codex command prefix, default"codex exec"--cache-file: cache file path, default/tmp/gmail_auto_label_codex_cache.json--cache-ttl-hours: cache TTL in hours, default336--cache-max-rules: max cached rules, default500--cache-max-memos: max cached memos, default5000--max-labels: max active labels, default10--merged-label: merge target when labels exceed limit, defaultๅ ถไป้็ฅ--codex-workers: Codex concurrency,0means auto--keep-inbox: do not remove processed threads from inbox--gmail-batch-size: Gmail modify batch size, default100--gmail-batch-retries: retries per Gmail write batch, default2--gmail-batch-retry-backoff-secs: backoff seconds between batch retries, default1--feedback-file: feedback file path, default/tmp/gmail_auto_label_feedback.json--feedback-bad-threshold: drop rule when bad feedback count reaches this threshold, default3--feedback-hit-penalty: reduce rule hits per bad feedback event, default2--feedback-max-age-hours: max accepted age of feedback events, default336
Feedback file format (--feedback-file):
Notes:
event_idmust be unique; duplicated/replayed events are skipped.tsuses Unix seconds; stale events older than--feedback-max-age-hoursare skipped.
Help