MAPI
MAPI copied to clipboard
Storing .msg attachments to server
I have a somewhat specific issue - the .msg email files I'm parsing sometimes have other .msg files as attachments. As I iterate over the attachments, calling ->copyToStream(...) on the .msg attachments fails (as opposed to calling the same method on, for example, a .pdf attachment, which works normally). Calling ->getData() on the .msg attachment returns a \Hfig\MAPI\Message\Message object. How do I save this .msg attachment (or the underlying Message object) as a physical .msg file on the server?
So, from memory, a MAPI attachment isn't stored as an attachment, it's stored as another sub-document in the OLE compound document. Other types of OLE compound documents - .DOC, .XLS etc - can theoretically also be stored this way.
This library doesn't implement writing of an OLE compound document. You have a couple of options -
- You can convert it to RFC822 Mime and save it as an .eml file
- You can implement the code to write the file.
On the second option:
- The PEAR::OLE library supports writing (have a look at the https://github.com/pear/OLE/blob/master/OLE/PPS/Root.php ), though I can't vouch for its quality.
- The
Messageclass is provided with an OLE root element in the$objmember. Unfortunately, the$objmember isprotected, so your implementation will require a fork.
Get it working and I'm happy to merge a PR.