Python mailbox: read and change on-disk mailboxes
Answer: This module defines two classes, Mailbox and Message, for on-disk mailboxes.
Classes and formats
Two classes do this work: Mailbox and Message.
Mailbox offers a dictionary-like mapping from keys to messages.
Message adds format-specific state on top of the email message class.
On-disk formats include Maildir and mbox, plus MH, Babyl, and MMDF.
Trusted use and the interface
The API is meant only for trusted environments.
The Mailbox class is not intended to be instantiated.
A format-specific subclass is what your code should construct.
A key continues to identify a message even if that message is modified.
See also
Claims
- id: C1 claim: The module defines the Mailbox and Message classes. source: S1 evidence: "This module defines two classes, Mailbox and Message"
- id: C2 claim: Mailbox maps keys to messages in a dictionary-like way. source: S1 evidence: "dictionary-like mapping from keys to messages"
- id: C3 claim: Supported formats include Maildir, mbox, MH, Babyl, and MMDF. source: S2 evidence: "Maildir, mbox, MH, Babyl, and MMDF"
- id: C4 claim: The base Mailbox class is not meant to be instantiated. source: S2 evidence: "defines an interface and is not intended to be instantiated"
Sources
- [S1] mailbox — Manipulate mailboxes in various formats. Python Software Foundation. https://docs.python.org/3/library/mailbox.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] mailbox documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/mailbox.rst . License: PSF License Version 2. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, mailbox — Manipulate mailboxes in various formats; CPython, mailbox documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, mailbox — Manipulate mailboxes in various formats; CPython, mailbox documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python mailbox: read and change on-disk mailboxes." iinventedlight Library, iil:note:c8j0yqyg, version of 2026-11-23. https://iinventedlight.com/library/notes/python-mailbox/. License: CC-BY-4.0.
@misc{iil_note_c8j0yqyg,
author = {{iinventedlight}},
title = {{Python mailbox: read and change on-disk mailboxes}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/python-mailbox/},
note = {Permanent ID iil:note:c8j0yqyg. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-mailbox.schema.json (schema; CC-BY-4.0)
- python-mailbox.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-mailbox.md.