diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 5b2dd1d9f..4bb1782d4 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -420,31 +420,6 @@ class EmailComponent extends Component { return null; } -/** - * Encode the specified string using the current charset - * - * @param string $subject String to encode - * @return string Encoded string - */ - protected function _encode($subject) { - $subject = $this->_strip($subject); - - $nl = "\r\n"; - if ($this->delivery == 'mail') { - $nl = ''; - } - $internalEncoding = function_exists('mb_internal_encoding'); - if ($internalEncoding) { - $restore = mb_internal_encoding(); - mb_internal_encoding($this->charset); - } - $return = mb_encode_mimeheader($subject, $this->charset, 'B', $nl); - if ($internalEncoding) { - mb_internal_encoding($restore); - } - return $return; - } - /** * Format addresses to be an array with email as key and alias as value * @@ -455,7 +430,7 @@ class EmailComponent extends Component { $formatted = array(); foreach ($addresses as $address) { if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) { - $formatted[$this->_strip($matches[3])] = $this->_encode($matches[2]); + $formatted[$this->_strip($matches[3])] = $matches[2]; } else { $address = $this->_strip($address); $formatted[$address] = $address; diff --git a/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php b/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php index b1a272b82..2e1ac3bbb 100644 --- a/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php @@ -879,4 +879,22 @@ HTMLBLOC; $this->assertNotRegExp('/Message-ID:/', $result); } +/** + * Make sure from/to are not double encoded when UTF-8 is present + */ + public function testEncodingFrom() { + $this->Controller->EmailTest->to = 'Teßt '; + $this->Controller->EmailTest->from = 'Teßt '; + $this->Controller->EmailTest->subject = 'Cake Debug Test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + + $this->Controller->EmailTest->delivery = 'DebugComp'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); + $result = DebugCompTransport::$lastEmail; + + $this->assertContains('From: =?UTF-8?B?VGXDn3Qg?= ', $result); + $this->assertContains('To: =?UTF-8?B?VGXDn3Qg?= ', $result); + } + }