D. J. Bernstein
Internet mail

Using maildir format

Why should I use maildir?

Two words: no locks. An MUA can read and delete messages while new mail is being delivered: each message is stored in a separate file with a unique name, so it isn't affected by operations on other messages. An MUA doesn't have to worry about partially delivered mail: each message is safely written to disk in the tmp subdirectory before it is moved to new. The maildir format is reliable even over NFS.

How are unique names created?

Unless you're writing messages to a maildir, the format of a unique name is none of your business. A unique name can be anything that doesn't contain a colon (or slash) and doesn't start with a dot. Do not try to extract information from unique names.

Okay, so you're writing messages. A unique name has three pieces, separated by dots. On the left is the result of time() or the second counter from gettimeofday(). On the right is the result of gethostname(). (To deal with invalid host names, replace / with \057 and : with \072.) In the middle is a delivery identifier, discussed below.

As the terminology suggests, every delivery to this maildir must have its own unique name. When a maildir is shared through NFS, every machine that delivers to the maildir must have its own hostname. Within one machine, every delivery within the same second must have a different delivery identifier.

Modern delivery identifiers are created by concatenating enough of the following strings to guarantee uniqueness:

Old-fashioned delivery identifiers use the following formats:

What can I put in info?

When you move a file from new to cur, you have to change its name from uniq to uniq:info. Make sure to preserve the uniq string, so that separate messages can't bump into each other.

info is morally equivalent to the Status field used by mbox readers. It'd be useful to have MUAs agree on the meaning of info, so I'm keeping a list of info semantics. Here it is.

info starting with "1,": Experimental semantics.

info starting with "2,": Each character after the comma is an independent flag.

New flags may be defined later. Flags must be stored in ASCII order: e.g., "2,FRS".

Can a maildir contain more than tmp, new, cur?