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

mail() breaks quoted_printable_encode()d subject #14084

Open
hornschorsch opened this issue Apr 30, 2024 · 2 comments
Open

mail() breaks quoted_printable_encode()d subject #14084

hornschorsch opened this issue Apr 30, 2024 · 2 comments

Comments

@hornschorsch
Copy link

Description

The following code:

$subject = "=?$charset?Q?" . quoted_printable_encode("Onlinetreffen $thema $datum $zeit") . "?=";
[...]
mail("$mailname <$email>", $subject, $mailtext, $headers, "-f $mailfrom");

Resulted in an email with this header:

Subject: =?iso-8859-1?Q?Onlinetreffen Starke Leistungen - fairer Beitrag: Das sollten ver.di Mitgli=  eder unbedingt wissen 14.05.2024 17:00:00?=

But I expected this header instead:

Subject: =?iso-8859-1?Q?Onlinetreffen Starke Leistungen - fairer Beitrag: Das sollten ver.di Mitgli=
 eder unbedingt wissen 14.05.2024 17:00:00?=

This happens because quoted_printable_encode() wraps lines at 75 characters and therefore inserts a "=\r\n" but the mail() function replaces every control character, that is not a \r followed by \n followed by space, with a space.

So quoted_printable_encode() should insert an additional space to prevent mail() from replacing the \r\n with spaces or the check in mail() should not check for a space after "\r\n" but for a "=" before the "\r\n"

https://github.com/php/php-src/blob/master/ext/standard/quot_print.c#L175
https://github.com/php/php-src/blob/master/ext/standard/mail.c#L307
https://github.com/php/php-src/blob/master/ext/standard/mail.c#L49

PHP Version

current version, see links to sourcecode

Operating System

No response

@SakiTakamachi
Copy link
Member

I have a question, is the notation using = still valid? That's code written a long time ago...

@hornschorsch
Copy link
Author

According to http://www.faqs.org/rfcs/rfc2045.html it is the correct notation:

(Soft Line Breaks) The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long. If longer lines are to be encoded with the Quoted-Printable encoding, "soft" line breaks must be used. An equal sign as the last character on a encoded line indicates such a non-significant ("soft") line break in the encoded text.

Perhaps quoted_printable_encode() is not the right function to encode the subject for the mail() function? How do you encode it then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants