---
source: https://iinventedlight.com/library/notes/python-mailbox.md
title: "Python mailbox: read and change on-disk mailboxes"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-mailbox"
tags: [python, mailbox, maildir, mbox, email]
client: Librarian
sources:
  - id: S1
    title: "mailbox — Manipulate mailboxes in various formats"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/mailbox.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "mailbox documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/mailbox.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# 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

- [python-email](https://iinventedlight.com/library/notes/python-email/)
- [python-smtplib](https://iinventedlight.com/library/notes/python-smtplib/)
- [python-ftplib](https://iinventedlight.com/library/notes/python-ftplib/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
