This page is part of the EmailServer article.
Mbox to Maildir migration
When upgrading a mail server, you may be faced with a rather 'interesting' problem: migrating old user account in the classic monolithic mbox format to the more tolerant and performing maildir.
Mbox is a way to store emails in a single file. It's old, compatible with most mail applications, but as your mail store grows, it becomes harder to manage emails contained within.
Maildir on the other hand is newer and not supported by all systems. Basically it's just a way to store emails as files within a folder hierarchy. Its advantages are mostly better performance and tolerance in case of failure since you're more likely to lose just one email instead of your entire mailbox.
Postfix (MTA) and Dovecot (POP3 and IMAP server) both support the maildir format and can integrate with each other seamlessly.
It's nevertheless a great pain when you have to migrate existing mailboxes to the new format, on a new server for instance.
There is apparently only one tool that allows this type of thing: it's a small Perl script maintained by Philip Mak that is available as Perfect_maildir.
Just download the single file script and you are ready to convert, unless you're getting a long error message and in that case you may need to download the
To install it, just enter:
# perl -MCPAN -e 'install Date::Parse'
If this is the first time you install a module, you will be asked a series of question. Just keep pressing Enter until you're asked about your geographic area. Make your selection of mirrors to download from and Perl will do the rest. Next time, you won't be asked anything.
If you have a handful of accounts to migrate, doing it by hand may be tedious, but it can still be faster than going through setting up an automated process.
I found useful to use my mail client to create IMAP accounts for every user I needed to migrate, then use their original mailbox layout to re-create the directories they had.
You can get the old mailbox layout by viewing the
# perfect_maildir.pl /mail/michael/email < /oldmail/var/mail/michael
# perfect_maildir.pl /mail/michael/email/.Drafts < \
# chown michael.michael -R /mail/michael/email
Would first move the inbox and then the old Draft mboxes to the new maildirs and ensure that the files belong to the user; this is particularly important if you're doing the migration as
If you need to migrate a lot of accounts, then you should use the migration tools below. They make use of
Just in case it may be useful to you, here is a small script I used to move each original mbox inbox to the new maildir one:
my $n = $ARGV;
$n =~ s/^\s+//;
$n =~ s/\s+$//;
die "No mailbox for $n\n" \
unless (-e "/oldmail/spool/$n" && -e "/mail/$n");
`mkdir /mail/$n/email/cur` unless -e "/mail/$n/email/cur";
`mkdir /mail/$n/email/new` unless -e "/mail/$n/email/new";
`mkdir /mail/$n/email/tmp` unless -e "/mail/$n/email/tmp";
print `perfect_maildir.pl /mail/$n/email < /oldmail/spool/$n`;
`chown $n.$n -R /mail/$n`;
You will need to modify the hard-coded paths to suit your configuration. In mine, I used the following:
If you're setting up a new machine and your inboxes are on the old one, you can make files available to the new system through NFS and mounting the exported directories locally or simply copying using
If your old email is sitting in a POP3 account at an ISP, you can use
Fetchmail is easy to use and I won't go into the details except that you could use a
poll mail.isp.com protocol pop3 user roger to roger password 123456 keep
Another way, useful if you are using IMAP on the old account and have created IMAP folders, is to have both old and new account in your client email for each user and drag-drop files from one to the other after having recreated the same directory structure manually.