Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding more tests for SMTP address formatting. Fixes #1100

  • Loading branch information...
commit 1b48cd60a719fcec3f4de3d9924b7b89f8ac079f 1 parent 8a43b6d
@markstory markstory authored
View
11 cake/libs/controller/components/email.php
@@ -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);
}
View
9 cake/tests/cases/libs/controller/components/email.test.php
@@ -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>');
}
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.