Using maildir

Using Maildir at CSE

What is it?

Many people at CSE store their CSE email in their home directory. The email is delivered to .incoming-mail which is usually a person's largest and most active mail folder. Often, mail is then moved to various folders in ~/mail/. The particular folder it is moved to is determined by the mail's origin, topic or time of creation. The typical mail box file format in UNIX is mbox in which a mail folder and all of the messages in it are lumped into a single file. This format tends to work well where concurrent read/write operations on a mail folder are rare, such as with mail archives. A popular alternative to mbox is the Maildir format. This has the advantage that the mail items are in separate files which means that:
  • File locking of the mail folder is not as crucial. Incorrect locking of mbox files is a cause of many mail access problems at CSE.
  • File corruption will only disrupt a few mail items and not make a whole folder inaccessible.
  • Nightly backups at CSE need to only save new mail items in the folder. If you have large mail folders that change regularly then Maildir might fix an issue you can have with backup file limits. (See Why weren't my files backed up?)

What can use Maildir?

The IMAP server at CSE will access ~/Maildir in preference to ~/mail by default. If you use CSE's webmail service or connect to our IMAP service then this lets you use Maildir. UNIX mail readers such as mutt can also use Maildir format folders. Currently pine cannot.

Converting your mbox folders to folders in ~/Maildir

  1. Close all IMAP connections and applications accessing your mail folders
  2. Log into a UNIX machine and run mb2md -R -s ~/mail/ -d ~/Maildir
  3. or somthing along those lines where files in the source (mail) are in mbox format. If there is many mbox folders in ~/mail when you run the command each individual mbox will get created in ~/Maildir/.mbox-name etc. You can then subscribe to these folders in your email application to create the same folder structure as before.
  4. Perform conversion on the Inbox by running mb2md -s ~/.incoming-mail -d ~/Maildir
  5. converted mails will be placed in ~/Maildir/cur/.
The next time you log in the IMAP server will be displaying mail folders in the ~/Maildir directory instead of the ~/mail directory. The general format of a maildir tree structure is as follows ~/Maildir cur/ new/ tmp/ subscriptions another-folder/ cur/ new/ tmp/ another-folder1/ cur/ new/ tmp/ . . Your inbox mail will be stored in ~/Maildir/cur/.

Changing your INBOX to Maildir

Unfortunately, your .incoming-mail file is still the first folder that your mail goes to and it is not in Maildir format. You will need to perform some further configuration to change this. You can configure your mail client to move the mail to a folder in the ~/Maildir directory to get the benefit of using the Maildir storage format. You can also use a procmail configuration to move the mails as they are received. To use procmail you will need to place a .procmailrc file in your home directory. The contents of a sample file are below # .procmailrc # routes incoming mail to appropriate mailboxes PATH=/usr/bin:/usr/local/bin MAILDIR=${HOME}/Maildir DEFAULT=${MAILDIR}/ #LOGFILE=${HOME}/.procmaillog LOGFILE=/dev/null SHELL=/bin/sh VERBOSE=on :0: * ^TO_.*seminar(s)?@cse.unsw.edu.au .seminars/ The above file has one procmail rule in it, saying that any mail we receive from the seminar mailing list will be put into the seminars folder in ~/Maildir/. It should be noted that the trailing slash on the .seminars/ is needed to make sure that procmail inserts the message in a maildir format not an mbox format.

Setting your environment variables

If you would like totally bypass your incoming-mail file you will need to set your environment variable $MAIL to be your Maildir folder. This can be achieved by making a change in your .bashrc or .profile files. An example from my file can be found below. export MAIL=$HOME/Maildir/

Housekeeping

Should there be configuration files referring to the old mbox like .incoming-mail or similar, they should be changed to refer to the corresponding folders under Maildir. If you have .backup files to exclude mail folders from backup or filemax limit, etc... then you should review how they work. For instance, any reference to .incoming-mail could be changed to Maildir/ instead.
Last edited by robertd 26/04/2015

Tags for this page:

maildir, email, IMAP