Fixing encoding of address aliases. They are now mime-encoded like other headers. Tests added. Fixes #1360

This commit is contained in:
mark_story 2010-12-13 23:23:02 -05:00
parent e410509684
commit 53a687049c
2 changed files with 23 additions and 2 deletions

View file

@ -774,14 +774,15 @@ class EmailComponent extends Object{
* @access private
*/
function _formatAddress($string, $smtp = false) {
$hasAlias = preg_match('/((.*)\s)?<(.+)>/', $string, $matches);
$hasAlias = preg_match('/((.*))?\s?<(.+)>/', $string, $matches);
if ($smtp && $hasAlias) {
return $this->_strip('<' . $matches[3] . '>');
} elseif ($smtp) {
return $this->_strip('<' . $string . '>');
}
if ($hasAlias && !empty($matches[2])) {
return $this->_strip($matches[2] . ' <' . $matches[3] . '>');
return $this->_encode($matches[2]) . $this->_strip(' <' . $matches[3] . '>');
}
return $this->_strip($string);
}

View file

@ -1216,6 +1216,9 @@ HTMLBLOC;
$result = $this->Controller->EmailTest->formatAddress('alias <email@example.com>');
$this->assertEqual($result, 'alias <email@example.com>');
$result = $this->Controller->EmailTest->formatAddress('alias<email@example.com>');
$this->assertEqual($result, 'alias <email@example.com>');
$result = $this->Controller->EmailTest->formatAddress('email@example.com');
$this->assertEqual($result, 'email@example.com');
@ -1232,4 +1235,21 @@ HTMLBLOC;
$result = $this->Controller->EmailTest->formatAddress('alias name <email@example.com>', true);
$this->assertEqual($result, '<email@example.com>');
}
/**
* test formatting addresses with multibyte chars
*
* @return void
*/
function testFormatAddressMultibyte() {
$this->Controller->EmailTest->charset = 'UTF-8';
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest <email@domain.de>');
$this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdCA=?= <email@domain.de>');
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest<email@domain.de>');
$this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdA==?= <email@domain.de>');
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest <email@domain.de>', true);
$this->assertEqual($result, '<email@domain.de>');
}
}