Working with Mac-sent attachments in Linux
Wednesday, October 10th, 2007If 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.)