hfig / MAPI

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

Some mail give memory error and lots of warnings but are OK after reloading and saving with Outlook 2019 #25

Open freebrowser1 opened 3 years ago

freebrowser1 commented 3 years ago

Using this tool as described in the example mostly works (using cli PHP 7 or 8) but in some cases it issues errors of empty keys and memory overflows.

However, when I load this msg into Outlook 2019 and save it again, it runs successfully through this code. It appears to be Outlook version dependant.


PHP Warning:  Undefined array key "" in /Users/user/Downloads/msg/vendor/pear/ole/OLE/ChainedBlockStream.php on line 126

Warning: Undefined array key "" in /Users/user/Downloads/msg/vendor/pear/ole/OLE/ChainedBlockStream.php on line 126
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 130023456 bytes) in /Users/user/Downloads/msg/vendor/pear/ole/OLE/ChainedBlockStream.php on line 125

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 130023456 bytes) in /Users/user/Downloads/msg/vendor/pear/ole/OLE/ChainedBlockStream.php on line 125
hfig commented 3 years ago

Something similar has been reported before. What generates the .msg file originally? Can you share an example of a file which trips up the library?

Note though that your error is being raised in the pear/ole library, so the issue is more likely to be in there.

Make sure you're using the latest version of this library which requires the latest version of pear/ole, as this has some fixes contributed by users of this library.

freebrowser1 commented 3 years ago

Well, pear/ole is part of this repository and I obviously used that one.

https://github.com/hfig/MAPI/tree/master/src/MAPI/OLE

hfig commented 3 years ago

I think you're misunderstanding the nature of dependencies. This library depends on the third party library pear/ole. It uses pear/ole to do the mechanical part of parsing an OLE compound document file. This library interprets the OLE compound documents structured in a way that is commonly called a MAPI document and which represents an email message.

Your error is raised in the pear/ole library. You can tell this because the path of the file generating the error is in the vendor/pear/ole directory. Composer places third party libraries in the vendor directory.

The part of the source tree of the library that you linked to is an abstraction of pear/ole. The abstraction exists because PEAR libraries are ancient and icky (PEAR is PHP's original package management system with a philosophy from another millennium) and so I didn't want the library to be too closely coupled to the pear/ole implementation of a OLE compound document parsing library.

Anyway, we're no closer to helping you, so maybe consider some of the other points I made in my previous reply.

LiaOkami commented 5 months ago

I'm running into a similar error with documentFactory->createFromFile function:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67108888 bytes) in \vendor\pear\ole\OLE\ChainedBlockStream.php on line 127

I installed the latest version of this library (v1.4.0) through composer. Dependencies, including pear/ole (v1.0.0) got installed at the same time. PHP version is 8.0.8.

Here is an example of a file not working, generated by Outlook with the "Save As" function: test.zip (The exact version used is Microsoft® Outlook® for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20176) 32-bit)