

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. None of the solutions described below preserve the message UIDs.

Convert plugin

Dovecot has a plugin which allows you to convert between any two mailbox formats supported by Dovecot. The conversion is done when the user logs in for the first time, or using convert-tool binary. See ["Plugins/Convert"].

Converting from mbox to Maildir

[ mb2md] is a script which can convert the files for you. [] can convert also message UIDs.


Example (user's mail in ~someuser/mail and INBOX in /var/mail/someuser):

cd ~someuser -s mail -R -m -s /var/mail/someuser
mv mail mail.old

Now the mail will be in ~someuser/Maildir.

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:namespaces]. In any case you need to replace the '/' with '.' in the subscriptions file:

UW-IMAP's subscriptions file is in ~/.mailboxlist. Dovecot's mbox subscriptions is in <mbox root dir>/.subscriptions. Dovecot's Maildir subscriptions is in <maildir root>/subscriptions.

Also if you're migrating from UW-IMAP, you probably had "mail/" prefixes in the mailbox names. You can again use [:Namespaces: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:

sed 's/^mail\.//' subscriptions >
mv subscriptions

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 [:MailboxFormat/mbox:mbox] with Dovecot.




cd ~hans
perl . >/tmp/hans-inbox
perl Sent >/tmp/hans-sent

# dw = Dovecot Wiki :-)
# figure out which program to run
$cmd="reformail -f1";
foreach $file (@files) {
  next unless -s $file; # skip empty files
  next unless -r $file; # skip unreadable files

Converting from MBX to mbox

If you are using UW-IMAP and using the [:MailboxFormat/mbx:MBX format], you will need to convert it to [:MailboxFormat/mbox: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].

# Written by Marc Perkel - public domain
# overhauled by Matthias Andree, 2006
# Usage: mbx-convert <filename>
# Change to any real user on your system.
# abort on error
set -e
if [ $# -ne 1 ] ; then
  exit 1
# set up automatic cleanup
# Run mailutil to convert as the user other than root
# mailutil requires this
# create new file with same permissions/owner as old
# cat instead of copy leaves the original owner and permissions alone
  # cat succeeded, rename file into place
  # cat failed, remove temp file
  rm -f "${1}.new"
  exit 1


User comments: