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:
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.
Refactor the code to not use (two) stream filters or to be more explicit about the ordering.
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 usestream_filter_prepend()
instead ofstream_filter_append()
inKodus\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()
, thesmtp.dot_stuffing
is appended to the output socket beforeconvert.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 thesmtp.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:After quoted printable (as configured by
kodus/mail
) it becomes:I see two possible fixes:
stream_filter_append()
bystream_filter_prepend()
inKodus\Mail\Writer::writeFiltered()
. This causes the quoted-printable filter to be applied before dot-stuffing.