Jun 11, '04 12:09:00PM • Contributed by: vocaro
Mail.app and Mozilla Mail both use the standard Unix mbox format, so I assumed that moving my mail archive would be trivial. Mail.app even has a Mozilla option for importing mailboxes! Unfortunately, I had very little luck importing: Mail.app wouldn't even detect some of my mailboxes as valid mbox files, and many of those that it could detect were only imported partially. (A mailbox containing 750 messages in Mozilla Mail would show up in Mail.app with only 12, for example.)
After lots of investigation, I discovered that the mbox files that Mozilla Mail had created were very inconsistent. Message boundaries had different forms, lines would end with different characters (sometimes carriage return, other times carriage return plus linefeed), etc. In a word, the files had simply gotten dirty, perhaps because my archive had been growing through several versions of Mozilla Mail, each of which had slightly different algorithms for reading and writing mbox files. As a result, Mail.app's inflexible mbox importer couldn't handle my mbox files.
I first tried manually correcting the files by loading them into TextEdit, but I soon realized that this would require days of effort. Instead, I wrote a Python script that cleaned up the Mozilla Mail mbox files and allowed every one to be imported into Mail.app. I used the script successfully on over 10,000 emails scattered throughout several dozen mailboxes.
I am posting the script here in the hope that someone may find it useful in solving the same problem with Mail.app that I had. Although I have not tested it with other mbox-based email clients such as Mozilla Thunderbird, it should be of use for them, as well.[robg adds: Due to the length of the script, I uploaded it as a separate text file: clean_moz.txt.]