CLI Reference (original) (raw)

Global Flags

Flag Description
--config Path to config file (default: ~/.msgvault/config.toml)
--home Home directory for all data (overrides MSGVAULT_HOME)
-v, --verbose Verbose output
--local Force local database mode when [remote] is configured
--help Show help

init-db

Initialize the SQLite database.


add-account

Add a Gmail account and authorize via OAuth.


msgvault add-account <email>

msgvault add-account <email> --headless

msgvault add-account <email> --oauth-app <name>

Flag Description
--headless Show instructions for headless server setup
--oauth-app Use a named OAuth app from [oauth.apps.] in config
--force Delete existing token and re-authorize
--display-name Set a display name for the account

add-imap

Add an IMAP account for syncing mail from any standard IMAP server.


msgvault add-imap --host <hostname> --username <email>

The command prompts interactively for your password (never accepted as a flag to avoid shell history exposure). For scripting or Docker, set MSGVAULT_IMAP_PASSWORD or pipe via stdin:


MSGVAULT_IMAP_PASSWORD="..." msgvault add-imap --host imap.example.com --username user@example.com

# or

echo "$PASS" | msgvault add-imap --host imap.example.com --username user@example.com

It tests the connection before saving credentials.

Flag Default Description
--host (required) IMAP server hostname
--username (required) IMAP username or email address
--port 993 IMAP server port (993 for TLS, 143 for STARTTLS/plain)
--starttls false Use STARTTLS instead of implicit TLS
--no-tls false Disable TLS entirely (plaintext, not recommended)

Credentials are stored in tokens/imap_<hash>.json with restricted file permissions (0600). Use app-specific passwords when your provider supports them.

After adding an account, sync it with msgvault sync-full. IMAP accounts use the same sync and sync-full commands as Gmail. See Setup Guide for a walkthrough.


add-o365

Add a Microsoft 365 or Outlook.com account via OAuth2 with XOAUTH2 IMAP authentication.


msgvault add-o365 <email>

The command opens your browser for Microsoft OAuth consent, then configures IMAP with XOAUTH2 automatically. The correct IMAP host is auto-detected: outlook.office.com for personal accounts (hotmail.com, outlook.com, live.com, msn.com) and outlook.office365.com for organizational accounts.

Requires a [microsoft] section with client_id in config.toml. See the OAuth Setup guide for Azure AD app registration.

Flag Default Description
--tenant common Azure AD tenant ID (restricts which accounts can authorize)

After adding the account, sync it with msgvault sync-full.


sync-full

Download all messages from a Gmail account. When called without an email argument, syncs all configured accounts.


msgvault sync-full [email] [flags]

Flag Description
--limit N Maximum messages to download
--after YYYY-MM-DD Only messages after this date
--before YYYY-MM-DD Only messages before this date
--query Gmail search query filter
--noresume Ignore checkpoints, start fresh
--verbose Detailed progress output

sync

Sync new and changed messages using Gmail History API. When called without an email argument, syncs all accounts that have completed an initial full sync.


import-mbox

Import a local MBOX archive into msgvault.


msgvault import-mbox <identifier> <export-file>

The export file may be a plain mbox file (any extension) or a .zip containing one or more .mbox/.mbx files.

Flag Default Description
--source-type mbox Source type recorded in database (e.g., hey for HEY.com)
--label Label(s) to apply to imported messages (repeatable, or comma-separated)
--no-resume false Start fresh, ignoring interrupted progress
--checkpoint-interval 200 Save progress every N messages
--no-attachments false Skip writing attachments to disk

See Importing Local Email for usage examples.


import-emlx

Import Apple Mail .emlx files into msgvault. Can auto-discover accounts from macOS Accounts4.sqlite or accept explicit arguments.


# Auto-discover accounts (reads ~/Library/Accounts/Accounts4.sqlite)

msgvault import-emlx

# Specify mail directory

msgvault import-emlx <mail-dir>

# Legacy form: explicit identifier and directory

msgvault import-emlx <identifier> <mail-dir>

The mail directory should be an Apple Mail mailbox tree containing .mbox or .imapmbox directories, each with a Messages/ subdirectory of .emlx files. You can also point directly at a single .mbox directory. Labels are derived from directory names.

Flag Default Description
--source-type apple-mail Source type recorded in database
--account Filter to specific account(s) during auto-discover (repeatable)
--accounts-db Custom path to macOS Accounts4.sqlite
--identifier Manual identifier when auto-discover is not suitable
--no-resume false Start fresh, ignoring interrupted progress
--checkpoint-interval 200 Save progress every N messages
--no-attachments false Skip writing attachments to disk

See Importing Local Email for usage examples.


import-whatsapp

Import messages from a decrypted WhatsApp msgstore.db SQLite database.


msgvault import-whatsapp <msgstore.db> --phone <your-number>

The --phone flag is required and must be in E.164 format (e.g., +447700900000).

Flag Required Description
--phone Yes Your phone number in E.164 format (must start with +)
--contacts No Path to contacts .vcf file for name resolution
--media-dir No Path to decrypted Media folder for attachments
--limit No Limit number of messages (for testing)
--display-name No Display name for the phone owner

See Text Messages for usage examples.


import-imessage

Import messages from the local iMessage database on macOS. Requires Full Disk Access in System Settings.

Reads from ~/Library/Messages/chat.db by default. This is a read-only operation.

Flag Default Description
--db-path ~/Library/Messages/chat.db Path to chat.db
--before Only messages before this date (YYYY-MM-DD)
--after Only messages after this date (YYYY-MM-DD)
--limit 0 Limit number of messages (for testing)
--me Your phone/email for recipient tracking

See Text Messages for usage examples.


import-gvoice

Import texts, calls, and voicemails from a Google Voice Takeout export.


msgvault import-gvoice <takeout-voice-dir>

The directory must be the “Voice” folder from a Google Takeout export, containing Calls/ and Phones.vcf.

Flag Default Description
--before Only messages before this date (YYYY-MM-DD)
--after Only messages after this date (YYYY-MM-DD)
--limit 0 Limit number of messages (for testing)

See Text Messages for usage examples.


Search the archive with Gmail-like query syntax.


msgvault search <query> [flags]

Flag Description
-n, --limit N Maximum number of results (default: 50)
--offset N Skip first N results
--json Output results as JSON
--account Limit results to a specific account

See Searching for the full operator reference.


tui

Launch the interactive terminal interface.

Flag Description
--force-sql Force SQLite queries instead of Parquet
--no-cache-build Skip automatic cache build/update

export-eml

Export a message as a .eml file. Accepts either a numeric database ID or a Gmail message ID.


msgvault export-eml <id> [flags]

Flag Description
-o, --output Output file (default: <gmail_id>.eml, use - for stdout)

export-attachment

Export an attachment by its SHA-256 content hash.


msgvault export-attachment <content-hash> [flags]

Flag Description
-o, --output Output file path (use - for stdout)
--base64 Output raw base64 to stdout
--json Output as JSON with base64-encoded data

The --json, --base64, and --output flags are mutually exclusive.

See Exporting Data for usage examples.


export-attachments

Export all attachments from a message as individual files.


msgvault export-attachments <message-id> [flags]

Flag Description
-o, --output Output directory (default: current directory)

Accepts internal numeric IDs or Gmail message IDs. See Exporting Data for usage examples.


export-token

Export a browser-created OAuth refresh token to a remote msgvault instance.

Use this for headless deployments (NAS, cloud VM, any remote server) that cannot run a browser flow.


msgvault export-token <email> [flags]

Flag Description
--to Remote msgvault URL (or MSGVAULT_REMOTE_URL)
--api-key API key (or MSGVAULT_REMOTE_API_KEY)
--allow-insecure Allow HTTP for trusted networks (for example Tailscale)

export-token uploads ~/.msgvault/tokens/<email>.json to /api/v1/auth/token/<email>, saves it in the remote token store, and posts account metadata to /api/v1/accounts.


verify

Verify local archive integrity against Gmail.


msgvault verify <email> [flags]

Flag Description
--sample N Messages to sample (default: 100)

stats

Show archive statistics.


list-senders

List top senders by message count.


msgvault list-senders [flags]

Flag Description
-n, --limit N Number of results (default: 50)
--after YYYY-MM-DD Only messages after this date
--before YYYY-MM-DD Only messages before this date
--json Output as JSON

list-domains

List top sender domains by message count.


msgvault list-domains [flags]

Flag Description
-n, --limit N Number of results (default: 50)
--after YYYY-MM-DD Only messages after this date
--before YYYY-MM-DD Only messages before this date
--json Output as JSON

list-labels

List all labels with message counts.


msgvault list-labels [flags]

Flag Description
-n, --limit N Number of results (default: 50)
--after YYYY-MM-DD Only messages after this date
--before YYYY-MM-DD Only messages before this date
--json Output as JSON

build-cache

Build or update the Parquet analytics cache.


msgvault build-cache [flags]

Flag Description
--full-rebuild Discard existing cache and rebuild

cache-stats

Show statistics about the analytics cache.


query

Run arbitrary SQL against the Parquet analytics cache using an in-memory DuckDB engine.


msgvault query <sql> [flags]

If the analytics cache is stale, it is automatically rebuilt before the query runs.

Flag Default Description
--format json Output format: json, csv, or table

See SQL Queries for available views and example queries.


mcp

Start the Model Context Protocol server for AI assistant integration.

Flag Default Description
--force-sql false Always use SQL retrieval instead of FTS5

See MCP Server for configuration and tool reference.


serve

Start the web server with optional background sync scheduling.

The serve command has no CLI flags. All configuration (port, bind address, API key, CORS, account schedules) is read from your config.toml. See Web Server for endpoint documentation and Configuration for config options.


setup

Run the first-run setup wizard for OAuth and optional remote deployment.

If configured for a remote server, this command generates <MSGVAULT_HOME>/nas-bundle with:

The wizard also stores remote URL/API key in remote config block so export-token can use it without extra flags.


show-message

Show full message details.


msgvault show-message <id> [flags]

Flag Description
--json Output as JSON

list-accounts

List synced email accounts.


msgvault list-accounts [flags]

Flag Description
--json Output as JSON

update-account

Update account settings.


msgvault update-account <email> [flags]

Flag Description
--display-name Set a display name for the account

list-deletions

List pending and recent deletion batches.


show-deletion

Show details of a deletion batch.


msgvault show-deletion <batch-id>


cancel-deletion

Cancel pending or in-progress deletion batches. When called without a batch ID, lists available batches.


msgvault cancel-deletion [batch-id]

msgvault cancel-deletion --all

Flag Description
--all Cancel all pending and in-progress batches

delete-staged

Execute staged deletions. This permanently deletes messages from Gmail.


msgvault delete-staged [batch-id] [flags]

Flag Description
-y, --yes Skip confirmation prompt
--trash Move to trash instead of permanent delete
--dry-run Show what would be deleted without deleting
-l, --list List staged deletion batches
--account Filter to a specific account

repair-encoding

Fix UTF-8 encoding issues in existing messages.


update

Update msgvault to the latest version.

Flag Description
--check Check for updates without installing
-y, --yes Skip confirmation prompt
-f, --force Force update even if already on the latest version

version

Print version, commit, build date, and platform information.


completion

Generate a shell completion script.


msgvault completion [bash|zsh|fish|powershell]

To load completions:

Bash:


source <(msgvault completion bash)

# Permanent (Linux):

msgvault completion bash > /etc/bash_completion.d/msgvault

# Permanent (macOS with Homebrew):

msgvault completion bash > $(brew --prefix)/etc/bash_completion.d/msgvault

Zsh:


msgvault completion zsh > "${fpath[1]}/_msgvault"

If shell completion is not already enabled, add autoload -U compinit; compinit to your ~/.zshrc first.

Fish:


msgvault completion fish > ~/.config/fish/completions/msgvault.fish

PowerShell:


msgvault completion powershell | Out-String | Invoke-Expression


quickstart

Print a quickstart guide for AI agents.