Skip to content

Commit 7fad205

Browse files
committed
Fixing encoding of address aliases.
They are now mime-encoded like other headers. Tests added. Fixes #1360
1 parent 8f3ce4f commit 7fad205

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cake/libs/controller/components/email.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,15 @@ function __encode($subject) {
649649
* @access private
650650
*/
651651
function __formatAddress($string, $smtp = false) {
652-
$hasAlias = preg_match('/((.*)\s)?<(.+)>/', $string, $matches);
652+
$hasAlias = preg_match('/((.*))?\s?<(.+)>/', $string, $matches);
653653
if ($smtp && $hasAlias) {
654654
return $this->__strip('<' . $matches[3] . '>');
655655
} elseif ($smtp) {
656656
return $this->__strip('<' . $string . '>');
657657
}
658+
658659
if ($hasAlias && !empty($matches[2])) {
659-
return $this->__strip($matches[2] . ' <' . $matches[3] . '>');
660+
return $this->__encode($matches[2]) . $this->__strip(' <' . $matches[3] . '>');
660661
}
661662
return $this->__strip($string);
662663
}
@@ -850,4 +851,4 @@ function __debug() {
850851
}
851852

852853
}
853-
?>
854+
?>

cake/tests/cases/libs/controller/components/email.test.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ function testFormatAddressAliases() {
795795

796796
$result = $this->Controller->EmailTest->formatAddress('alias <email@example.com>');
797797
$this->assertEqual($result, 'alias <email@example.com>');
798+
799+
$result = $this->Controller->EmailTest->formatAddress('alias<email@example.com>');
800+
$this->assertEqual($result, 'alias <email@example.com>');
798801

799802
$result = $this->Controller->EmailTest->formatAddress('email@example.com');
800803
$this->assertEqual($result, 'email@example.com');
@@ -811,5 +814,22 @@ function testFormatAddressAliases() {
811814
$result = $this->Controller->EmailTest->formatAddress('alias name <email@example.com>', true);
812815
$this->assertEqual($result, '<email@example.com>');
813816
}
817+
818+
/**
819+
* test formatting addresses with multibyte chars
820+
*
821+
* @return void
822+
*/
823+
function testFormatAddressMultibyte() {
824+
$this->Controller->EmailTest->charset = 'UTF-8';
825+
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest <email@domain.de>');
826+
$this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdCA=?= <email@domain.de>');
827+
828+
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest<email@domain.de>');
829+
$this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdA==?= <email@domain.de>');
830+
831+
$result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest <email@domain.de>', true);
832+
$this->assertEqual($result, '<email@domain.de>');
833+
}
814834
}
815835
?>

0 commit comments

Comments
 (0)