zbateson / mail-mime-parser

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

Two dots decoding issue #139

Closed ahmadfds closed 1 year ago

ahmadfds commented 3 years ago

Hello,

I've noticed in some of my parsed emails that you don't decode the two dot's in the beginning of the line. which cause it to render a wrong image path in my case, check this out:

<td style=3D"-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;=
 font-family: sans-serif !important; mso-table-lspace: 0pt !important; mso-=
table-rspace: 0pt !important;">
                                         =
 <img src=3D"https://www.example.com/themes/jawabmanzel/images/jpg/Cairo=
..jpg" width=3D"100%" alt=3D"" style=3D"-ms-text-size-adjust: 100%; -webkit-=
text-size-adjust: 100%; font-family: sans-serif !important; -ms-interpolati=
on-mode: bicubic; max-width: 100%; height: auto;">
</td> 
zbateson commented 3 years ago

Hi @ahmadfds --

That's more an smtp transport thing and not a mime message thing. At one point I had an option to consider input streams 'smtp' and remove a single period at the beginning of a line when two periods start the line, but in retrospect I removed it as it didn't seem 'in-scope' for a mail parser (I don't really do anything else specifically 'smtp' related, and didn't want to go in that direction).

Having said that, you could implement a stream decorator with psr7 pretty easily for example, and pass the decorated stream on to 'parse'... that would be my preferred way if you're dealing with streams as it wouldn't involve an additional full 'read' and cache step before passing it. If you're parsing a string or file I'd just use regex on it directly.

If you end up going the psr7 route, feel free to submit a pull request to zbateson/stream-decorators -- maybe that way I could both support it and not have it be part of this library :)

If you need some help with it, feel free to reach out here or on an open pull request -- my way to do it would probably be to use guzzlehttp's BufferStream to buffer a full line of text, and simply check the start of the line. I can't remember if there are any other things to check with an smtp stream though.