I'm sure this post is boring for my regular readers, but it's about a workaround for a bug that kept me busy for some hours, and I didn't find any solution on the web that worked for me. I found some people that had the same problem, but the workaround that worked for them didn't work for me - which actually almost freaked me out. So, I hope this post is useful to anybody who has the same problem. I tried to write it as detailed as possible, in case there are people that aren't very familiar with a command shell and all that stuff.
If this post was helpful, please leave a note. Thanks. :)
A friend of mine bought a macbook recently, and he wanted to import mails from his outlook on his old PC to mail.app which came with his mac. We figured out that there's no way to do that directly. But you can import the mails into Thunderbird (which is my favourite mail program, by the way), and then you can import those to apple's mail.
At least that's what we were thinking. But it didn't work. Each folder contained only one big mail, it didn't create seperate entries for each mail. First I thought its a matter of line ending, since Unix and Windows use different characters to indicate the end of a line. Recoding Thunderbird's mail files didn't work.
I knew that the mbox file format that Thunderbird uses to store the mails is like this: Each folder is one file that contains all mails of the folder, and the beginning of a mail is marked by a line that starts with "From " and then some additional information. (Mind the space after "From", it's very important).
Most programs that use mbox files don't care about the data in the line after the "From ". A typical line in Thunderbird would look like that:
From - Mon 29 Dec 1997 23:45:58
Googling showed that mail.app is picky about the format of the From-Line, and there were some posts where people said that you need to replace the "-" by the address of the sender. I wrote a perl program that changed the From lines to something like this:
From firstname.lastname@example.org Mon 29 Dec 1997 23:45:58
But still, it didn't work. Still only one HUGE mail in each folder. It seemed like this worked for everybody except me. But I figured out that the date was not correctly formatted. Mail.app seems to expect the date in another format. It needs to look like this (mind the different order of the fields in date):
From email@example.com Mon Dec 29 23:45:58 1997
So, I wrote this perl program that fixes the mbox files, and finally it worked. This script changes the From line to the format that mail.app needs. It adds the actual email address of the sender, and changes the date (if neccessary).
If anybody has the same problem, here's how it works:
- Save the file mboxfix to your desktop. But you probably want to skip this step after you've read the update at the bottom of this post.
- Go to your Thunderbird mail dir (on windows it's probably c:\Documents and Settings\ YourUsername\ Applications\ Thunderbird\ Profiles\ default\ StrangeChars\ Mail, and on Mac its most likely /Users/ YourUsername/ Library/ Thunderbird/ Profiles/ default/ StrangeChars/ Mail. (I've inserted blanks for better line wrapping results))
- For each mail folder there are three files or folders, e.g. Inbox, Inbox.msf, Inbox.sbd. Only the Inbox (without extensions) is important. Copy those files (one for each mail folder) to your desktop as well.
- Open a Terminal on your Mac. (Applications -> Accessories (probably, I don't know the English name) -> Terminal).
- Type cd Desktop and hit enter.
- Type chmod 755 mboxfix and hit enter.
- Now do this with each mailbox file (this example uses the mail folders Inbox, Sent, Private and Office. If you have different names, and/or more mail folders, alter the command to your needs:
./mboxfix Inbox Sent Private Office
- This creates the files Inbox.mbox, Sent.mbox, Private.mbox and Office.mbox
- Open Mail, go to "Import Messages", select "Import from Other", and point it to your desktop. Make sure to import only the files with the ending .mbox.
- You're done. Clean up your desktop and say "thank you, Rian". :-)
Update (March, 25th): (see also post from March 25th, 2007)
Lars Kobbe created a Droplet out of my perl script. Just download my script wrapped up in Lars' Droplet here (i.e. skip step 1), and replace step 4 to step 7 by just dragging your mbox files on this Droplet.