Some email messages contain the attachments in a format called TNEF (Transport_Neutral_Encapsulation_Format). This attachment is usually called winmail.dat. Extraction tools exist for linux, but originally these are meant to be opened by Outlook.

I have a large directory hierarchy with stored mail in MailDir format.

How would I best go about to:

  • Best detect messages in sub-folders containing winmail.dat
  • Cut out the winmail.dat, unpack it
  • "reassemble" the email.

I can sort-of imagine a "crude/naive" way, something with grep/perl for finding/cutting, lots of temporary files, and then catting extracted/7bit_converted pieces back together into a (hopefully) valid email structure.

Can somebody think of a better way, perhaps using more appropriate tools. I'd also be interested in any Got-Chas you can come up with, or first-hand accounts of similar endeavors.

In my wildest dreams, somebody here has written/seen use of some cool framework in e.g. python to accomplish something like "Recursively frobnicate some_property of eMail in MailDirs matching some_condition".

Replacing the "meat" of that with something that calls tnef -xyz would serve my immediate need, but having a nice "example" like this will surely be useful for lots of other use-cases not only for myself.

  • 3
    It depends on how badly you want this solved. You could write a Perl script to inspect and convert the messages, there are modules on CPAN for everything you need. It might take you a day to read the relevant standards, another day to write the code, and yet another day to debug it. Make backups first. :) – Satō Katsura Jun 30 '16 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.