hfig / MAPI

A PHP library for reading MAPI documents (Outlook .msg files)
MIT License
33 stars 41 forks source link

mimetypes accepted #27

Open HAL0594 opened 3 years ago

HAL0594 commented 3 years ago

It is not specified in the documentation but I would like to know what type of mimetypes the package can read, I had problems with people who upload files with mimetype plain/text or html as msg and I would like to validate the accepted mimetypes.

hfig commented 3 years ago

I wouldn't rely on a file extension-to-mime type map to determine if the file is valid. If you see a .msg file in the wild, it's usually given application/vnd.ms-outlook. But it could also be a TNEF file, which usually has the file name winmail.dat and type ​application/ms-tnef or application/vnd.ms-tnef. (This library is untested on TNEF files so behaviour will be undefined.)

You can verify you actually have an OLE compound document that the library can attempt to parse by magic bytes 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/05060311-bfce-4b12-874d-71fd4ce63aea

All of which is out of scope for this library