Things I learned last week (9)

Maildir conversion with Thunderbird

Because a full backup of my desktop takes more than 7 hours, I do only incremental backups during the week. This also permits to have more than two weeks of daily backups online, which is really helpful when a file is accidentally deleted or modified. I try to keep these incremental backup as small as possible by using various tricks. For example I use a snapshot of each of my Virtualbox instances during the week, and merge them the day before the full backup. Similarly, I do a run a garbage collection (which compress the objects into a pack file) of all my git repository just before a full backup, so an automatic garbage collection is not triggered before an incremental backup, and so on. But even with these tricks, each incremental backup is at least 10 Gb, which is mostly because of my mailer, which use mbox as storage, i.e. one big file for each folder, so receiving one email will trigger the backup of the full folder.

There is a better type of storage in this case, maildir, where each email is stored in a different file (in fact an even better storage would be to have one file per email, but to have all the current emails packed in one file when the “Compact Folders…” command is run). Changing an account storage to maildir is simple under Thunderbird: Search for the storeContractId property for the account, and change it from “@mozilla.org/msgstore/berkeleystore;1” to “@mozilla.org/msgstore/maildirstore;1”. The problem is that there is currently no automatic process to also convert the existing folders to the new format. Here’s a small script that does the conversion of an existing directory containing mbox files to a new directory containing maildir files:

#!/bin/bash
find $1 -type d -exec bash -c 'mkdir -p $0/${1#*/}' $2 {} ;
dir=$(pwd)
find $1 -type f -name *.msf -exec bash -c 'f=${2%.*}; ./mb2md -s $0/$f -d $0/$1/${f#*/}' $dir $2 {} ;

The mb2md program should be downloaded from http://www.ulduzsoft.com/2012/02/your-personal-gmail-like-mail-system-converting-emails/ but you need to apply the patch from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578084 (the mb2md program installed from the Debian package mb2md has some issues with malformed mbox).

After converting the directory, you have to copy some of the files in the original repository (msgFilterRules.dat, popstate.dat, rules.dat). Modify the storeContractId property and restart Thunderbird or Icedove and your emails should be available after the index files are rebuilt.