Skip to content

Commit

Permalink
Remove double encoding on addresses in EmailComponent.
Browse files Browse the repository at this point in the history
CakeEmail should be handling all the encoding now, duplicating it is
silly.

Fixes #2797
  • Loading branch information
markstory committed Apr 24, 2012
1 parent 1346893 commit 9e3fe63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
27 changes: 1 addition & 26 deletions lib/Cake/Controller/Component/EmailComponent.php
Expand Up @@ -420,31 +420,6 @@ protected function _findFiles($attachment) {
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
*
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
Expand Up @@ -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);
}

}

0 comments on commit 9e3fe63

Please sign in to comment.