Maildir

The newest mailbox format covered here is Maildir. It was invented for use with the Qmail MTA, which was designed as a replacement for the venerable sendmail. It is an enhancement to the MH format and adds some important functionality.

A Maildir mailbox is, like an MH one, a directory. The directory name is the mailbox name. Each message is stored in a file of its own.

Maildir mailboxes contain at least three subdirectories: tmp, new, and cur. An incoming message is fully written to the tmp directory, then moved to new when complete. A message is moved to cur (and its name changed, as we shall see) after it has been viewed by an MUA.

Each message in a Maildir mailbox has a name that is guaranteed to be unique but is not related to the message number. This, along with the directory scheme, allows multiple processes to write messages to the mailbox with no need of file locking. This allows the Maildir format to be used safely over NFS or other time-delayed file-systems.

Filenames are not allowed to contain the colon or forward slash characters (: or /) and are not allowed to start with a period (.). Each name has three parts, which are separated with a period (.).

The first part is the number of seconds since midnight, January 1, 1970, measured in seconds [13] and represents the time that the file was written. The second part is a number that is guaranteed to be unique within one second on the host machine (to account for the fact that more than one message might have the same first part), and the third part is the hostname.

The second (middle) part can be built in one of three ways: If you are writing only one message per process, the process id (pid) may be used. If you are writing multiple messages from the same process, the pid and the message count be be used, separated by an underscore (i.e. pid_count).

For example, a message that was written on 17 December 1998 at 8:36:12 AM would have a first part of 913847772. We can see that this is true by doing something like this:

[lovelace]$ date ; perl -e 'print time . "
"'
Thu Dec 17 08:36:12 EST 1998
913847772
[lovelace]$

From Perl, the pid is available in the built-in $$ variable:

[lovelace]$ perl -e 'print $$ . "
"'
3984
[lovelace]$

and the hostname may be found using the Sys::Hostname module:

[lovelace]$ perl -e 'use Sys::Hostname; print hostname() . "
"'
lovelace. staff.plugged.com.au
[lovelace]$

Now, using all three, we can finally name a message file! If we call this message number 1, we can name it thusly:

913847772.3984_1.lovelace.staff.plugged.com.au

Some systems will just use the machine name part of the hostname, stripping the domain.

That should do it. One may be pretty certain of creating a unique filename. Since files are created initially in the “tmp” subdirectory and then moved into the “new” subdirectory, all files in those two subdirectories will be named with this scheme.

Once files are read, they are moved into the “cur” directory. The filenames are appended with a colon, followed by an “info” parameter. Two types of info parameters are currently defined; a “1,” followed by experimental markings or a “2,” followed by message flag.

This compares with the use of the Status header in mbox format.

Legal flags for Maildir messages are:

F

Marks (flags) a message as “important” to the user.

R

Marks a message as having been replied to.

S

Marks a message as having been seen.

T

Marks a message for deletion (trashed).

Any other one-letter flag

Defined by the system.

Flags must be listed in ASCII order. So, a message that has been seen by an MUA is immediately moved into the “cur” subdirectory. If it is replied to, its name will be changed to:

913847772.3984_1.lovelace.staff.plugged.com.au:2,RS

A directory listing of a Maildir mailbox might look like this:

[lovelace]$ ls Inbox/*
Inbox/cur:
913839876.3189.lovelace:2,S    913845634.431_2.lovelace:2,ST
913845634.431_1.lovelace:2,FRS

Inbox/new:
913847327.3782.lovelace   913847899.4511_1. lovelace

Inbox/tmp:
913847899.4511_2.lovelace
[lovelace]$

Whether you choose to use the more simple mbox format (or its variants) or the more complex Maildir format is a matter of design and taste. In short, you should use Maildir if you are concerned about file locking, especially in environments using NFS, and mbox otherwise. Most MUAs will implement a form of mbox.



[13] This is the output of the C time() call.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.10.137