TheFox / smtpd

SMTP server (library) for receiving emails, written in pure PHP.
https://fox21.at
MIT License
121 stars 30 forks source link

Corrupted Base64 Attachments 3-5% of the Time. #21

Open ClaytonPulman opened 1 year ago

ClaytonPulman commented 1 year ago

I would like some help, I have been using this library for some time now in testing. However I have noticed there is corruption in the Base64 output of some email attachments, some of the time. It happens from 3-5% of emails received by the application.

I am running PHP-FPM and Nginx on a Centos9 VM. I have done extensive testing, and I believe it is somewhere within this library. I have been able to send many emails in quick succession, and compare the raw email output using "$mail" from a corrupted and non corrupted email. When comparing just the Base64 values of the same attachment over two different emails the base64 is corrupted sometimes by a single character. I can sometimes simply add a "0" to the front of a line within the base64 text and it will make the attachment work (base64 validated, and decode works). The strange thing also is the Base64 value within the raw email output will be short, breaking the base64 encoded data.

I have traced the error all the way back to the client.php file, even before it leverages the Zend Mail framework. I have even replaced this all together to use "ZBateson\MailMimeParser" to parse the data, and the issue is still present.

To cross out the thought of corruption in transit of the email to the library (before it gets to the server) I also have tried sending emails from multiple SMTP servers (Apple and Microsoft) both the same, I have also addressed the email to another address also (cc) and compared the received raw output, and the cc addressed email arriving in another mailbox is fine. The issue is somewhere within the library or within the Webserver.

Do you have any ideas?

I have already tried replacing the version of PHP from latest, to version 7, updated the mailparse, all without proper resolution of the issue.

TheFox commented 1 year ago

Hi. Thank you for your message.

This library is not dealing with any base64. I don't know how I would start searching for this issue.

hemantkjalin commented 1 year ago
Screenshot 2023-08-16 at 1 59 15 PM

Please see the above screenshot, we are dumping $mail contents, where it contains base64 of the attachment, which is corrupted sometimes.

TheFox commented 1 year ago

Is it also happening when you directly dump $mail, without MailMimeParser ?

hemantkjalin commented 1 year ago

@TheFox Yes, in fact if you see the above screenshot, this mail parser is not doing anything to original $mail object.