Programmatically manipulating mailbox

software development


Hi all –

From my old server, I have Perl scripts which I use to manage my mailbox. The old system gave me a file /var/mail/ with all the messages in it, and I could read and write it (with appropriate locking) to filter stuff.

What’s the right way to do this under Dreamhost’s email system? I see ~/Maildir with various subdirectories and files for my mail, but it seems (experimentally heh) that I can’t just go willy-nilly moving them around and expect the mail system (IMAP?) to work.

What do I do? Is there some well-known spec that will guide me?

I’m a highly skilled programmer/scripter, but I don’t know the rules of this mail system.

Al guidance appreciated! thanks.

Polyominoes and Pixels


I use a couple of Python programs to manage my spam folders, and I think you can just manipulate the message files and it will work. It may be necessary to rename the files, and put them in the “new” subdirectory to get the IMAP server to notice the changes. The filenames encode some attributes about the messages, but I’ve found that if you want to create a new message just picking a unique name is sufficient. There is documentation for Maildirs online if you want more details.

The basic structure is that the Maildir directory represents your main Inbox; new messages are put into the “new” subdirectory and moved to “cur” when first read. If you create a mail folder named Test within your Inbox, the messages are stored in the .Test subdirectory (again in “new” and “cur”).


Are you also highly skilled at using google?

Much as I hate djb, he wrote the Maildir spec, so this is the canonical document:

Courier IMAP uses its own weird Maildir++ format, which creates a hierarchy for submailboxes - all of these show up as sub-mailboxes of the inbox, and are arranged like:

Maildir/.foo =
Maildir/ =
(i.e., bar is a subfolder of foo which is a subfolder of bar)

Maildirs are pretty easy to work with, from a scripting point of view, because locking is unnecessary if you follow the rules, and each message is in its own file.