Converting mbox’s to maildir format

Posted on February 1st, 2008 in General,Linux System Administration,Mail by Brandon

There is a handy utility for converting mbox style mailboxes into maildir format at http://batleth.sapienti-sat.org/projects/mb2md/

To convert all of the mailboxes on your server:

Edit /etc/sudoers and comment out the env_keep section. These variables make it so that the sudo command keeps some environment variables and tries to put things in the wrong directory.

Download mb2db, unzip it, and copy the binary to /bin (where all users can access it)

# wget http://batleth.sapienti-sat.org/projects/mb2md/mb2md-3.20.pl.gz
# gunzip mb2db-3.20.pl.gz
# cp mb2db-3.20.pl.gz / bin

Then run this command to convert all of the mailboxes into maildir format.

cd /var/spool/mail

for username in `ls`; do echo $username; sudo -u $username /bin/mb2md -m -d Maildir; done

That will create a directory called Maildir in each user’s home directory. Then just configure your MTA to deliver mail there, and your IMAP server to pick it up there
In postfix, add this to /etc/postfix/main.cf

home_mailbox = mail/

And in Dovecot, change this in /etc/dovecot.conf

mail_location=maildir:~/mail/

Now you can edit /etc/sudoers and uncomment the env_keep section.

3 Responses to 'Converting mbox’s to maildir format'

Subscribe to comments with RSS or TrackBack to 'Converting mbox’s to maildir format'.


  1. on February 4th, 2008 at 2:47 pm

    Very cool. When I switched I think I lost most of my mail because I didn’t know this. I have some kinda mail server running on my basement linux box (that sends through my ISP’s smtp) and it’s a huge mystery to me. So many parts that I set up so long ago. If it ever goes down I’ll have to reinvent the wheel. :)

  2. netlynker said,

    on August 22nd, 2009 at 11:06 am

    I am using sendmail as MTA.
    How to configure sendmail to save mail to maildir format.

    Best Regards,

    netlynker

  3. Brandon said,

    on August 22nd, 2009 at 12:29 pm

    I don’t use sendmail much, but it seems like you should be able to have sendmail use procmail as LDA which is able to save in Maildir format.

Post a comment

Please copy the string N3X7I7 to the field below: