Working with Mac-sent attachments in Linux
October 10th, 2007//-->
If you’re reading mails offline on Linux (or if you’re browsing from GMail,) and you have some contacts using a Mac who sends you emails with attachments from Mail.app, you may some of the time get attachments that may seem to be unreadable by the intended application (like, when some Mac guy sends you a mindmap file in FreeMind that you can read in Ubuntu.) I recently hit this snag at work, so I did a little looking around to see why this is so, and how to fix it.
The first thing I did, after downloading the attachment, was to obviously `pager` it.
What seems to be a single attachment is in fact a couple of MIME objects, one an `application/applefile’ object, and an `application/octet-stream’ object. Since both are Base64-encoded parts, I can run a simple filter (using Perl’s MIME::Base64::decode_base64 routine) on both to get the raw parts. It turns out that the first part is an AppleDouble-encoded resource fork that describes the metadata for the actual file (called the data fork in AppleDouble parlance.) One can read this on Linux via Perl using the Mac::AppleSingleDouble module to get Finder information, among other things.
However, for non-Mac users, what they’re really interested in getting is the the data fork. This can be done by using Email::MIME on the original message to get the data fork subpart, then filtering it through MIME::Base64. (Or you can cheat by using the already-downloaded AppleDouble attachment and extract+decode the octet-stream part as mentioned earlier.)
October 10th, 2007 at 1:17 am
Why don’t you post the script? I think this would be even more helpful for most people than your great explanation.
October 10th, 2007 at 2:44 am
Because there is no script (yet,) hehe; that will follow after I get some sleep (its 2 in the morning here now.
The perl filter however, is this (straight out of
perldoc$ perl -MMIME::Base64 -ne 'print decode_base64($_)' < data-fork > mindmap
October 12th, 2007 at 6:05 am
Why would you put up with this shit from Apple? Simply tell the people you correspond to get a clue and use a decent email client that doesn’t mangle attachments.
October 12th, 2007 at 1:50 pm
Well if I didn’t `put up with this shit,’ I wouldn’t be telling.
Besides, it is nice to know (but not required, obviously) how to retrieve info from such mangled attachments.
Anyway, the folks now have a clue; I can’t force them to use a client not of their choice, it is up to them. Remember Jon Postel (http://en.wikipedia.org/wiki/Robustness_Principle)