jump to navigation

Mbox vs Maildir: Mail Storage Formats on Linux January 2, 2011

Posted by Tournas Dimitrios in Linux.

The Unix world has two ways of storing mail messages, the traditional mbox format and the newer maildir format. Postfix and Dovecot supports the two mail storage format so you can use any format, but I highly recommend you use the maildir format.

The Mbox Format

This is the traditional way of storing mail messages in the Unix world. In this format, a regular text file which serves as the mail user’s mailbox file is created.

How mbox works :

Receiving and storing a mail

  1. Lock the mailbox.
  2. Append the header (usually “From [sender’s email address] [date and time received]“) and the mail into the mailbox file.
  3. Unlock the mailbox.

Retrieving a mail

  1. Lock the mailbox.
  2. Locate and read the mail.
  3. Update the mail status flag.
  4. Unlock the mailbox.

Deleting a mail

  1. Lock the mailbox.
  2. Move the contents of the mailbox, beginning from the position right after the mail to be deleted until the end of the mailbox, into the position of the mail to be deleted.
  3. Reduce the size of the mailbox file by the size of the deleted mail.
  4. Unlock the mailbox.

Searching a mail

  1. Lock the mailbox.
  2. Search the mailbox.
  3. Unlock the mailbox.



  • Format is universally supported.
  • Appending a new mail into the mailbox file is fast.
  • Searching text inside a single mailbox file is fast.


  • Has file locking problems.
  • Has problems when used with network file systems.
  • Format is prone to corruption.


The Maildir Format

This is a new way of storing mail messages. In this format, a directory usually named Maildir is created for each mail user. Under this directory are three more directories named new, cur and tmp.How maidir works :

Receiving and storing a mail

  1. Create a unique file in the tmp directory.
  2. Write the mail into the newly created file.
  3. Move the completely written mail into the new directory.

Retrieving a mail

  1. Locate and read the mail.
  2. Move the mail from new into the cur directory and append the mail status flag into the filename.

Deleting a mail

  1. Delete the file containing the mail.

Searching a mail

  1. Search each and every mail file.



  • Locating, retrieving and deleting a specific mail is fast.
  • Minimal to no file locking needed.
  • Can be used on network file system.
  • Immune to mailbox corruption (assuming the hardware will not fail).


  • Some filesystems may not efficiently handle a large number of small files.
  • Searching text, which requires all mail files to be opened is slow.


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s