PHPverse 2025

Voting

: two minus zero?
(Example: nine)

The Note You're Voting On

atamido at gmail dot remove dot com
16 years ago
If you download an attachment labeled "winmail.dat" or "win.dat", or with the mime-type of "APPLICATION/MS-TNEF", this is a Microsoft Transport Neutral Encapsulation Format file. It is a proprietary method for encoding several files together in a single file. AFAIK only Outlook sends it with its default setting of sending emails in Rich Text Format.

As of PHP 5.2 there is no internal method of breaking apart these attachments.

There are external command line utilities that can be called from PHP. Alternately, it is possible to decode these files entirely in PHP. It appears that all current libraries are based on a plugin written by Graham Norbury for Squirrel Mail. The only ones I've seen are in IlohaMail, Telean, Horde-Imp, and NaSMail. The only one that I know that will also decode the RTF message is from NaSMail.

To use the NaSMail code, download the "TNEF Attachment Decoder" plugin and extract it to
plugins/attachment_tnef/

Then use this bit of code:
<?php
include_once('plugins/attachment_tnef/constants.php');
include_once(
'plugins/attachment_tnef/functions.php');
include_once(
'plugins/attachment_tnef/class/tnef.php');

// $tnef is a binary variable containing only the contents of winmail.dat
$attachment = &new TnefAttachment($tnef_debug);
$result = $attachment->decodeTnef($tnef);
$tnef_files = &$attachment->getFilesNested();
print_r($tnef_files); // See the format of the returned array
?>

<< Back to user notes page

To Top