Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quoted-printable and dot-stuffing filters applied in wrong order! #21

Closed
rhl-jfm opened this issue Sep 27, 2024 · 0 comments · Fixed by #22
Closed

quoted-printable and dot-stuffing filters applied in wrong order! #21

rhl-jfm opened this issue Sep 27, 2024 · 0 comments · Fixed by #22
Assignees

Comments

@rhl-jfm
Copy link
Contributor

rhl-jfm commented Sep 27, 2024

TL;DR kodus/mail sometimes fails to do dot-stuffing on leading "." when sending mail via SMTP, leading to an SMTP protocol error. A possible fix is to use stream_filter_prepend() instead of stream_filter_append() in Kodus\Mail\Writer::writeFiltered()

In the current implementation, quoted-printable encoding and SMTP dot-stuffing are both implemented using PHP stream filters. When calling Kodus\Mail\SMTP\SMTPMailService::send(), the smtp.dot_stuffing is appended to the output socket before convert.quoted-printable-encode. This is a mistake, as the SMTP dot-stuffing is a lower level concern (a part of the protocol) and must be performed as the last step.

Usually this works out fine, but sometimes convert.quoted-printable-encode will break up a long line, putting a single dot on a line by itself. Lines with single dots are exactly what the smtp.dot_stuffing filter is meant to handle, but it never sees this output.

An example of a mail body that does not work with the current kodus/mail is:

Test mail 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.
More text.

After quoted printable (as configured by kodus/mail) it becomes:

Test mail 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890=
.
More text.

I see two possible fixes:

  1. Replace the use of stream_filter_append() by stream_filter_prepend() in Kodus\Mail\Writer::writeFiltered(). This causes the quoted-printable filter to be applied before dot-stuffing.
  2. Refactor the code to not use (two) stream filters or to be more explicit about the ordering.
@vortrixs vortrixs self-assigned this Oct 2, 2024
@vortrixs vortrixs linked a pull request Oct 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants