Skip to content

Commit

Permalink
Fixing encoding of address aliases. They are now mime-encoded like ot…
Browse files Browse the repository at this point in the history
…her headers. Tests added. Fixes #1360
  • Loading branch information
markstory committed Dec 14, 2010
1 parent e410509 commit 53a6870
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cake/libs/controller/components/email.php
Expand Up @@ -774,14 +774,15 @@ function _encode($subject) {
* @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);
}
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -1216,6 +1216,9 @@ function testFormatAddressAliases() {

$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');
Expand All @@ -1232,4 +1235,21 @@ function testFormatAddressAliases() {
$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>');
}
}

0 comments on commit 53a6870

Please sign in to comment.