Navigation Menu

Skip to content

Commit

Permalink
Adding more tests for SMTP address formatting. Fixes #1100
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 14, 2010
1 parent 8a43b6d commit 1b48cd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cake/libs/controller/components/email.php
Expand Up @@ -617,9 +617,14 @@ function __encode($subject) {
* @access private
*/
function __formatAddress($string, $smtp = false) {
$hasAlias = preg_match('/(.+)\s<(.+)>/', $string, $matches);
if ($hasAlias) {
return $this->__strip($matches[1] . ' <' . $matches[2] . '>');
$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->__strip($string);
}
Expand Down
9 changes: 9 additions & 0 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -692,6 +692,15 @@ function testFormatAddressAliases() {

$result = $this->Controller->EmailTest->formatAddress('<email@example.com>');
$this->assertEqual($result, '<email@example.com>');

$result = $this->Controller->EmailTest->formatAddress('email@example.com', true);
$this->assertEqual($result, ' <email@example.com>');

$result = $this->Controller->EmailTest->formatAddress('<email@example.com>', true);
$this->assertEqual($result, ' <email@example.com>');

$result = $this->Controller->EmailTest->formatAddress('alias name <email@example.com>', true);
$this->assertEqual($result, ' <email@example.com>');
}
}
?>

0 comments on commit 1b48cd6

Please sign in to comment.