Maildir
   HOME

TheInfoList



OR:

The Maildir
e-mail Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email was thus conceived as the electronic ( digital) version of, or counterpart to, mail, at a time when "mail" meant ...
format is a common way of storing
email Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email was thus conceived as the electronic ( digital) version of, or counterpart to, mail, at a time when "mail" meant ...
messages in which each message is stored in a separate
file File or filing may refer to: Mechanical tools and processes * File (tool), a tool used to ''remove'' fine amounts of material from a workpiece **Filing (metalworking), a material removal process in manufacturing ** Nail file, a tool used to gent ...
with a unique name, and each mail folder is a file system directory. The local
file system In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
handles
file locking File locking is a mechanism that restricts access to a computer file, or to a region of a file, by allowing only one user or process to modify or delete it at a specific time and to prevent reading of the file while it's being modified or deleted ...
as messages are added, moved and deleted. A major design goal of Maildir is to eliminate the need for program code to handle file locking and unlocking. __TOC__


Specifications

A Maildir
directory Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network's u ...
(often named Maildir) usually has three subdirectories named tmp, new, and cur. The tmp subdirectory temporarily stores e-mail messages that are in the process of being delivered. This subdirectory may also store other kinds of temporary files. The new subdirectory stores messages that have been delivered, but have not yet been seen by any mail application. The cur subdirectory stores messages that have already been seen by mail applications.


Maildir++

Sam Varshavchik, the author of the
Courier Mail Server The Courier Mail Server is a mail transfer agent (MTA) server that provides SMTP, IMAP, POP3, SMAP, webmail, and mailing list services with individual components. It is best known for its IMAP server component. Courier can function as an interme ...
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 complies with the Maildir specification, which explicitly provides for the possibility to add more than tmp, new, cur to a maildir.


Technical operation

A
mail delivery agent A message delivery agent (MDA), or mail delivery agent, is a computer software component that is responsible for the delivery of e-mail messages to a local recipient's mailbox., ''Internet Mail Architecture'', D. Crocker (July 2009) It is also call ...
is a
program Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Progra ...
that delivers an email message into a Maildir. The mail delivery agent creates a new file with a unique filename in the tmp directory. The original algorithm circa 1995 for generating unique filenames, as implemented by
qmail qmail is a mail transfer agent (MTA) that runs on Unix. It was written, starting December 1995, by Daniel J. Bernstein as a more secure replacement for the popular Sendmail program. Originally license-free software, qmail's source code was ...
was: # read the current
Unix time Current Unix time () Unix time is a date and time representation widely used in computing. It measures time by the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, the beginning of the Unix epoch, less adjustments m ...
# read the current
process identifier In computing, the process identifier (a.k.a. process ID or PID) is a number used by most operating system kernels—such as those of Unix, macOS and Windows—to uniquely identify an active process. This number may be used as a parameter in various ...
(PID) # read the current
hostname In computer networking, a hostname (archaically nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web. Hos ...
# concatenate the above three values into a string separated by the period character; this is the new filename # if stat() reports that the filename exists, then wait two seconds # go to previous step until the filename does not exist # create a file with the unique filename and write the message contents to the new file By 2000, the author of qmail recommended to append the value of a per-process counter to the PID, whose value should be incremented after each delivery, and the rate-limiting suggestion had been dropped. By 2003, the recommendations had been further amended to require that instead of the PID and counter, the middle part of the filename should be created by "concatenating enough of the following strings to guarantee uniqueness" even in the face of multiple simultaneous deliveries to the same maildir from one or more processes:
* #''n'', where ''n'' is (in hexadecimal) the output of the operating system's unix_sequencenumber() system call, which returns a number that increases by 1 every time it is called, starting from 0 after reboot. * X''n'', where ''n'' is (in hexadecimal) the output of the operating system's unix_bootnumber() system call, which reports the number of times that the system has been booted. Together with #, this guarantees uniqueness; unfortunately, most operating systems don't support unix_sequencenumber() and unix_bootnumber(). * R''n'', where ''n'' is (in hexadecimal) the output of the operating system's unix_cryptorandomnumber() system call or an equivalent source, such as /dev/urandom. Unfortunately, some operating systems don't include cryptographic random number generators. * I''n'', where ''n'' is (in hexadecimal) the UNIX
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
number of this file. Unfortunately, inode numbers aren't always available through NFS. * V''n'', where ''n'' is (in hexadecimal) the UNIX device number of this file. Unfortunately, device numbers aren't always available through NFS. (Device numbers are also not helpful with the standard UNIX filesystem: a maildir has to be within a single UNIX device for link() and rename() to work.) * M''n'', where ''n'' is (in decimal) the microsecond counter from the same gettimeofday() used for the left part of the unique name. * P''n'', where ''n'' is (in decimal) the process ID. * Q''n'', where ''n'' is (in decimal) the number of deliveries made by this process.
This algorithm was criticised in 2006 by
Timo Sirainen Timo Sirainen, born 1979, is a Finnish programmer also known under the nickname, handles "cras" and "tss". Sirainen is the original author of the IRC-client Irssi and the POP3, POP/IMAP server Dovecot (software), Dovecot. Sirainen lives in Helsink ...
, the creator of Dovecot, as being unnecessarily complex. As of November 2018, qmail author
Daniel Bernstein Daniel Bernstein is a composer for video games and movies. Born in Leningrad in the Soviet Union (now part of Russia), he received a B.S. in computer science and an M.A. in music composition from the University of Virginia. Bernstein started in ga ...
had made no further changes to these filename generation recommendations. On modern POSIX systems,
temporary file A temporary file is a file created to store information temporarily, either for a program's intermediate use or for transfer to a permanent file when complete. It may be created by computer programs for a variety of purposes, such as when a program ...
s can be safely created with the
mkstemp In computing, mkstemp is a POSIX function for creating a temporary file (a computer file which usually ceases to exist when the program, which opened the file, closes it or terminates). It accepts an argument that determines the location of the t ...
C library function. The delivery process stores the message in the maildir by creating and writing to tmp/''uniquefilename'', and then moving this file to new/''uniquefilename''. The moving can be done using
rename Rename may refer to: * Rename (computing), rename of a file on a computer * RENAME (command), command to rename a file in various operating systems * Rename (relational algebra) In relational algebra, a rename is a unary operation written as \r ...
, 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 agent The mail or post is a system for physically transporting postcards, letters, and parcels. A postal service can be private or public, though many governments place restrictions on private systems. Since the mid-19th century, national postal syst ...
s (MUAs), which access the server's file system directly, through
Internet Message Access Protocol In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection. IMAP is defined by . IMAP was designed with the goal of per ...
or
Post Office Protocol In computing, the Post Office Protocol (POP) is an application-layer Internet standard protocol used by e-mail clients to retrieve e-mail from a mail server. POP version 3 (POP3) is the version in common use, and along with IMAP the most common p ...
servers acting on behalf of remote MUAs, to utilities such as biff and
rsync rsync is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files. It is commonly found on Unix-like operat ...
, which may or may not be aware of the maildir structure. Readers should never look in tmp. When a cognizant maildir-reading process (either a POP or
IMAP In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection. IMAP is defined by . IMAP was designed with the goal of per ...
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 The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...
and various
flag A flag is a piece of fabric (most often rectangular or quadrilateral) with a distinctive design and colours. It is used as a symbol, a signalling device, or for decoration. The term ''flag'' is also used to refer to the graphic design empl ...
s. 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 that 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. Although Maildir was intended to allow lockless usage, in practice some software that uses Maildirs also uses locks, such as Dovecot.


File-system 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 Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
and some configurations of
Novell Storage Services Novell Storage Services (NSS) is a file system used by the Novell NetWare operating system. Support for NSS was introduced in 2004 to SUSE Linux via low-level network NCPFS protocol. It has some unique features that make it especially useful for ...
) can use an alternative separator, such as ";" or "-". It is often trivial to patch
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
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 MUA is used, then non-standard alternative separators may be used without interoperability problems.


Software that supports Maildir directly


Mail servers

* Dovecot IMAP server *
Courier Mail Server The Courier Mail Server is a mail transfer agent (MTA) server that provides SMTP, IMAP, POP3, SMAP, webmail, and mailing list services with individual components. It is best known for its IMAP server component. Courier can function as an interme ...
SMTP and IMAP server, for which the Maildir++ format was invented *
Sendmail Sendmail is a general purpose internetwork email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet. A descendant of the ...
The original SMTP server *
Exim Exim is a mail transfer agent (MTA) used on Unix-like operating systems. Exim is free software distributed under the terms of the GNU General Public License, and it aims to be a general and flexible mailer with extensive facilities for checking ...
SMTP server * Postfix SMTP server *
qmail qmail is a mail transfer agent (MTA) that runs on Unix. It was written, starting December 1995, by Daniel J. Bernstein as a more secure replacement for the popular Sendmail program. Originally license-free software, qmail's source code was ...
SMTP server, for which the Maildir format was invented *
MeTA1 MeTA1 is a mail transfer agent (MTA) that has been designed with these main topics in minds: security, reliability, efficiency, configurability and extendibility. It supports the Simple Mail Transfer Protocol (SMTP) as specified by RFC 2821 and va ...
SMTP server *
OpenSMTPD OpenSMTPD (also known as OpenBSD SMTP Server) is a Unix daemon implementing the Simple Mail Transfer Protocol to deliver messages on a local machine or to relay them to other SMTP servers. It was publicly released on 17 March 2013 with version nu ...
SMTP server


Delivery agents

*
procmail procmail is an email server software component — specifically, a message delivery agent (MDA). It was one of the earliest mail filter programs. It is typically used in Unix-like mail systems, using the mbox and Maildir storage formats. procm ...
* Dovecot delivery agent *
maildrop Maildrop is a Mail delivery agent used by the Courier Mail Server. The maildrop Mail Delivery Agent (MDA) also includes filtering functionality. Maildrop receives mail via stdin and delivers in both Maildir and mbox formats. Features Mai ...
*
getmail getmail is a simple mail retrieval agent intended as a replacement for fetchmail, implemented in Python. It can retrieve mail from POP3, IMAP4, and ''Standard Dial-up POP3 Service'' servers, with or without SSL. It supports simple and domain ...
, a Maildir-aware mail-retrieval and delivery agent alternative to
Fetchmail Fetchmail is an open-source software utility for POSIX-compliant operating systems which is used to retrieve e-mail from a remote POP3, IMAP, or ODMR mail server to the user's local system. It was developed from thpopclientprogram, written by Ca ...
* fdm *
OfflineIMAP OfflineIMAP is IMAP synchronization utility software, capable of synchronizing mail on IMAP server with local Maildir folder or another server. Description The synchronization is performed bidirectionally between two endpoints ("Remote" and "L ...
* mbsync


Mail readers

*aerc (efficient and extensible email client) *
Balsa ''Ochroma pyramidale'', commonly known as the balsa tree, is a large, fast-growing tree native to the Americas. It is the sole member of the genus ''Ochroma''. The tree is famous for its wide usage in woodworking, with the name ''balsa'' being ...
previously the official GNOME mail reader (prior to Evolution) *
Cone A cone is a three-dimensional geometric shape that tapers smoothly from a flat base (frequently, though not necessarily, circular) to a point called the apex or vertex. A cone is formed by a set of line segments, half-lines, or lines con ...
a curses-based mail reader *
Evolution Evolution is change in the heritable characteristics of biological populations over successive generations. These characteristics are the expressions of genes, which are passed on from parent to offspring during reproduction. Variation ...
, official GNOME mail client *
GNUMail GNUMail is a free and open-source, cross-platform e-mail client based on GNUstep and Cocoa. It is the official mail client of GNUstep and is also used in Étoilé. It was inspired by NeXTMail (NeXT's Mail.app), the predecessor of Apple Mail. ...
*
Gnus Gnus (), or Gnus Network User Services, is a message reader which is part of GNU Emacs. It supports reading and composing both e-mail and news and can also act as an RSS reader, web processor, and directory browser for both local and remote files ...
*
KMail Kontact is a personal information manager and groupware software suite developed by KDE. It supports calendars, contacts, notes, to-do lists, news, and email. It offers a number of inter-changeable graphical UIs (KMail, KAddressBook, Akregator, ...
, KDE mail reader *
mailx mailx is a Unix utility program for sending and receiving mail, also known as a Mail User Agent program. Being a console application with a command syntax similar to ed, it is the POSIX standardized variant of the Berkeley Mail utility. See als ...
* Mutt *Notmuch (fast, global-search and tag-based email system) * Pine/Alpine *
Mozilla Thunderbird Mozilla Thunderbird is a free and open-source cross-platform email client, personal information manager, news client, RSS and chat client developed by the Mozilla Foundation and operated by subsidiary MZLA Technologies Corporation. The project s ...
– experimental and “disabled by default because there are still many bugs”


Notes and references

{{reflist, refs= {{cite web , first=Daniel J. , last=Bernstein. , author-link=Daniel J. Bernstein , year=c. 2000 , url=http://cr.yp.to/proto/maildir.html , title=Using maildir format , archive-url=https://web.archive.org/web/20000902121438/http://cr.yp.to/proto/maildir.html , archive-date=2000-09-02 , orig-year=First published 2000 or earlier , url-status=live , access-date=2018-11-23 {{cite web , first=Daniel J. , last=Bernstein. , author-link=Daniel J. Bernstein , year=2003, url=http://cr.yp.to/proto/maildir.html , title=Using maildir format , archive-url=https://web.archive.org/web/20030401082238/https://cr.yp.to/proto/maildir.html , archive-date=2003-04-01 , orig-year=The earliest version of this document was first published in 2000 or earlier , url-status=live , access-date=2018-11-23 {{cite web , url=https://web.archive.org/cdx/search/cdx?url=cr.yp.to/proto/maildir.html , publisher=
Internet Archive The Internet Archive is an American digital library with the stated mission of "universal access to all knowledge". It provides free public access to collections of digitized materials, including websites, software applications/games, music, ...
, access-date=2018-11-23 , title=Wayback Machine snapshots of cr.yp.to/proto/maildir.html , year=2018
{{cite web , url=http://www.courier-mta.org/maildir.html , title=maildir , author=Sam Varshavchik , year=2009 , access-date=24 July 2016 {{cite mailing list , url=http://www.mail-archive.com/courier-users@lists.sourceforge.net/msg38512.html , title=Management of maildir structures , date=25 July 2016 , access-date=26 July 2016 , mailing-list=courier-users , author=Sam Varshavchik {{cite web , url=http://www.courier-mta.org/imap/README.maildirquota.html , title=Maildir++ , author=Sam Varshavchik , year=2011 , access-date=24 July 2016 Dovecot Wiki: maildir format
/ref> mutt maildir support: workaround for filesystems that don't accept colons
/ref> {{cite web , url=https://wiki2.dovecot.org/MailboxFormat/Maildir?action=diff&rev1=11&rev2=12 , title=Diff for 'MailboxFormat/Maildir' , first=Timo , last=Sirainen , author-link=Timo Sirainen , access-date=2018-11-23 , date=2006-12-05, quote="All this trouble is rather pointless. Only the first step is what really guarantees that the mails won't get overwritten, the rest just sounds nice. Even though they might catch a problem once in a while, they give no guaranteed protection and will just as easily pass duplicate filenames through to overwrite existing mails. Step 2 is pointless because there's a race condition between steps 2 and 3. PID/host combination by itself should already guarantee that it never finds such a file. If it does, something's broken and the stat() check won't help since another process might be doing the same thing at the same time, and you end up writing to the same file in tmp/, causing the mail to get corrupted. In step 4 the link() would also fail if identical file was already in the maildir, right? Wrong. The file may already have been moved to cur/ directory, and since it may contain any number of flags by then you can't check with a simple stat() anymore if it exists or not. So really, all that's important in not getting mails overwritten in your maildir is the step 1: Always create filenames that are guaranteed to be unique. Forget about the 2 second waits and such that the Qmail's man page talks about" {{cite web , url=https://wiki2.dovecot.org/MailboxFormat/Maildir?action=diff&rev1=13&rev2=14 , title=Diff for 'MailboxFormat/Maildir' , first=Timo , last=Sirainen , author-link=Timo Sirainen , access-date=2018-11-23 , date=2006-12-05 {{cite web , url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html , title=rename , author= , year=2013 , publisher=
The Open Group The Open Group is a global consortium that seeks to "enable the achievement of business objectives" by developing "open, vendor-neutral technology standards and certifications." It has over 840 member organizations and provides a number of servi ...
, access-date=23 July 2016 , quote=That specification requires that the action of the function be atomic.
{{cite web , archive-url=https://web.archive.org/web/19971012032244/http://www.qmail.org/qmail-manual-html/man5/maildir.html , url=http://www.qmail.org/qmail-manual-html/man5/maildir.html , first=Daniel J. , last=Bernstein , author-link=Daniel J. Bernstein , title=maildir(5) , archive-date=1997-10-12 , year=1995 , access-date=2018-11-23 , url-status=dead


See also

*
mbox Mbox is a generic term for a family of related file formats used for holding collections of email messages. It was first implemented in Research Unix, Fifth Edition Unix. All messages in an mbox mailbox are concatenated and stored as plain text ...
*
MH Message Handling System The MH Message Handling System is a free, open source e-mail client. It is different from almost all other mail reading systems in that, instead of a single program, it is made from several different programs which are designed to work from the co ...
*
MIX (email) MIX is a high-performance, indexed, on-disk email storage system that is designed for use with the IMAP protocol. MIX was designed by Mark Crispin, the author of the IMAP protocol. Server support for it has been included in releases of UW IMAP si ...


External links


manual page for maildir


Email storage formats