Skip to content
Permalink
Browse files

Adding more tests for SMTP address formatting. Fixes #1100

  • Loading branch information...
markstory committed Sep 12, 2010
1 parent 8a43b6d commit 1b48cd60a719fcec3f4de3d9924b7b89f8ac079f
@@ -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);
}
@@ -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.
You can’t perform that action at this time.