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
- Optional custom label rules with higher priority than memoized, learned, and Codex-generated matches
- 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 the limit (public control is
--max-labels, merge target defaults toothers) - Gmail rate-limit handling with automatic retry/backoff in single-pass mode, and no in-round retries in watch mode
- 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
Install with:
Optional (pin a version):
After installation, run the binary directly:
Common Usage
- Single pass (default: 10 threads):
- Dry run (no write operations):
- Watch mode (base interval: every 5 minutes):
Watch mode uses adaptive idle backoff: when rounds stay idle, the next sleep interval grows up to 8x the base interval; once a round processes emails, it resets to the base interval.
In watch mode, Gmail API calls do not retry within the same round; failed calls are retried in the next round.
- Keep messages in inbox (label only, no archive):
- Use custom label rules:
Key Options
--limit: max threads per run, default10--watch: base polling interval in seconds (adaptive idle backoff may extend actual sleep), for example--watch 300--account: gog account name--dry-run: print actions only, no writes--custom-labels-file: load custom label rules from a JSON file--max-labels: max active labels, default10--keep-inbox: do not remove processed threads from inbox
Advanced Options
These flags remain supported for compatibility, but are hidden by default:
--codex-cmd--cache-file--merged-label- Legacy compatibility:
--loop+--intervalstill work, but--watchis the preferred form
Built-in feedback file format (internal path is fixed to /tmp/gmail_auto_label_feedback.json):
Notes:
event_idmust be unique; duplicated/replayed events are skipped.tsuses Unix seconds; stale events older than the built-in feedback retention window are skipped.
Custom Label Rules
Use --custom-labels-file <path> to load user-defined label rules before a run starts. Matching order is:
- Custom label rules
- Memoized matches
- Learned rules
- Codex fallback
Rules are evaluated in file order, first match wins. Custom labels are not auto-pruned by feedback and are not merged into the learned-label compression target.
Example file:
Validation rules:
- File must be readable JSON
- Top-level value must be an array
- Each rule must include a non-empty
label - Each rule must include at least one non-empty
include_keywordsvalue
Help