How detect if message body is TNEF format (winmail.dat)?

464 Views Asked by At

How detect/check if message body is format (winmail.dat) using PHP?

I don't want to decode, just want to check. I using imap_fetchbody and imap_body for get BODY, I need get mimetype (or like) for check if is "tnef format", like this:

if (in_array($bodyMimeType, array('application/tnef', 'application/x-tnef', 'application/ms-tnef'))) {
    //Decode
}

I tried:

$structure = imap_fetchstructure($imap, $messageId, FT_UID);
echo 'sub-type:', $structure->subtype, PHP_EOL;
echo 'encoding:', $structure->encoding, PHP_EOL;
1

There are 1 best solutions below

1
On

I think there's no way to know without decoding, I'm decoding it and check the status if it is successful using exec(), exec("tnef {$datfile} 2>&1", $output, $status), if it is successfully decoded, $status will be 0.