From 145dbacb78e15730ca49762f64181be57916b3ee Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 4 Nov 2013 22:17:21 -0500 Subject: [PATCH 1/2] Fix incorrectly encoded headers in MailTransport. When encoded values are present in header fields, they need to have newlines removed as leaving the newlines in place and interfere with delivery on Qmail based SMTP servers. Fixes #2209 --- lib/Cake/Network/Email/MailTransport.php | 3 +++ .../Case/Network/Email/MailTransportTest.php | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Network/Email/MailTransport.php b/lib/Cake/Network/Email/MailTransport.php index 3ad50f7f8..4435a35bc 100644 --- a/lib/Cake/Network/Email/MailTransport.php +++ b/lib/Cake/Network/Email/MailTransport.php @@ -40,6 +40,9 @@ class MailTransport extends AbstractTransport { $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc')); $to = $headers['To']; unset($headers['To']); + foreach ($headers as $key => $header) { + $headers[$key] = str_replace(array("\r", "\n"), '', $header); + } $headers = $this->_headersToString($headers, $eol); $message = implode($eol, $email->message()); $subject = str_replace(array("\r", "\n"), '', $email->subject()); diff --git a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php index 98445dec5..e948bcea3 100644 --- a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php @@ -52,10 +52,19 @@ class MailTransportTest extends CakeTestCase { $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); $email->bcc('phpnut@cakephp.org'); $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); - $email->subject('Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz'); + $longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz'; + $email->subject($longNonAscii); $date = date(DATE_RFC2822); - $email->setHeaders(array('X-Mailer' => 'CakePHP Email', 'Date' => $date)); - $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); + $email->setHeaders(array( + 'X-Mailer' => 'CakePHP Email', + 'Date' => $date, + 'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'), + )); + $email->expects($this->any())->method('message') + ->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); + + $encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?='; + $encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?='; $data = "From: CakePHP Test " . PHP_EOL; $data .= "Return-Path: CakePHP Return " . PHP_EOL; @@ -63,17 +72,16 @@ class MailTransportTest extends CakeTestCase { $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 .= "Content-Transfer-Encoding: 8bit"; - $subject = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?='; - $subject .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?='; $this->MailTransport->expects($this->once())->method('_mail') ->with( 'CakePHP ', - $subject, + $encoded, implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')), $data, '-f' From 9ee5efaa2d750a40a85fbf94219b65617f47b865 Mon Sep 17 00:00:00 2001 From: Bryan Crowe Date: Thu, 7 Nov 2013 22:14:11 -0500 Subject: [PATCH 2/2] Add missing return type --- lib/Cake/Network/CakeRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index b325f26f4..529ff726c 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -756,7 +756,7 @@ class CakeRequest implements ArrayAccess { * {{{ CakeRequest::acceptLanguage('es-es'); }}} * * @param string $language The language to test. - * @return If a $language is provided, a boolean. Otherwise the array of accepted languages. + * @return mixed If a $language is provided, a boolean. Otherwise the array of accepted languages. */ public static function acceptLanguage($language = null) { $raw = self::_parseAcceptWithQualifier(self::header('Accept-Language'));