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 all commits
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', version_compare(PHP_VERSION, '8.0', '>=') ? "\r\n" : "\n");
$headers = $message->getHeadersString(
[
'from',
Expand Down
26 changes: 14 additions & 12 deletions tests/TestCase/Mailer/Transport/MailTransportTest.php
Expand Up @@ -67,6 +67,8 @@ public function testSendWithoutRecipient()
*/
public function testSendData()
{
$eol = version_compare(PHP_VERSION, '8.0', '>=') ? "\r\n" : "\n";

$message = new Message();
$message->setFrom('noreply@cakephp.org', 'CakePHP Test');
$message->setReturnPath('pleasereply@cakephp.org', 'CakePHP Return');
Expand All @@ -88,24 +90,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>{$eol}";
$data .= "Reply-To: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>{$eol}";
$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>{$eol}";
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>{$eol}";
$data .= "Bcc: phpnut@cakephp.org{$eol}";
$data .= "X-Mailer: CakePHP Email{$eol}";
$data .= 'Date: ' . $date . $eol;
$data .= 'X-add: ' . $encoded . $eol;
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>{$eol}";
$data .= "MIME-Version: 1.0{$eol}";
$data .= "Content-Type: text/plain; charset=UTF-8{$eol}";
$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($eol, ['First Line', 'Second Line', '.Third Line', '', '']),
$data,
'-f'
);
Expand Down