diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 2aa96c3e0..83ee15df2 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -774,14 +774,15 @@ class EmailComponent extends Object{ * @access private */ function _formatAddress($string, $smtp = false) { - $hasAlias = preg_match('/((.*)\s)?<(.+)>/', $string, $matches); + $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->_encode($matches[2]) . $this->_strip(' <' . $matches[3] . '>'); } return $this->_strip($string); } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index ed80c1b2b..0dbb72d0e 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -1216,6 +1216,9 @@ HTMLBLOC; $result = $this->Controller->EmailTest->formatAddress('alias '); $this->assertEqual($result, 'alias '); + + $result = $this->Controller->EmailTest->formatAddress('alias'); + $this->assertEqual($result, 'alias '); $result = $this->Controller->EmailTest->formatAddress('email@example.com'); $this->assertEqual($result, 'email@example.com'); @@ -1232,4 +1235,21 @@ HTMLBLOC; $result = $this->Controller->EmailTest->formatAddress('alias name ', true); $this->assertEqual($result, ''); } + +/** + * test formatting addresses with multibyte chars + * + * @return void + */ + function testFormatAddressMultibyte() { + $this->Controller->EmailTest->charset = 'UTF-8'; + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest '); + $this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdCA=?= '); + + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest'); + $this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdA==?= '); + + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest ', true); + $this->assertEqual($result, ''); + } }