Core

Command reference

A single binary, mailsubsystem <command> [options]. Run with no args or help for usage at the terminal.

Sync

CommandDescription
checkVerify DB and IMAP connectivity.
syncFull envelope sync + durable body sync (workers drain the body queue).
sync-slowOnly drain body queue (backfill bodies for rows missing body_text).
statusShow imap_folders and emails table state.
sync-incrementalIncremental sync (MODSEQ changes since last sync).
sync-incremental --daemonRun incremental sync in a loop until Ctrl+C.
sync-window [--days N] [--full]Sync envelopes for the last N days (or full if --full).
daemonUnified daemon: incremental sync + periodic full + periodic slow.

Analyze

CommandDescription
analyze [--force] [message_id]AI analysis: batch (uses ANALYZE_LIMIT) or single email.
test-llm --localTest connection to local LLM (LM Studio / Ollama).
test-llm --frontierTest connection to a frontier provider (Gemini / OpenAI / Anthropic).
show <message_id>Print AI fields stored in DB for that email.
process-frontier-queue [--limit N]Re-analyze queued emails with frontier (default N=10).
embed-backfill [--limit N]Generate embeddings for emails missing them (RAG; default N=50).

Locate & file

CommandDescription
resolve-orphansFind rows with location=NULL by Message-ID in other folders; update or mark deleted.
locate [--force] [message_id]Agentic folder recommendation (batch or one).
file [--dry-run]Apply location recommendations: create folder if needed, IMAP MOVE, update DB.

Maintenance

CommandDescription
backfill-message-tokensBackfill message_tokens (chars / 4) for emails with body content.
backfill-message <message_id>Fetch one message from IMAP and backfill null fields.
backfill-from-imap [--limit N]Fetch from IMAP to backfill received_date, raw_email_content, body_text, etc. (default N=100).

Example workflow

# One-time full sync and analyze
./target/release/mailsubsystem sync
./target/release/mailsubsystem analyze
./target/release/mailsubsystem embed-backfill --limit 100   # optional, for RAG
./target/release/mailsubsystem locate
./target/release/mailsubsystem file --dry-run              # preview
./target/release/mailsubsystem file                        # apply

# Daemon for ongoing sync only (analyze/locate/file still manual)
./target/release/mailsubsystem daemon

Configuration

Configuration is via environment variables. See the repository README and GAP_CLOSURE_SPEC.md for the full list. Most relevant groups:

GroupExamplesPurpose
IMAPICLOUD_IMAP_SERVER, ICLOUD_USERNAME, ICLOUD_PASSWORDMailbox connection (any IMAP server).
DatabaseDATABASE_URL, DB_HOST, DB_NAMEPostgreSQL connection and runtime persistence.
AI providersAI_PROVIDER, LOCAL_LLM_URL, GEMINI_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEYLocal-first or hosted model routing.
Daemon & batchesINCREMENTAL_SYNC_INTERVAL_SECS, ANALYZE_LIMIT, LOCATE_LIMITOperational cadence and processing limits.