Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Maildir
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Technical operation == A [[mail delivery agent]] is a [[Computer process|program]] that delivers an email message into a Maildir. The mail delivery agent creates a new file with a unique filename in the <code>tmp</code> directory.<ref name="djbspec-2000"/><ref name="dovecot"/><ref name="courier-maildir"/> At the time of its invention guaranteeing unique filenames efficiently was difficult. The original [[qmail]]<ref name="qmail-manpage"/> algorithm for unique names was: # read the current [[Unix time]] # read the current [[process identifier]] (PID) # read the current [[hostname]] # concatenate the above three values into a string separated by the [[Full stop|period character]]; this is the new filename # if [[stat (system call)|<code>stat()</code>]] 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 qmail author recommended in an updated specification<ref name="djbspec-2000"/> to append the value of a per-process counter to the PID, whose value should be incremented after each delivery. The rate-limiting recommendation to "wait two seconds" was 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:<ref name="djbspec-2003"/> <blockquote> * #''n'', where ''n'' is (in hexadecimal) the output of the operating system's <code>unix_sequencenumber()</code> 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 <code>unix_bootnumber()</code> 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 <code>unix_sequencenumber()</code> and <code>unix_bootnumber()</code>. * R''n'', where ''n'' is (in hexadecimal) the output of the operating system's <code>unix_cryptorandomnumber()</code> system call or an equivalent source, such as <code>/dev/urandom</code>. Unfortunately, some operating systems don't include cryptographic random number generators. * I''n'', where ''n'' is (in hexadecimal) the UNIX [[inode]] number of this file. Unfortunately, inode numbers aren't always available through [[Network File System|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 <code>link()</code> and <code>rename()</code> to work.) * M''n'', where ''n'' is (in decimal) the microsecond counter from the same <code>gettimeofday()</code> 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. </blockquote> This 2003 algorithm was criticised<ref name="dovecot-2006-crit"/> in 2006 as being unnecessarily complex by [[Timo Sirainen]], the creator of [[Dovecot (software)|Dovecot]]. As of November 2023, qmail author [[Daniel J. Bernstein|Daniel Bernstein]] had made no further changes to the 2003 filename generation recommendations.<ref name="djbspec-hist"/> On modern POSIX systems, [[temporary file]]s can be safely created with the <code>[[mkstemp]]</code> C library function. The delivery process stores the message in the maildir by creating and writing to <code>tmp/''uniquefilename''</code>, and then moving this file to <code>new/''uniquefilename''</code>. The moving can be done using <code>[[rename (computing)|rename]]</code>, which is atomic in many systems.<ref name="opengroup-rename"/> Alternatively, it can be done by [[hard link|hard-linking]] the file to <code>new</code> and then unlinking the file from <code>tmp</code>. 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]]s (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 (Unix)|biff]] and [[rsync]], which may or may not be aware of the maildir structure. Readers should never look in <code>tmp</code>. When a cognizant maildir-reading process (either a [[Post Office Protocol|POP]] or [[Internet Message Access Protocol|IMAP]] server, or a mail user agent acting locally) finds messages in the <code>new</code> directory, it ''must'' move them to <code>cur</code>. It is just a means to notify the user "you have ''X'' new messages".<ref name="courier-msg38512"/> This moving needs to be done using the atomic filesystem <code>rename()</code>, as the alternative ''link-then-unlink'' technique is non-atomic and may result in duplicated messages. An informational suffix is appended to filenames at this stage. It consists of a [[colon (punctuation)|colon]] (to separate the unique part of the filename from the actual information), a "2", a [[comma]] and various [[flag (computing)|flag]]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".<ref name="djbspec-2003"/> Applications often choose to supplement this very limited set of flags, for example notmuch<ref>{{Cite web|url=https://notmuchmail.org/|title=Notmuch mail system homepage|website=notmuchmail.org|access-date=2019-06-22}}</ref> offers flag synchronization in addition to arbitrary user-defined flags,<ref name="notmuch-config d147">{{cite web | title=notmuch 0.38.3 documentation | website=notmuch-config | url=https://notmuchmail.org/doc/latest/man1/notmuch-config.html#nmconfig-maildir.synchronize_flags | access-date=2024-04-17}}</ref> while Dovecot uses lowercase letters to match 26 IMAP keywords,<ref name="dovecot"/> which may include keywords such as $[[Message Disposition Notification|MDNSent]] or user-defined flags. Although Maildir was intended to allow lockless usage, in practice some software that uses Maildirs also uses locks, such as Dovecot.<ref name="dovecot-2006-crit-2"/>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Maildir
(section)
Add topic