A friend has been having problems with a full imap mailbox. I googled for an easy (for me …) way to archive off the email, but came up with nothing – so I had to work the process out the hard way. Posting it here in the hope it’ll help someone.

Here’s what I did (using a linux machine):

1. I used offlineimap to  make a local “mirror” of the imap folder.
2. I then used mhonarc to process this into html.

The only difficulty once I’d decided what to do was that offlineimap produces maildir message stores, rather than mbox, but mhonarc seems to work best with mbox. It can be used with maildir, but only one folder at a time. So I used find to pass it each of the relevant folders in turn.

Result was this bash script ….

#!/bin/bash
# author: ben lumley
# requires mhonarc - mhonarc.org which is in repos for ubuntu/debian
# usage: ./myname.sh <source maildir root path> <destination path>
mailroot=$1;
archive=$2;
find $mailroot -type d -regex ".*\(new\|cur\)" -exec mhonarc -mhpattern '^[^\.]' -add {} -outdir $archive \;

I then zipped the output and sent it off to the owner of the mailbox.

And some of the things I googled to try and help other people find this:
html email backup
html imap backup
html email archive
html imap archive
mhonarc maildir
email to html