Moving mail archives to MobileMe (or other Sun Java System Messaging Servers)

I recently consolidated all my email on MobileMe (for easy access from both my Mac and iPad). However, I ran into a problem with the MobileMe IMAP server when I tried to move my old mail archives to the MobileMe IMAP server. MobileMe uses the Sun Java System Messaging Server (which has since become the Oracle Communications Messaging Exchange Server). It turns out that this IMAP server (like some others as well) is rather strict about the format of mail headers; hence, uploading old mail archives usually aborts with the following error message: "The IMAP command “APPEND” (to …) failed with server error: Message contains invalid header".

Querying the Internets and some experimentation revealed that the problem are lines in email message headers that start with "From ", ">From ", and ">>From ". These are not proper message headers fields (whose names need to be delimited by a colon), but remnants from storage of these mail messages in the mbox format. The remedy is to delete or edit these invalid lines in all affected message headers.

Apple Mail stores mail messages in "$USER/Library/Mail/Mailboxes/". Each mailbox directory (suffix ".mbox") contains a directory "Messages" with one file per message. These files can easily be modified using your favourite command line tools that support matching of regular expressions or by loading them, en masse, into TextMate for project-wide search and replace. This is somewhat naughty as the files containing individual messages contain the message header and text as well as a property list (plist), used by Mail.app to store a few attributes. The start of that property list in the text file is marked by a character count in the first line of each message. By eliminating or modifying the offending lines, you invalidate that character count.  However, Mail.app seems to cope just fine with those slightly malformed messages. After fixing the headers, all my messages uploaded without problems (and no attributes seemed to get lost).

Filed under  //  iPad   imap   mac   mail   mobileme  
Posted