Skip to main content

mbox-md

Convert a Gmail Takeout (or other) .mbox archive into one Markdown file per message, organized by year and month, with attachments stored once and shared across messages.

Work in progress.

Usage

CLI:

mbox-md "All mail Including Spam and Trash.mbox" archive/
mbox-md takeout.mbox.zst archive/ --since 2020-01-01 --strip-quotes
mbox-md takeout.mbox --dry-run            # counts and output size, writes nothing
mbox-md takeout.mbox archive/ --compress-source zstd --delete-source
Option What it does
--since, --until YYYY-MM-DD only messages in this date range (undated mail is skipped when a range is set)
--skip-labels LABELS comma-separated Gmail labels to skip; default Spam,Trash, "" keeps everything
--limit N stop after reading N messages
--tz ZONE timezone for folder and file names and --since/--until: sender (default), utc, local, or an IANA name
--min-inline-image SIZE drop inline images smaller than this (logos, tracking pixels); default 5KB, 0 keeps all
--strip-quotes drop quoted replies from bodies
--keep-from-escapes don't undo mboxrd >From escaping (for mboxo files)
--workers N worker processes; default CPUs − 1
--dry-run parse and count everything, write nothing
--incremental convert only messages not already in the output (a newer export, or resuming a stopped run)
--prune delete files that earlier runs wrote into the output and this run didn't
--compress-source zstd|gzip after converting, compress the input mbox next to it and verify it by decompressing it in full
--compress-level 1-10 compression level, 1 fastest to 10 smallest (default 5)
--delete-source delete the original mbox, only after the compressed copy verifies
-q, -v, --json quiet, report each failure, or print stats as JSON

Input can be plain, zstd, or gzip; compression is detected from the file's contents and handled in-process by compress-utils, with no zstd or gzip command needed.

API:

import mbox_md

stats = mbox_md.convert("All mail.mbox", "out/")

for raw in mbox_md.iter_messages("All mail.mbox"):
    msg = mbox_md.parse_message(raw)  # None if it's in Spam or Trash

Development

uv sync
uv run pytest            # unit tests, fabricated data only
uv run pytest -m local   # smoke test against local-data/takeout-sample.mbox, if you have it
uv run mypy              # strict type checking
uv run coverage run -m pytest && uv run coverage combine && uv run coverage report   # branch coverage, 95% minimum
uv run ruff check src tests && uv run ruff format --check src tests

License

MIT

Metadata

Release files for mbox-md 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 mbox-md 0.1.0
File Size Uploaded
mbox_md-0.1.0.tar.gz 59.9 kB Details

Built distribution (wheel)

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

Total release size: 95.4 kB

Release files / mbox_md-0.1.0.tar.gz

Download URL mbox_md-0.1.0.tar.gz
Size 59.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cf5826978b7dcd873229a569e118130c7072a8733e13c0ebe73d640470141500
BLAKE2b-256 checksum
How to use checksums
a4bc9fefa004ed447d6b943be0ca5887b81239a09e4e29feff88ff14a62fe07d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

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

Download URL mbox_md-0.1.0-py3-none-any.whl
Size 35.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
833b416fe9e3d476b1ba7783e8414c27418f9c28a320ad7c9a4e2122491d1af2
BLAKE2b-256 checksum
How to use checksums
0fbe4c837fa7e0912d5dd2812d11539530a6c333c7c342dd1a34f125fbf16151
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release 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