1999-10-15-16:16:03 Jay Orr:
I must be missing it -- where is some info on maildir ? I see it mentioned on the qmail page, but I can't find the source and the homepage...
URL:http://www.qmail.org/qmail-manual-html/man5/maildir.html URL:ftp://koobera.math.uic.edu/www/proto/maildir.html URL:ftp://ftp.cs.hmc.edu/pub/me/mutt/contrib/maildir.c
For a quick overview, a Maildir is a directory with 3 subdirectories, named "tmp", "new", and "cur" (in the order messages flow through them).
dirname/tmp/ dirname/new/ dirname/cur/
When delivering a new message to a maildir, the writer opens a file under tmp/, with a guaranteed-unique name, typically built up from the time, the pid of the writer, and the hostname. This only counts on the inability to wrap pids within one second, and so far that seems safe. If a single writer (with a single pid) wants to write multiple messages (which it might easily do within a second) it includes a sequence number in the filename. But you can build filenames however you want as long as they're universally unique.
So once the writer has completed writing the message into tmp/, flushed it and closed it and so on, it links it into new/, where it appears for the benefit of mail readers. When a mail reader wants to indicate a change in its status (typically "it's been read, it's not new any more") it renames it over into cur/, and appends some flags to the filename. The contents normally never get rewritten.
If you read djb's docs, he specifies in exquisite detail the precise syscalls you should use, in what order, to write portable code that interacts with maildirs in perfect safety. That makes it seem a lot more complex. For many purposes the far cruder approach works fine, e.g. a local delivery agent
#!/bin/sh -e cd $HOME/Maildir fn=`date +%s`.$$.`hostname` cat >tmp/$fn mv tmp/$fn new/
Yup, it ain't perfect, but it's close enough to be robust in a lot of settings:-).
-Bennett