Skip to content

Commit

Permalink
Fixing encoding of address aliases.
Browse files Browse the repository at this point in the history
They are now mime-encoded like other headers.
Tests added.
Fixes #1360
  • Loading branch information
markstory committed Jul 23, 2011
1 parent 8f3ce4f commit 7fad205
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cake/libs/controller/components/email.php
Expand Up @@ -649,14 +649,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 Expand Up @@ -850,4 +851,4 @@ function __debug() {
}

}
?>
?>
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -795,6 +795,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 @@ -811,5 +814,22 @@ 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 7fad205

Please sign in to comment.