axllent / mailpit

An email and SMTP testing tool with API for developers
https://mailpit.axllent.org
MIT License
5.48k stars 136 forks source link

Long link urls in mails have wrong extra dots #350

Closed mediaessenz closed 1 month ago

mediaessenz commented 1 month ago

What I did: I discovered some strange problems with link urls in emails caught by mailpit. Some urls in emails get two points ("..") where only one point should be. For example an url should look like this:

https://mail-dev-typo3-13.ddev.site/?mail=61&rid=tt_address-1&aC=236308eb&jumpurl=https://mail-dev-typo3-13.ddev.site/_assets/0ded769d04985086564d46d9100f6b95/Images/mailerping.gif

but looks like:

https://mail-dev-typo3-13.ddev.site/?mail=61&rid=tt_address-1&aC=236308eb&jumpurl=https://mail-dev-typo3-13.ddev.site/_assets/0ded769d04985086564d46d9100f6b95/Images/mailerping..gif 

See the last part /mailerping..gif which has an extra (wrong) point.

This happens not always at the same place. In some generated mails the double point appear at a different place like so:

https://mail-dev-typo3-13.ddev.site/?mail=62&rid=fe_users-1&aC=236308eb&jumpurl=https://mail-dev-typo3-13..ddev.site/_assets/0ded769d04985086564d46d9100f6b95/Images/mailerping.gif

In this case, there is an extra point at &jumpurl=https://mail-dev-typo3-13..ddev.site/.

This happens in mailpit 1.19.3 and 1.20.2 as well.

What I expected: Correct Link-Urls without any modifications.

What I got: Incorrect, not working Link-Urls.

Release or branch I am using: I tried it with 1.19.3 and 1.20.2

I also posted this issue to the enmime project: https://github.com/jhillyerd/enmime/issues/341

axllent commented 1 month ago

Please could you attach an example message where this is happening? Feel free to remove any personal information from the headers etc - but I'd like to try to determine whether it is the message itself, or the parser.

mediaessenz commented 1 month ago

Archiv.zip Attached two eml files in a zip, which I got by clicking on "Download" > "Raw message"

axllent commented 1 month ago

I can see the double-dot in the quoted printable HTML content in both emails you attached:

;rid=3Dfe_users-1&aC=3D236308eb&jumpurl=3Dhttps://mail-dev-typo3-13=
..ddev.site/_assets/0ded769d04985086564d46d9100f6b95/Images/mailerping.gif" =

and

po3-13.ddev.site/_assets/0ded769d04985086564d46d9100f6b95/Images/mailerping=
..gif" width=3D"1" height=3D"1" alt=3D"" style=3D"outline: none; text-decora=

The issue is not the decoding at all - the issue is the encoding (what generated the message).

TYPO3 uses the symfony mailer, and the symfony mailer has this code which appears to be prefixing any line starting with a dot - with another dot ~ if the sendmail command does not contain a -i (link below).

I do not know why symfony would prefix all line starting with a . when postfix's sendmail states:

       -i     When  reading  a message from standard input, don't treat a line
              with only a . character as the end of input.

The difference here is postfix is referring to a line that contains only a dot, yet, if I understand the code correctly, symfony is replacing any line starting with a dot (regardless what comes after).

The "solution" (I think this is more of a work-around) is apparently to modify the sendmail command in your application (TYPO3) to include -i, however I don't know how you do that in TYPO3.

mediaessenz commented 1 month ago

Your are the best! This additional -i solve the problems! In the case of TYPO3, its done with this MAIL configuration:

'transport_sendmail_command' => '/usr/local/bin/mailpit sendmail -t -i --smtp-addr 127.0.0.1:1025',
axllent commented 1 month ago

Excellent, I'm glad it resolved the issue!