Converting mbox’s to maildir format

There is a handy utility for converting mbox style mailboxes into maildir format at

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
# gunzip
# cp / 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/

home_mailbox = mail/

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


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

3 thoughts on “Converting mbox’s to maildir format”

  1. 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. I am using sendmail as MTA.
    How to configure sendmail to save mail to maildir format.

    Best Regards,


  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *