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, imapbackup.py 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 Mail.app 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 maildir2mbox.sh <foldername>:

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

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 Mail.app. Another possiblity for import to Thunderbird.app 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. Mail.app. 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.

One Comment

  1. Reply
    getriebe September 5, 2011

    Thank you very much for this posts. Cheers :)

Leave a Reply

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

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">