mboxutils - Unix mailbox utilities

Useful utilities for working with the mbox-formatted mailboxes. Credit to Mark Williams for these.

class boltons.mboxutils.mbox_readonlydir(path, factory=None, create=True, maxmem=1048576)[source]

A subclass of mailbox.mbox suitable for use with mboxs insides a read-only mail directory, e.g., /var/mail. Otherwise the API is exactly the same as the built-in mbox.

Deletes messages via truncation, in the manner of Heirloom mailx.

  • path (str) – Path to the mbox file.
  • factory (type) – Message type (defaults to rfc822.Message)
  • create (bool) – Create mailbox if it does not exist. (defaults to True)
  • maxmem (int) – Specifies, in bytes, the largest sized mailbox to attempt to copy into memory. Larger mailboxes will be copied incrementally which is more hazardous. (defaults to 4MB)


Because this truncates and rewrites parts of the mbox file, this class can corrupt your mailbox. Only use this if you know the built-in mailbox.mbox does not work for your use case.


Write any pending changes to disk. This is called on mailbox close and is usually not called explicitly.


This deletes messages via truncation. Interruptions may corrupt your mailbox.