Skip to main content

mailsync

mailsync keeps a searchable local mirror of Gmail in one SQLite file. It is a sync, not an archive: Gmail deletions, moves, and label changes are applied locally too. Close it for any length of time and the next run catches up from Gmail's history; if that history has expired, it safely reconciles the whole selected set.

Start

First create a Gmail token with gclientid:

gclientid-auth --account you@example.com --preset gmail

Then initialize and sync the mirror:

mailsync --account you@example.com --initial-lookback-days 365

This creates:

  • $XDG_CONFIG_HOME/mailsync/config.ini — account, token override, selection, and polling settings
  • $XDG_CACHE_HOME/mailsync/you@example.com.sqlite3 — raw messages plus structured and full-text indexes

fastgws reads gclientid's standard $XDG_CONFIG_HOME/gclientid/oauth-token-you@example.com.json location directly. Pass --token-path only for a google-auth authorized-user JSON file stored elsewhere.

After setup, run mailsync whenever you want to catch up, or leave it polling:

mailsync
mailsync --follow

During larger fetches, mailsync prints a compact fetched/total update every 10 seconds. Change the cadence with --progress-seconds, or pass --progress-seconds 0 for quiet operation.

mailsync follows Gmail's synchronization model: it downloads complete RFC 822 data only for uncached messages, refreshes cached label state with minimal responses, batches reads in groups of 50, and asks Google only for the response fields it uses. fastgws enables gzip and handles quota-aware retries for both ordinary and batched calls.

The initial lookback becomes a fixed sync floor. Mail older than that floor is outside the managed set: it is not silently aged out, updated, or deleted locally.

Choose labels

With no includes, all messages are mirrored, including Spam and Trash. Repeat options to select labels; label names and Gmail label IDs both work. Any excluded label wins over an included label.

mailsync --account you@example.com --include-label INBOX --include-label work --exclude-label SPAM

Selection is stored at first setup. Edit config.ini later; changing it automatically triggers a full reconciliation.

Search, inspect, and back up

mailsync-search 'sender:"alice@example.com" AND roadmap'
mailsync-search 'subject:"release notes"' --label work
mailsync-status
mailsync-backup --output mail.sqlite3

Search accepts SQLite FTS5 syntax. SQLite itself is also a supported interface: messages, headers, labels, and message_labels provide structured fields, while message_fts indexes subject, sender, recipients, CC, and decoded body text. The original decoded RFC 822 bytes are in messages.raw.

mailsync-backup uses SQLite's online backup API, so the resulting file is a consistent standalone snapshot even while the working database uses WAL.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailsync-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailsync-0.1.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file mailsync-0.1.0.tar.gz.

File metadata

  • Download URL: mailsync-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for mailsync-0.1.0.tar.gz
Algorithm Hash digest
SHA256 60d969308534cced4321a6770efaf18fe6f823fd341b2e36fbfa8d6034b2e2df
MD5 32f3e8592c0806f1e13cd57206cd9178
BLAKE2b-256 93be44e9176c431ac80b1e39857119251899343cbc7a0dbe40886cbbebadb7ae

See more details on using hashes here.

File details

Details for the file mailsync-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mailsync-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for mailsync-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc72081cffd399aeddc95bf4b6acd843738832a36493b2762408d609a43d08b
MD5 22f742ab98d099d1423589227ce5a23e
BLAKE2b-256 dbbed6f2d6775968861a766f5e2d4396645c9757df8c810325b08f37fe35530f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page