Converting between mailbox formats

If you want a transparent migration, the biggest problem is preserving message UIDs. See Migration for the problems this may cause. If you do the conversion with dsync, it preserves the UIDs.

dsync

With dsync you can convert between any two mailbox formats that Dovecot supports. As much of the mailbox state is preserved as possible. Typically it's everything. See Tools/Dsync for full documentation, here are only a couple of examples:

Yet another way to fix the UIDL migration problem. If you can generate an uildlist ("messagenumber uidl" pairs), use my new -U uidllist option to inject X-UILD: headers in the converted Maildir-file. The modified mb2md script is avalable here: mb2md.xuidl.pl.gz. I used this to convert a cucipop installation to dovecot. pop3_reuse_xuidl=yes will do the rest. -- SoerenSchroeder 2009-02-13

Now the mail will be in ~someuser/Maildir. Do not forget to migrate the subscriptions as well, otherwise the new maildir will seem to have only an inbox when viewed through a mail client that supports them. This can be as simple as copying the old ~someuser/mail/.subscriptions file to ~someuser/Maildir/subscriptions (warning: I have not tested this extensively, my subscription list and folder hierarchy was very simplistic).

Hierarchy separator change

The default hierarchy separator with Maildir is '.' instead of '/' which is common with mboxes. To keep the migration transparent to users, you can keep the '/' separator by using namespaces. In any case you need to replace the '/' with '.' in the subscriptions file:

Also if you're migrating from UW-IMAP, you probably had "mail/" prefixes in the mailbox names. You can again use namespaces to let clients use the prefix, or you can tell your users to remove the namespace prefix from their clients and change the subscriptions file:

Note that because Maildir uses '.' as the hierarchy separator in filesystem, it's not possible to have mailbox names containing '.' characters, even if you changed the separator in namespaces. If you really want to have dots, the only way to do this is by modifying the filesystem separator in MAILDIR_FS_SEP and MAILDIR_FS_SEP_S defines in src/lib-storage/index/maildir/maildir-storage.h file in the sources. Do not be tempted to change MAILDIR_FS_SEP et al to '/'; it won't work.

Converting from Maildir to mbox

This is especially helpful if you want to archive your mail to a single file for storage on a CD, a PC, etc. But it can also be helpful if you want to use mbox with Dovecot.

Use the reformail program that comes with maildrop. You can also use the formail program that comes with procmail. Here is a simple script showing how this works.

To use it, adjust the script to invoke the right command according to your system.

Then cd to the user's home directory (one level above Maildir) and run the script with two arguments: the mailbox name (You can use "." for the top-level folder), and the output mbox filename, for example:

Converting from MBX to Maildir

Converting from MBX to mbox

If you are using UW-IMAP and using the MBX format, you will need to convert it to mbox format. The conversion process isn't pretty, but here is a script that works. You will need to get and compile the mailutil program from the UW-IMAP web site.

Make a copy of some folders and test it first. Once you are satisfied that it works then:

Write a script to convert all your files.

Shut down your email system so files can't be modified

Copy all your email to a backup location in case you have to revert

Run the script

Turn on Dovecot and test to verify it is working

Important - make sure that you changed your SMTP configuration to write mbox and not MBX.

Turn on SMTP and verify it is all working

User comments:

Is this hassle actually necessary? I have run mailutil as root like this (mailutil as provided by the PINE 4.61 package for SUSE Linux 10.0): mailutil copy /tmp/foo.mbx.orig '#driver.unix//tmp/foo.test' and did not encounter any problems. -- MatthiasAndree, 2006-05-18

I did the same (using mailutil) but it doesn't maintain UIDs or UIDVALIDITY. So I hacked this together to do the migration. -- JulianFitzell, 2008-08-02

Tried to do mailutil -v copy /tmp/foo '#driver.unix'/tmp/foo.unix, but mailutil argues Can't open mailbox /tmp/foo: no such mailbox. (mailutil as from the Debian package uw-mailutils in Debian 5.0 Lenny) strace shows that it searches for /tmp/foo/cur, i.e. a Maildir format mailbox. (WTF?) No idea yet how to get this working. And I'm really glad when I got rid of MBX. -- AxelBeckert, 2009-06-19