Monday, February 7, 2011

Converting from mbox to Maildir with Postfix and Dovecot on Debian

This is the procedure I used for converting from mbox to Maildir with Postfix and Dovecot running Debain 5.x. This assumes that you have individual system accounts for each mail user and that the mbox files are currently in /var/spool/mail/USER and /home/USER/mail/FOLDERS.

All the following commands/edits will need to be done as root:

Install mb2md:

aptitude install mb2md

Stop the mail servers:

/etc/init.d/postfix stop
/etc/init.d/dovecot stop


Edt the /etc/posfix/main.cf:

home_mailbox = Maildir/

Edit the /etc/procmailrc (if you are using procmail for local delivery/filtering):

ORGMAIL=$HOME/Maildir/
MAILDIR=$ORGMAIL
DEFAULT=$ORGMAIL


Edit the /etc/dovecot/dovecot.conf:

mail_location = maildir:~/Maildir

At this point I'd backup the user accounts just in case there is an issue.

Create a bash script with the following and execute it:

for i in $( ls -1 /home ); do
su -l -c 'mb2md -m' $i; ## convert /var/spool/mail/USER
su -l -c 'mb2md -s mail -R' $i;
done


At this point you will need to restart the mail servers:

/etc/init.d/dovecot start
/etc/init.d/postfix start

No comments:

Post a Comment