robertmuench.de

To the point & Out of the box


Import Opera into Apple Mail.app

Since Apple added MS Exchange support into OSX Snow Leopard, it makes quite some sense to use the internal Apple Mail.app.

Being an Opera user for since version 3.x (can’t remember) and loving the M2 mail client (because it’s extremely fast if you search and well suited if you handle 100.000 email) I first want to test Mail.app under heave load.

Ok, no big deal. Just import the Opera Mails into Apple Mail.app. Works right out of the box. But... Opera stores every mail in a single MBS file. This is mostly a mbox format. No problem, Apple Mail.app can handle it. But... you will get a hierarchy inside Apple Mail.app, that reflects the layout of Opera MBS files. Folder, subfolder, subfolders, etc...

Since Apple added MS Exchange support into OSX Snow Leopard, it makes quite some sense to use the internal Apple Mail.app.

Being an Opera user for since version 3.x (can’t remember) and loving the M2 mail client (because it’s extremely fast if you search and well suited if you handle 100.000 email) I first want to test Mail.app under heave load.

Ok, no big deal. Just import the Opera Mails into Apple Mail.app. Works right out of the box. But... Opera stores every mail in a single MBS file. This is mostly a mbox format. No problem, Apple Mail.app can handle it. But... you will get a hierarchy inside Apple Mail.app, that reflects the layout of Opera MBS files. Folder, subfolder, subfolders, etc...

It’s not a big deal because you can collapse the folder and use some intelligent postbox filters. But... knowing that this “Imported from Opera” folder is such a mess is something I don’t like.

Well, simple solution: Just concatenate all MBS files into one file. As MBS files are mbox compatible this shouldn’t be a big deal. Said, done, doesn’t work.

Hmm... Ok, Opera uses CRLF as line separator. Apple Mail.app doesn’t like it. No big deal, changing line terminators. Said, done, doesn’t work again.

Hmm... The mbox format spec states (even there is no official standard) that the first line has the following structure (including spaces):
From <24 character date and time>
Opera adds the MBS filename (which is always a number) into the additional information area. Other mail programs are requested to skip this information untouched. The problem is, that Apple Mail.app is very picky about this line. It does’t handle the additional information (at least not if it’s just a number). And because this line is the indicator, that a new message starts, it is crucial for a good import

So the next step was to repair this line for every MBS file.

The last thing that I found out was that messages in a mbox file should be separated by two LFs, not only one LF.

Ok, so what to do now? If technology is not willing to work like we need it, we write a script to fix it. Said, done, and it worked! Here is the Rebol script I used to do it.


rebol []
; where are our MBS files stored?
root: make block! [%/Users/robby/tmp/]

; we need file access
secure [file allow]

; to support multiple runs
if exists? mbox: %mail_app/opera.mbox [delete mbox]

; let’s walk the directory hierarchy
foreach dir root [
foreach sub-entry read dir [
either dir? join dir sub-entry
[
; add directory to the end of the list we just traverse
append root dirize join dir sub-entry
]
[
; let’s make the correct path to the file
f: join dir sub-entry

; we are only interested in MBS files
if (suffix? f) == %.mbs [
; not sure if we should read the file
read-file: false

; get file infos like date, size etc. to determine of file should be read
finfo: info? f

; for each different account we only import files older than a specific date
case [
found? find f %account1/ [if finfo/date < 16-Aug-2008/13:31 [read-file: true]]
found? find f %account3/ [if finfo/date < 28-Jan-2009/08:34 [read-file: true]]
found? find f %account4/ [if finfo/date < 02-Sep-2008/10:13 [read-file: true]]
found? find f %account5/ [if finfo/date < 18-Aug-2008/11:40 [read-file: true]]
found? find f %account6/ [if finfo/date < 16-Aug-2008/13:21 [read-file: true]]
found? find f %account8/ [if finfo/date < 16-Aug-2008/13:21 [read-file: true]]
found? find f %account11/ [read-file: true]
found? find f %account12/ [read-file: true]
]

; read condition fullfilled?
if read-file [
; inform user
print ["Appending file" f]

; read file as single lines
msg: read/lines f

; get rid of additional information in the From_ line, this is Rebol magic
; 1st we split the line by space (parse)
; 2nd remove the additional information is the last entry in the result block of parse (remove back tail)
; 3rd move to the beginning of the block (head)
; 4th make a string incl. spaces out of it (form)
; 5th and assign back to line 1 (msg/1)
msg/1: form head remove back tail parse msg/1 ""

; now let’s write it to our mbox file
write/lines/append mbox msg

; and ensure correct separators between mails
write/append mbox #{0A0A}
]
]
]
]
]

; back to user command line
halt


That’s it. More is not needed.

To use the script:

  1. copy text to a file: mbs2mbox.r or download from download page
  2. adjust: root, account1/..., compare dates and target path
  3. download Rebol-2 interpreter from www.rebol.com
  4. Put interpreter into same dir as script
  5. Start interpreter
  6. Type: do %
  7. Wait and look

0 Comments