Skip to content

Commit

Permalink
Merge pull request #15807 from cakephp/fix-15803
Browse files Browse the repository at this point in the history
Use crlf in mail headers
  • Loading branch information
markstory committed Sep 3, 2021
2 parents d7612bd + 706d6dc commit 48735ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
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

0 comments on commit 48735ff

Please sign in to comment.