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.

Metadata

Release files for mailsync 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailsync 0.1.0
File Size Uploaded Provenance Actions
mailsync-0.1.0.tar.gz 16.2 kB Without provenance Details for mailsync-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mailsync 0.1.0
File Interpreter ABI Platform Actions
mailsync-0.1.0-py3-none-any.whl Python 3 none any Details for mailsync-0.1.0-py3-none-any.whl

Total release size: 31.0 kB

Release files / mailsync-0.1.0.tar.gz

Download URL mailsync-0.1.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
60d969308534cced4321a6770efaf18fe6f823fd341b2e36fbfa8d6034b2e2df
BLAKE2b-256 checksum
How to use checksums
93be44e9176c431ac80b1e39857119251899343cbc7a0dbe40886cbbebadb7ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / mailsync-0.1.0-py3-none-any.whl

Download URL mailsync-0.1.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bc72081cffd399aeddc95bf4b6acd843738832a36493b2762408d609a43d08b
BLAKE2b-256 checksum
How to use checksums
dbbed6f2d6775968861a766f5e2d4396645c9757df8c810325b08f37fe35530f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for mailsync 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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