Email storage: mbox vs Maildir
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
Mbox is an email storage first implemented in 1974 for Fifth Edition Unix.
Maildir was developped in 1995 by Daniel Bernstein for his mail transfer agent (MTA) qmail, addressing technical issues inherent to the mbox format, especially solving file locking problems when new mail is being received.
The mail difference between the two is that mbox stores all of a user's emails into a single file, while Maildir stores each single email in a different file. All the major advantages of Maildir over mbox derive from this single fact.
Only major email storage providers, who serve a very large user base and have heavy storage requirements, might prefer mbox, depending on their operating system and file system limitations. The requirement here is that the filesystem must be fast and able to handle lots of small files. This is not a concern for regular users who store POP3 emails on their personal computers.
For archives (long term preservation of historical emails), a simple script can convert Maildir to a single mbox file.
Scripts like maildir2mbox and mbox2maildir can make it easy to convert from one format to another.
For backups, the Maildir format allows for smaller, differential backups since only the newly added emails need to be backed up. With mbox, the whole file, which can become huge, must be backed-up every time.
For low-level maintenance, e.g. when debugging a mail client, it is easier with Maildir to deal with (move, copy, delete) single emails. It is also easier to grep
for some keywords (e.g. email address) and have a list of emails (i.e. files) which contain the given keywords.
Maildir is also more resistant to filesystem corruption. If a file gets corrupted, only one single email is potentially lost whilst with mbox the whole collection of emails can be. Think of what may happen if the disk is full, is an application crashes while handling mails, etc.
In mbox, the word From
is the message separator line. Thus email clients must escape the word "From" when it appears at the beginning of a new line. E.g. PINE silently changes it to "> From", which is confusing because ">" makes it look like that line was quoted from a reply. If a mail client forgets to escape it, it may corrupt the whole mbox file.
On the filesystem level, with Maildir it is much quicker and easier to move thousands of emails from one directory to another, or even delete them. With mbox, the content of the file must be completely parsed and updated accordingly.