Converting mbox’s to maildir format

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 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,

    netlynker

  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.