mbox(5)

πŸ“¦
this version Β· 3 versions
, in alpine 3.24, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’Œ mbox(5) β€” the mail storage format, bestie πŸ’Œ

okay so welcome to mbox(5) from the User Manuals section, and honestly? this one is a classic. it's giving "your mail spool called and it wants to explain itself." let's get into it 🫢


✨ NAME ✨

mbox β€” the format for mail message storage. that's it, that's the whole vibe. πŸ’–


🌸 DESCRIPTION 🌸

so this doc describes the format that Unix hosts have traditionally used to store mail messages locally. iconic behavior. mbox files typically live in the system's mail spool, and they also show up under various names in users' Mail directories, plus under the name mbox in users' home directories. she's everywhere, no cap. πŸ’…

An mbox is a text file containing an arbitrary number of e-mail messages. each message is a postmark, followed by an e-mail message formatted according to RFC822, RFC2822. the file format is line-oriented, and lines are separated by line feed characters (ASCII 10). very demure, very simple. ✨

A postmark line consists of the four characters "From", followed by a space character, followed by the message's envelope sender address, followed by whitespace, and followed by a time stamp. this line is often called the From_ line. lowkey famous.

The sender address is expected to be addr-spec as defined in RFC2822 3.4.1. the date is expected to be date-time as output by asctime(3). for compatibility reasons with legacy software, two-digit years greater than or equal to 70 should be interpreted as the years 1970+, while two-digit years less than 70 should be interpreted as the years 2000-2069. (yes bestie, that's the real rule, not me being chaotic. πŸ•°οΈ)

Software reading files in this format should also be prepared to accept non-numeric timezone information such as "CET DST" for Central European Time, daylight saving time. she's flexible like that. 🌈

Example:

>From example@example.com Fri Jun 23 02:56:55 2000

In order to avoid misinterpretation of lines in message bodies which begin with the four characters "From", followed by a space character, the mail delivery agent must quote any occurrence of "From " at the start of a body line. non-negotiable, periodt. πŸ‘‘

There are two different quoting schemes:

  • The first (MBOXO) only quotes plain "From " lines in the body by prepending a '>' to the line.
  • The second (MBOXRD) also quotes already quoted "From " lines by prepending a '>' (i.e. ">From ", ">>From ", ...).

The later has the advantage that lines like

>From the command line you can use the '-p' option

aren't dequoted wrongly as a MBOXRD-MDA would turn the line into

>>From the command line you can use the '-p' option

before storing it. see how that works? chef's kiss. 😌

Besides MBOXO and MBOXRD there is also MBOXCL, which is MBOXO with a "Content-Length:" field with the number of bytes in the message body. some MUAs (like neomutt(1)) do automatically transform MBOXO mailboxes into MBOXCL ones when ever they write them back, as MBOXCL can be read by any MBOXO-MUA without any problems. glow up, honestly. ✨

If the modification-time (usually determined via stat(2)) of a nonempty mbox file is greater than the access-time, the file has new mail. many MUAs place a Status: header in each message to indicate which messages have already been read. so that's how she keeps track. πŸ“¬


πŸ”’ LOCKING πŸ”’

Since mbox files are frequently accessed by multiple programs in parallel, mbox files should generally not be accessed without locking. i cannot stress this enough bestie, do not skip the lock. 😭

Three different locking mechanisms (and combinations thereof) are in general use:

  • fcntl(2) locking is mostly used on recent, POSIX-compliant systems. Use of this locking method is, in particular, advisable if mbox files are accessed through the Network File System (NFS), since it seems the only way to reliably invalidate NFS clients' caches.
  • flock(2) locking is mostly used on BSD-based systems.

If multiple methods are combined, implementers should make sure to use the non-blocking variants of the fcntl(2) and flock(2) system calls in order to avoid deadlocks. deadlocks are not the vibe. πŸ’€

If multiple methods are combined, an mbox file must not be considered to have been successfully locked before all individual locks were obtained. When one of the individual locking methods fails, an application should release all locks it acquired successfully, and restart the entire locking procedure from the beginning, after a suitable delay. like, all of it, from scratch. no half-locking. πŸ™ˆ

⚠️ The locking mechanism used on a particular system is a matter of local policy, and should be consistently used by all applications installed on the system which access mbox files. Failure to do so may result in loss of e-mail data, and in corrupted mbox files. bestie i am BEGGING you to be consistent. πŸ™

πŸ“‚ FILES πŸ“‚

  • /var/spool/mail/$LOGNAME β€” $LOGNAME's incoming mail folder.
  • $HOME/mbox β€” user's archived mail messages, in their $HOME directory.
  • $HOME/Mail/ β€” a directory in user's $HOME directory which is commonly used to hold mbox format folders.

πŸ¦‹ SEE ALSO πŸ¦‹

neomutt(1), fcntl(2), flock(2), link(2), stat(2), asctime(3), maildir(5), mmdf(5), RFC822, RFC976, RFC2822

the reading list is long but she's worth it. πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Thomas Roessler <roessler@does-not-exist.org>, Urs Janssen <urs@tin.org>

legends. actual legends. 🫢


⭐ HISTORY ⭐

The mbox format occurred in Version 6 AT&T Unix.

A variant of this format was documented in RFC976.

so she's been around since forever and she's still serving. main character energy since Version 6. πŸ’…βœ¨


and that's the whole page bestie!! πŸŽ€ this was Unix's take from 2002-02-19, and yeah β€” it lives under mbox(5). go lock your mailboxes. mwah πŸ’–πŸŒΈ

πŸ“¦ where this page comes from