Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove double encoding on addresses in EmailComponent.

CakeEmail should be handling all the encoding now, duplicating it is
silly.

Fixes #2797
  • Loading branch information...
commit 9e3fe633bba6c31f9700ed0d7fef4cf8ab8223ff 1 parent 1346893
@markstory markstory authored
View
27 lib/Cake/Controller/Component/EmailComponent.php
@@ -421,31 +421,6 @@ protected function _findFiles($attachment) {
}
/**
- * 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
*
* @param array $addresses
@@ -455,7 +430,7 @@ protected function _formatAddresses($addresses) {
$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;
View
18 lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
@@ -879,4 +879,22 @@ public function testMessageId() {
$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 <test@example.com>';
+ $this->Controller->EmailTest->from = 'Teßt <test@example.com>';
+ $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?= <test@example.com>', $result);
+ $this->assertContains('To: =?UTF-8?B?VGXDn3Qg?= <test@example.com>', $result);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.