Remove double encoding on addresses in EmailComponent.

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

Fixes #2797
This commit is contained in:
mark_story 2012-04-23 21:41:08 -04:00
parent 13468937cc
commit 9e3fe633bb
2 changed files with 19 additions and 26 deletions

View file

@ -420,31 +420,6 @@ class EmailComponent extends Component {
return null; 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 * Format addresses to be an array with email as key and alias as value
* *
@ -455,7 +430,7 @@ class EmailComponent extends Component {
$formatted = array(); $formatted = array();
foreach ($addresses as $address) { foreach ($addresses as $address) {
if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) { 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 { } else {
$address = $this->_strip($address); $address = $this->_strip($address);
$formatted[$address] = $address; $formatted[$address] = $address;

View file

@ -879,4 +879,22 @@ HTMLBLOC;
$this->assertNotRegExp('/Message-ID:/', $result); $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);
}
} }