Converting from UNIX mbox/mailbox to Maildir

This guide discusses transforming a system from the traditional mbox/mailbox format to the more advanced Maildir format.

I assume you are using the postfix mailer - if not, you will probably want to change over to postfix first or some of this material may not be relevant.

Make a backup

Before commencing, backup your entire system.

Stop the mailer

You do not want any mail coming in while doing the conversion. You should also stop any programs that automatically generate mail locally.


# /etc/init.d/postfix stop

Get the necessary tools

If you are running Debian, this command will get everything you need:


# apt-get install mb2md

Convert each users mail

For each user on your system:


# su daniel
$ cd ~
$ mb2md -m
$ mb2md -s mail
$ exit
# mv /var/spool/mail/daniel /var/spool/mail/daniel.preMaildir
# mv ~daniel/mail ~daniel/mail.preMaildir

NOTE: The second mb2md command is only needed if the user has a directory ~/mail where they store mbox/mailbox format mail folders.

Later on, you will want to delete the .preMaildir versions to recover disk space. Before you do so, make sure everything is working fine.

Configure postfix

If you are using the built in delivery agent you should put this into /etc/postfix/main.cf:


home_mailbox = Maildir/

If you are using procmail as your delivery agent, you should put this into /etc/postfix/main.cf (it is all one line):


mailbox_command = /usr/bin/procmail -a "$EXTENSION" DEFAULT=$HOME/Maildir/ MAILDIR=$HOME/Maildir

If you are using another delivery method, you should refer to the documentation that comes with it.

If you are using LDAP, you may need to put an attribute into each user's entry in the directory. The attribute needs to specify the full path of the Maildir, with a trailling /

Configure each procmailrc

If users have their own .procmailrc files, then they need to be updated. This could be time consuming.

Wherever a folder name is specified, such as /home/daniel/mail/folder1, it needs to be changed to .folder1/ - you don't need to put the complete filesystem path, just the full stop, a folder name and a trailling slash.

Original .procmailrc:


:0
* ^From.*xyz-list@xyz-domain.com
/home/daniel/mail/xzy-list

changed for Maildirs:


:0
* ^From.*xyz-list@xyz-domain.com
.xyz-list/

Remove uw-imap, install cyrus-imap

If you are using uw-imap to access your mail, you will need to find a new IMAP server. Try cyrus-imap. On Debian, just type:


# apt-get install cyrus-imap

Reconfigure squirrelmail

If you use squirrelmail, you need to make the following changes:


# /etc/squirrelmail/conf.pl

Section (2) "Server Settings", change the IMAP server type to "Cyrus" and make sure that "delimiter" is set to "detect".

Section (3) "Folder Settings", make sure the first option, "Default Folder Prefix" is blank.

You will also need to change the prefs file for each individual user (I hope you know how to use sed, or you could be editing a lot of text files by hand!).

For user daniel, the file to change is /var/lib/squirrelmail/data/daniel.prefs

You simply need to make sure these values are correct, this is what I use for compatibility with my other IMAP client, Mozilla Thunderbird (package icedove on Debian):


trash_folder=INBOX.Trash
sent_folder=INBOX.Sent
draft_folder=INBOX.Drafts

Start postfix

Don't forget this last step, or you won't receive any mail for a few days.


# /etc/init.d/postfix start

Comments

Thank you, this walk-through was a great help to me today!

thx for your help

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.