Maildir
The Maildir e-mail format is a common way of storing email messages in which each message is stored in a separate file with a unique name, and each mail folder is a file system directory. The local file system handles file locking 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. Specifications. A Maildir directory (often named codice_1) usually has three subdirectories named codice_2, codice_3, and codice_4. The codice_2 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 codice_3 subdirectory stores messages that have been delivered, but have not yet been seen by any mail application. The codice_4 subdirectory stores messages that have already been seen by mail applications. Maildir++. 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. Technical operation. A mail delivery agent is a program that delivers an email message into a Maildir. The mail delivery agent creates a new file with a unique filename in the codice_2 directory. The original algorithm circa 1995 for generating unique filenames, as implemented by qmail was: 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: This algorithm was criticised in 2006 by Timo Sirainen, the creator of Dovecot. As of November 2018, qmail author Bernstein had made no further changes to these filename generation recommendations. On modern POSIX systems, temporary files can be safely created with the codice_19 C library function. The delivery process stores  the message in the maildir by creating and writing to codice_20, and then moving this file to codice_21. The moving can be done using codice_22, which is atomic in many systems. Alternatively, it can be done by hard-linking the file to codice_3 and then unlinking the file from codice_2. 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 of 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 codice_2. When a cognizant maildir-reading process (either a POP or IMAP server, or a mail user agent acting locally) finds messages in the codice_3 directory, it "must" move them to codice_4. It is just a means to notify the user "you have "X" new messages". This moving needs to be done using codice_17, 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 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 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  MUA is used, then non-standard alternative separators may be used without interoperability problems.