MAPI icon indicating copy to clipboard operation
MAPI copied to clipboard

Storing .msg attachments to server

Open GTCrais opened this issue 5 years ago • 1 comments

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?

GTCrais avatar Aug 21 '20 15:08 GTCrais

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 -

  1. You can convert it to RFC822 Mime and save it as an .eml file
  2. 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 Message class is provided with an OLE root element in the $obj member. Unfortunately, the $obj member is protected, so your implementation will require a fork.

Get it working and I'm happy to merge a PR.

hfig avatar Aug 23 '20 08:08 hfig