The Maildir e-mail format is a common way of storing e-mail messages, where each message is kept in a separate file with a unique name, and each folder is a directory. The local filesystem handles file locking as messages are added, moved and deleted. A major design goal of Maildir is to eliminate program code having to handle locking, which is often difficult.
A Maildir directory (often named
Maildir) usually has three subdirectories named
The original Maildir specification was written by Daniel J. Bernstein, the author of qmail, djbdns, and other software. Although the original specification was written specifically for Bernstein's qmail, it is general enough to be implemented in many programs.
Sam Varshavchik, the author of the Courier Mail Server and other software, wrote an extension to the Maildir format called Maildir++ to support subfolders and mail quotas. Maildir++ directories contain subdirectories with names that start with a '.' (dot) that are also Maildir++ folders. This extension is not a violation of the Maildir specification, which explicitly provides for the possibility to add more than tmp, new, cur to a maildir.
The program that delivers an email message, a mail delivery agent, writes it to a file in the
tmp directory with a unique filename. Algorithms for generating unique filenames can combine time, host name, and a number of pseudo-random parameters to ensure uniqueness, taking into account that multiple messages can be delivered at the same time.
The delivery process stores the message in the maildir by creating and writing to
tmp/unique, and then moving this file to
new/unique. The moving can be done using rename, which is atomic in many systems. Alternatively, it can be done by hard linking the file to
new and then unlinking the file from
tmp. Any leftover file will eventually be deleted. This sequence guarantees that a maildir-reading program will not see a partially written message. There can be multiple programs reading a maildir at the same time. They range from mail user agents (MUAs) which access the server's file system directly, through Internet Message Access Protocol or Post Office Protocol servers acting on behalf or remote MUAs, to utilities such as biff and rsync, which may or may not be aware of the maildir structure. Readers should never look in
When a cognizant maildir reading process (either a POP or IMAP server, or a mail user agent acting locally) finds messages in the
new directory it must move them to
cur. It is just a means to notify the user "you have X new messages". This moving needs to be done using
rename(), as the non-atomic link then unlink technique may result in duplicated messages. An informational suffix is appended to filenames at this stage. It consists of a colon (to separate the unique part of the filename from the actual information), a '2', a comma and various flags. The '2' specifies the version of the information that follows the comma. '2' is the only currently officially specified version, '1' being an experimental version. The specification defines flags which show whether the message has been read, deleted and so on: the initial (capital) letter of Passed, Replied, Seen, Trashed, Draft, and Flagged. Dovecot uses lowercase letters to match 26 IMAP keywords, which may include standardised keywords such as $MDNSent, and user defined flags.
Filesystem Compatibility Issues
The Maildir standard can only be implemented on systems that accept colons in filenames.
Systems that don't allow colons in filenames (This includes Microsoft Windows and some configurations of Novell Storage Services.) can use an alternative separator, such as ";", or "-". it is often trivial to patch free and open source software to use a different separator.
As there is currently no agreement on what character this alternative separator should be, there can be interoperability difficulties between different Maildir-supporting programs on these systems. However, not all Maildir-related software needs to know what the separator character is, because not all Maildir-related software needs to be able to read or modify the flags of a message ("read", "replied to" etc.); software that merely delivers to a Maildir, or archives old messages from it based only on date, should work no matter what separator is in use. If only the MUA needs to read or modify message flags, and only one is used, then non-standard alternative separators may be used without interoperability problems.
Software that supports Maildir directly
- bincimap IMAP server
- Dovecot IMAP server
- Courier Mail Server SMTP and IMAP server, for which the Maildir++ format was invented
- Exim SMTP server
- Postfix SMTP server
- Qmail SMTP server, for which the Maildir format was invented
- XMail, an open source cross-platform (*nix and Windows) SMTP and POP3 server
- MeTA1 SMTP server
- MagicMail Email Server
- UW IMAP, through an external patch
- OpenSMTPD SMTP server
- Dovecot delivery agent
- Getmail, a Maildir-aware mail-retrieval and delivery agent alternative to Fetchmail
- Alpine through a patch
- Balsa previously the official GNOME mail reader (prior to Evolution)
- Cone a curses-based mail reader
- Evolution, official GNOME mail client
- KMail, KDE mail reader
- Pine through a patch
- sup The hacker's Mail User Agent
- Thunderbird (beta 38)
Mail index and search tools
- Beagle (software) can index Maildirs and many other information storage formats
- Mairix is a program for indexing and searching email messages stored in maildir, MH or mbox folders
- Mboxgrep is a program that can search through maildir folders. It is similar to using grep
- Notmuch is a program for indexing and searching email messages stored in maildir
- mu is a set of command-line tools for searching in maildirs
Notes and references
- Daniel J. Bernstein. (1995) Using maildir format (the original specification)
- Sam Varshavchik (2009). "maildir". Retrieved 24 July 2016.
- Sam Varshavchik (2011). "Maildir++". Retrieved 24 July 2016.
- "rename". The Open Group. 2013. Retrieved 23 July 2016.
That specification requires that the action of the function be atomic.
- Sam Varshavchik (25 July 2016). "Management of maildir structures". courier-users (Mailing list). Retrieved 26 July 2016.
- Dovecot Wiki: maildir format
- mutt maildir support: workaround for filesystems that don't accept colons
- "Sup: The hacker's Mail User Agent". 2013-11-16.
- Thunderbird 38 goes to beta! 2015.04.03