0

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;
BastianW
  • 2,628
  • 7
  • 29
  • 38
Protomen
  • 9,471
  • 9
  • 57
  • 124

1 Answers1

0

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.

sulaiman sudirman
  • 1,826
  • 1
  • 24
  • 32
  • The problem with such a solution is that it is not actually in PHP, it is an external software that I would need to upload to the server to run, of course I agree that it is a solution, only it is not in PHP, which complicates a lot of sharing a code and project. I hope that the PHP IMAP API has some support on this, I need to study it. thanks anyway, your solution will probably work for someone else. – Protomen Jun 08 '20 at 23:05