Your personal GMail-like mail system: converting emails

As mentioned before, the email system uses Maildir format for storage. There are a lot of reasons to choose Maildir and I’m not going to debate about it although technically you can adopt this guide for MBOX storage as well. And since I already had the emails which I want to keep, and since I already had them in MBOX format from Thunderbird, I had to convert them back to Maildir format. If your e-mail storage is in Maildir format already, you can just copy it into two different storages (business maildir and personal maildir) and go on. If you however have MBOX, read on.

There are a lot of different scripts to convert MBOX to Maildir format. None of them frankly supports Thunderbird directly, so you’ll have to try them. I used from this site, although I still had to modify it as it did not convert all the mail. I suggest you use this one as well unless you find something better which suits your needs.My modifications include better parsing of mboxrd which is the subset Thunderbird uses to store the messages, proper handling of Thunderbird subfolders and ignoring the indexes and empty folders. The modified script could be downloaded here:¬†

The conversion script uses the Date::Parse Perl modules which is likely to be missing from your default Perl installation. If you experience the message like that:

Can't locate Date/ in @INC (@INC contains: ...
BEGIN failed--compilation aborted at line 385.

Then grab your superuser account and install them:

myhost:~ # perl -MCPAN -e "install Date::Parse"
... a lot of output...
/usr/bin/make install -- OK

The way you run the conversion script is the following:

perl -R -s ~/.thunderbird/<profile dir>/<mail dir> -d /path/to/<destdir>

Use the absolute path for -d command line option, otherwise the script will create the destdir in your home directory – probably not what you wanted. This will take a while to finish if you have a lot of emails.

Make sure that all emails converted properly, and the number of files in each directory corresponds to the number of emails in the associated folder in Thunderbird. The command

ls -1 <directory> | wc -l

will show you the number of files in a directory. Note that Maildir stores emails in cur directory; new and tmp are only used during e-mail delivery.

You can move the directories around. For example, you can create the business directory and move there all the Maildir directories related to business, and move the rest of the e-mail directories into personal directory.

A side note if you did not convert your email storage because you used the native KMail storage. dovecot uses a different naming structure, so you need to rename your folders to keep the proper structure. For example, the following folder structure:


will be represented in KMail Maildir format as:

while dovecot requires this structure to be presented as


As you see, there is no dot prefix nor .directory suffix in the Dovecot directory representation. And the whole directory structure is represented as a single directory with entries separated by a dot, which means there are no subdirectories deeper than 2nd level nesting. You will probably have to rename them manually as I’m not familiar with any application doing that. However it should be a simple task as there is no possibility of mail loss unless you delete a directory during the rename.

Now you got the e-mail storage, either converted or your native one, you can proceed with the next step which will be dedicated to the installation your IMAP server, dovecot.

This entry was posted in Email.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.