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

Broken linebreaks in auto-generated mails on hosts using qmail #644

Closed
th-h opened this issue Oct 13, 2019 · 0 comments
Closed

Broken linebreaks in auto-generated mails on hosts using qmail #644

th-h opened this issue Oct 13, 2019 · 0 comments

Comments

@th-h
Copy link
Member

th-h commented Oct 13, 2019

What s9y does

Serendipity will convert the body of auto-generated mails to quoted-printable if imap_8bit() is available, and to base64 otherwise. Quoted-printable will trim all lines to less then 76 characters and add "soft" linebreaks; "real" linebreaks ("\n") will be encoded, too (as "=A0"). Decoding will go the other way around. The mail will be send using PHP's mail() function.

The way it should go

So, the text

A new comment has been posted on your blog "Serendipity", to the entry entitled "Serendipity 2.3.1 released".
Link to entry: https://blog.s9y.org/archives/286-Serendipity-2.3.1-released.html

will be encoded to

A new comment has been posted on your blog "Serendipity", to the entry enti=
tled "Serendipity 2.3.1 released".=0ALink to entry: https://blog.s9y.org/ar=
chives/286-Serendipity-2.3.1-released.html=0A=0A

and decoded right back to the original text.

What goes wrong

But sometimes, those messages will get mangled, due to extra linebreaks. The encoded message will now look like this:

A new comment has been posted on your blog "Serendipity", to the entry enti=

tled "Serendipity 2.3.1 released".=0ALink to entry: https://blog.s9y.org/ar=

chives/286-Serendipity-2.3.1-released.html=0A=0A

The decodes message will now look mangled like this:


A new comment has been posted on your blog "Serendipity", to the entry enti
tled "Serendipity 2.3.1 released".
Link to entry: https://blog.s9y.org/ar
chives/286-Serendipity-2.3.1-released.html

The cause of this problem

... seems to be qmail (again). I couldn't reproduce the problem, as all my hosts run Exim as MTA; but Uberspace does not, the use qmail. Using a little test script, I can confirm that messages delivered using mail() on a host running Exim (and sendmail, and probably Postfix, too) will arrive just fine, but on a host running qmail (especially on corvus) will get mangled.

Old messages from more than 15 years ago seem to pin the problem to qmail's handling of linebreaks in incoming mail. imap_8bit() will use \r\n as linebreaks as mandated in RFC 822 (and its descendants). Most MTAs can handle that, but qmail seems to insist on getting an ordinary UNIX text file as input and converting all \n linebreaks to the \r\n needed for SMTP transmission, so we get \r\r\n. That's one \r too much, leading to our problems. It's even documented on the PHP mail() page ...

@th-h th-h closed this as completed in 9867d70 Oct 13, 2019
th-h added a commit to th-h/Serendipity that referenced this issue Oct 13, 2019
s9y will encode the body of its auto-generated
mails as quoted-printable when imap_8bit() is
available. imap_8bit() will use "\r\n" as
linebreaks as mandated for SMTP transfer.
The result will be transmitted via PHP's
mail() function, using direct SMTP on
Windows and piping it to a MTA on Unix.

Most MTAs will cope just fine with those
linebreaks, while qmail will not; it will
replace all "\n" linebreaks with "\r\n",
so we get "\r\r\n" in our case. We can't
"fix" qmail (as its maintainer, if there
even is one, does not consider this
behaviour wrong), but we can replace the
line endings we get from imap_8bit().

The fix does work with qmail and Exim and
should work with sendmail and Postfix and
other MTAs, too. It may break sending
mail on Windows (i.e. lose all linebreaks),
but I think that's acceptable, as we'll
have more qmail installation than Windows
servers out there.

A workaround could be to set
serendipity['forceBase64']=true in
serendipity_config_local.inc.php, but I'd
prefer this fix.

Fixes s9y#644.

Signed-off-by: Thomas Hochstein <thh@inter.net>
th-h added a commit to th-h/Serendipity that referenced this issue Oct 13, 2019
s9y will encode the body of its auto-generated
mails as quoted-printable when imap_8bit() is
available. imap_8bit() will use "\r\n" as
linebreaks as mandated for SMTP transfer.
The result will be transmitted via PHP's
mail() function, using direct SMTP on
Windows and piping it to a MTA on Unix.

Most MTAs will cope just fine with those
linebreaks, while qmail will not; it will
replace all "\n" linebreaks with "\r\n",
so we get "\r\r\n" in our case. We can't
"fix" qmail (as its maintainer, if there
even is one, does not consider this
behaviour wrong), but we can replace the
line endings we get from imap_8bit().

The fix does work with qmail and Exim and
should work with sendmail and Postfix and
other MTAs, too. It may break sending
mail on Windows (i.e. lose all linebreaks),
but I think that's acceptable, as we'll
have more qmail installation than Windows
servers out there.

A workaround could be to set
serendipity['forceBase64']=true in
serendipity_config_local.inc.php, but I'd
prefer this fix.

Fixes s9y#644.

Backported from master branch.

Signed-off-by: Thomas Hochstein <thh@inter.net>
robelix pushed a commit to robelix/Serendipity that referenced this issue Mar 9, 2020
s9y will encode the body of its auto-generated
mails as quoted-printable when imap_8bit() is
available. imap_8bit() will use "\r\n" as
linebreaks as mandated for SMTP transfer.
The result will be transmitted via PHP's
mail() function, using direct SMTP on
Windows and piping it to a MTA on Unix.

Most MTAs will cope just fine with those
linebreaks, while qmail will not; it will
replace all "\n" linebreaks with "\r\n",
so we get "\r\r\n" in our case. We can't
"fix" qmail (as its maintainer, if there
even is one, does not consider this
behaviour wrong), but we can replace the
line endings we get from imap_8bit().

The fix does work with qmail and Exim and
should work with sendmail and Postfix and
other MTAs, too. It may break sending
mail on Windows (i.e. lose all linebreaks),
but I think that's acceptable, as we'll
have more qmail installation than Windows
servers out there.

A workaround could be to set
serendipity['forceBase64']=true in
serendipity_config_local.inc.php, but I'd
prefer this fix.

Fixes s9y#644.

Signed-off-by: Thomas Hochstein <thh@inter.net>
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

No branches or pull requests

1 participant