10.2 Mailbox Deliveries

Qmail has two built-in delivery programs: one for mbox mailbox files and one for Maildir directories. In either case, the delivery is attempted under the recipient's user ID and primary group ID, so the mailbox must be writable by the user.

If a line in a .qmail file starts with a dot or slash and doesn't end with a slash, it's taken to be the name of an mbox mailbox file. To do the delivery, qmail-local opens the file for appending, creating it if it doesn't exist. It then locks the file using the flock( ) or lockf( ) system call.[2] If it can't set the lock within 30 seconds, the delivery fails temporarily. Once the file is opened and locked, qmail-local writes a traditional separator line, then the Return-Path: and Delivered-To: lines to provide the message envelope information, then the message, and a newline at the end. Any message line that starts with From, possibly preceded by some number of > angle brackets is quoted by preceding the line with an angle bracket. (This makes it possible to recover the original message by deleting one bracket from any such line.) It then calls fsync( ) to flush the file to disk and closes the file. The delivery fails if qmail-local can't create or lock the file, or if any of the writes to the file or the fsync( ) fail.

[2] Some mail systems lock mailboxes in different ways, but qmail doesn't. If flock or lockf isn't adequate for locking your mailboxes, you should switch to Maildirs, which don't need locks to work correctly.

If a line in a .qmail starts with a dot or slash and does end with a slash, it's taken to be the name of a Maildir directory. First, qmail-local forks, and the child process does the delivery. The child makes the Maildir its current directory, then creates a new file named tmp/t.p.h where t is the time in seconds since 1970 (the standard internal Unix time format), p is the process ID, and h is the hostname, so a typical name would be tmp/1012345678.34567.mail.example.com. It then writes the Return-Path: and Delivered-To: lines to the file, followed by the message. Unlike mailbox format files, the message is written literally and there is no need to quote lines. It then calls fsync( ) to flush the file to disk, closes the file, links the file from tmp to new, and unlinks the tmp file. The delivery fails if qmail-local can't change directory to the Maildir, create or lock the file, or if any of the writes to the file, the fsync, or the link fail. The delivery also fails temporarily if the delivery subprocess doesn't complete in 24 hours, an error I have never seen but might occur with deliveries to an unavailable NFS filesystem. Maildir deliveries do not need explicit locking because the operating system has internal locks that make system calls to create and rename files atomic.



qmail
qmail
ISBN: 1565926285
EAN: 2147483647
Year: 2006
Pages: 152

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net