Handling Microsoft Office Document Scanning TNEF and TIFFs in Linux


I've received a number of “TNEF” files. Evolution calls them “application/ms-tnef attachments”. They are containers (“Transport Neutral Encapsulation Format”) that can hold other types of files. There are two programs that can extract the contents from these files, tnef (for Debian, and Ubuntu), and ytnef (for Debian, and Ubuntu). After saving the attachment from Evolution into a file called “attachment”, these work like so:

Now, this only solves half of the problem. The TIFF that is generated by Microsoft Office Document Scanning is not a proper TIFF. It appears that it Microsoft has decided to use TIFF as a container itself (for a JPEG, it turns out!). This is against the TIFF standard, rendering the TIFF file useless to anything but Microsoft Office Document Imaging, as far as I can tell. Of course, I don't have Microsoft Office 2003, so I don't know. I do know that I've tried to open these files using the Microsoft TIFF viewer on Windows XP to no avail. To prove my point, here's the result of using LibTIFF's tiffinfo tool on the TIFF we extracted above:

OK, enough ranting on the use of no less than three containers (MIME, TNEF, and TIFF) to send a simple image in an email. The question remains: how can one get at the attached contents? If you're like me, you can't necessary get all senders to change their ways and simply attach a JPEG via MIME directly, which, of course, would be ideal, since almost all email clients these days know how to deal with JPEG attachments. So we are left with trying to figure out some way to get at the contents. Fortunately, there is a program that can help: Foremost (for Debian, and Ubuntu). This is a file recovery tool originally designed to recover files from busted hard drives. It turns out that we can use it on the TIFF file to recover the original JPEG. Here's how:

The file of interest is attached/jpg/00000000.jpg. It should be a normal JPEG which any image viewer can display.

[Comments]

Additional references:

  1. Malone #18289: crash in tiff loader
  2. IrfanView is a Windows application that apparently has native support for these files, too. I haven't used it myself, but I've been told that it will run in wine.
  3. typhoncore posted a short script that shows how to convert a multipage tiff into multipage pdf.
  4. Samiuela LV Taufa wrote a more detailed post which covers the issue in more depth.

Michael R. Head
Last modified: Thu Mar 13 20:02:28 EDT 2008