dx4.org :: linux :: outlookmigration

Ever wanted to take all of a user's Outlook Express mail and copy it to an IMAP server? Sounds easy, but it turns out it's a huge pain. Neither OE or Thunderbird will let you copy hierarchies of folders from local disk to a server. In hopes of saving you some pain down the road, here's how I ended up doing it.
In this case, the server was running uw-imapd, so the first step was to turn the OE proprietary folders into MBOX files. Fortunately, Thunderbird provides an import plugin for OE and uses MBOX as its native format..

Unfortunately, Thunderbird adds some junk to the plain MBOX files, like .msf files, zero-length mailboxes, and empty directories. I didn't need them, so I removed them by running these commands from the root of the mailbox hierarchy:

find . -name "*.msf" -print0|xargs -0 rm
find . -size 0 -print0|xargs -0 rm
find . -type d -print0|xargs -0 rmdir
Also, at least in the case of importing from OE, Thunderbird produces MBOX files that break RFC. Here's how an MBOX message header line should look:
From fakeuser@fakedomain.com  Tue Jun  5 07:32:51 2007
And here's what the imported MBOX message headers look like:
From - Mon Jan 1 00:00:00 1965
I wasn't even able to pin down what all's wrong with the second example. I just ended up swapping out all of them for a known-good header, using this script:
#!/bin/sh
perl -i -pe 's/From - Mon Jan 1 00:00:00 1965/From fakeuser\@fakedomain.com  Tue Jun 5 07:32:51 2007/' "$1"
Which I ran on all the MBOX files in the hierarchy.
IFS='
'
for i in `find . -type f`; do
convert-from-tbird "$i"
done
Pity the poor end user who tries to attempt such a Herculean feat.