zbateson / mail-mime-parser

An email parser written in PHP
https://mail-mime-parser.org/
BSD 2-Clause "Simplified" License
458 stars 58 forks source link

Mail ->getTextContent() ends with TypeError fwrite() #205

Closed Kuzuto closed 1 year ago

Kuzuto commented 1 year ago

I have a mail message, that looks like it has an empty body. It's a phishing message, and it might be constructed to crash mail-parsers.

with ->getHtmlContent() it return null , but with ->getTextContent() my code fails with: TypeError fwrite() expects parameter 2 to be string, bool given

the error trace is : TypeError : fwrite() expects parameter 2 to be string, bool given /vendor/guzzlehttp/psr7/src/Stream.php:254 /vendor/guzzlehttp/psr7/src/CachingStream.php:112 /vendor/guzzlehttp/psr7/src/Utils.php:87 /vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php:58 /vendor/zbateson/mail-mime-parser/src/Message/MessagePart.php:168 /vendor/zbateson/mail-mime-parser/src/Message.php:148 /tests/Unit/CodeTest.php:10

I'm not sure, if this is a GuzzleHTTP failure or mail-mime-parser..

If the .eml message is needed, we find a way to share, as this is a malicious message.

zbateson commented 1 year ago

Hi @Kuzuto --

I'm unable to reproduce this with a simple test (email with headers and no content). It seems the call to read from a stream is returning 'false' (looking at Utils.php:87), and reportedly isn't at 'eof()' and isn't returning a blank string. The original copy would be great if it's possible to share?

Thank you!

Kuzuto commented 1 year ago

Hi, yes I can share the original mail. I expect the mail is created to break parsers or it might be a lucky strike. Don't think I should share it here, can you share email adr. I can send it to ? I have 2 .eml files, that is constructed the same way with same kind of attachment. Both fails.

Kuzuto commented 1 year ago

Closing this issue.. Is a very rare case of issue and if it shows up again, I will try to investigate where in the message it fail to parse.

zbateson commented 1 year ago

Sorry, thought I replied -- if you do get it in the future or want to forward it my email's my github username at mailbox dot org.