mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding more tests for SMTP address formatting. Fixes #1100
This commit is contained in:
parent
703344cbae
commit
e9d194822d
2 changed files with 17 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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>');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue