Wednesday, March 28, 2007

Exporting selected mails from Evolution

Had an impromptu need to export different selections of emails from Evolution onto the web.

A brief (read: impatient) googling did not reveal any pre-existing solutions, so a quick hack was in order.

Digging around the ~/.evolution directory, I noted that local Evolution foldes are store in ~/evolution/mail/local/<folder_name> as flat files which looks suspiciously like the mbox format. That looks like a good start.

Searching for "mbox to HMTL", I was lead to hypermail.

Hypermail is a program that takes a file of mail messages in UNIX mailbox format and generates a set of cross-referenced HTML documents. Each file that is created represents a separate message in the mail archive and contains links to other articles, so that the entire archive can be browsed in a number of ways by following links. Archives generated by Hypermail can be incrementally updated, and Hypermail is set by default to only update archives when changes are detected.

A quick solution was now obvious:

1. Install hypermail
2. Copy selected emails to a new1 local folder, say "hypermail_temp"
3. Run hypermail
cat ~/.evolution/mail/local/hypermail_temp | hypermail -i -l "Title of Export" -d output_dir

The output produced by hypermail was exactly what I needed. Sortable by thread, author, date, subject, and attachment (Example output).

1[Note: mails deleted from within Evolution (which are sent to trash) will still remain the flat file and would thus also appear in the output of hypermail. Therefore, if running hypermail on an existing folder, you might want to Expunge (ctrl-e) the folder beforehand to ensure deleted mails do not appear]


Ideally, cooking up a tool based on the Eplugin system would have be really neat. Alas, investing too much time on a one-off requirement is just not practical. Maybe next time.

No comments: