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

Use crlf in mail headers #15807

Merged
merged 2 commits into from Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mailer/Transport/MailTransport.php
Expand Up @@ -41,7 +41,7 @@ public function send(Message $message): array
$to = $message->getHeaders(['to'])['To'];
$to = str_replace("\r\n", '', $to);

$eol = $this->getConfig('eol', PHP_EOL);
$eol = $this->getConfig('eol', "\r\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The php bug listed above was fixed in php8. https://bugs.php.net/bug.php?id=47983

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping that MTAs are ok with CRLF in headers. The other option would be to change the default based on the PHP version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the standard and if php 8 is doing it then we're as compatible as php is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if php 7.4 will throw errors because PHP uses \n while cakephp uses \r\n. We might need version-specific default?

Would be nice to test that at least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, using \n for PHP7 would make this a safer change.

$headers = $message->getHeadersString(
[
'from',
Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Mailer/Transport/MailTransportTest.php
Expand Up @@ -88,24 +88,24 @@ public function testSendData()
$encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
$encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';

$data = 'From: CakePHP Test <noreply@cakephp.org>' . PHP_EOL;
$data .= 'Reply-To: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>' . PHP_EOL;
$data .= 'Return-Path: CakePHP Return <pleasereply@cakephp.org>' . PHP_EOL;
$data .= 'Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>' . PHP_EOL;
$data .= 'Bcc: phpnut@cakephp.org' . PHP_EOL;
$data .= 'X-Mailer: CakePHP Email' . PHP_EOL;
$data .= 'Date: ' . $date . PHP_EOL;
$data .= 'X-add: ' . $encoded . PHP_EOL;
$data .= 'Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>' . PHP_EOL;
$data .= 'MIME-Version: 1.0' . PHP_EOL;
$data .= 'Content-Type: text/plain; charset=UTF-8' . PHP_EOL;
$data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$data .= "Reply-To: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>\r\n";
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
$data .= "Bcc: phpnut@cakephp.org\r\n";
$data .= "X-Mailer: CakePHP Email\r\n";
$data .= 'Date: ' . $date . "\r\n";
$data .= 'X-add: ' . $encoded . "\r\n";
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
$data .= "MIME-Version: 1.0\r\n";
$data .= "Content-Type: text/plain; charset=UTF-8\r\n";
$data .= 'Content-Transfer-Encoding: 8bit';

$this->MailTransport->expects($this->once())->method('_mail')
->with(
'CakePHP <cake@cakephp.org>',
$encoded,
implode(PHP_EOL, ['First Line', 'Second Line', '.Third Line', '', '']),
implode("\r\n", ['First Line', 'Second Line', '.Third Line', '', '']),
$data,
'-f'
);
Expand Down