Code Play a software blog by tim benke

How to backup your IMAP mail account

Since about a year IMAP has become widely available with free email providers. See GMX and gmail. That’s why I decided to abandon my old payed email account at fusemail. Now to backup your emails there a couple of open-source projects that store your emails (archivemail, and offlineIMAP). I finally settled for offlineIMAP because it has the most interface options and supports incremental backups. Incremental backups were very important to me because the other programs seemed to hang from time to time and had to restart the whole backup process all over again.

This might be due to my flaky Wifi connection; YMMV.

Offlineimap only backups in Maildir format. Unfortunately most GUI email clients like or Thunderbird by default only support mbox format for importing mails. I found a small script that converts mails from Maildir to mbox format using the command formail from the projekt procmail.

Using this command the conversion is extremely easy. I’ve written a small script that should be executed from the parent directory of the backed up Maildir folder with <foldername>:

for i in $1/cur/*;
do formail -I "Status: RO" <"$i" >>$1-mbox;
for i in $1/new/*;
do formail -I Status: <"$i" >>$1-mbox;

for i in $1/cur/; do formail -I “Status: RO” <“$i” >>$1-mbox; done for i in $1/new/; do formail -I Status: <“$i” >>$1-mbox; done

The resulting <folder-name>.mbox files can be easily imported into either Thunderbird or Another possiblity for import to is the Add-on ImportExportTools. Which recognizes the mails from Offlineimap if you add an .eml extension to their filenames.

There remains the problem that mails for special folders like drafts or templates are imported like normail emails in e.g. A simple solution to this problem is to drag them to the drafts folder in a local POP3 mailbox or on another remote IMAP mailbox.