Adding more tests for SMTP address formatting. Fixes #1100

This commit is contained in:
mark_story 2010-09-12 11:48:09 -04:00
parent 703344cbae
commit e9d194822d
2 changed files with 17 additions and 3 deletions

View file

@ -743,9 +743,14 @@ class EmailComponent extends Object{
* @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 file

@ -1178,5 +1178,14 @@ HTMLBLOC;
$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>');
}
}