Skip to content
Permalink
Browse files

Fix encoding of addreses containin comma & unicode

Email addresses that contain both unicode and commas will not be
correctly encoded by mime_encode_header if the comma precedes the
unicode. In this scenario we have to quote the encoded address.

Refs #10763
  • Loading branch information...
markstory committed Jun 12, 2017
1 parent 910d045 commit 738b20a19b58e675ea7948a4e4ca7564c2dd4b41
Showing with 31 additions and 5 deletions.
  1. +4 −1 lib/Cake/Network/Email/CakeEmail.php
  2. +27 −4 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -830,7 +830,10 @@ protected function _formatAddress($address) {
$return[] = $email;
} else {
$encoded = $this->_encode($alias);
if ($encoded === $alias && preg_match('/[^a-z0-9 ]/i', $encoded)) {
if (
$encoded === $alias && preg_match('/[^a-z0-9 ]/i', $encoded) ||
strpos($encoded, ',') !== false
) {
$encoded = '"' . str_replace('"', '\"', $encoded) . '"';
}
$return[] = sprintf('%s <%s>', $encoded, $email);
@@ -450,10 +450,6 @@ public function testFormatAddress() {
$expected = array('CakePHP <cake@cakephp.org>', 'Cake <php@cakephp.org>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array('me@example.com' => 'Last, First'));
$expected = array('"Last, First" <me@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array('me@example.com' => '"Last" First'));
$expected = array('"\"Last\" First" <me@example.com>');
$this->assertSame($expected, $result);
@@ -471,6 +467,33 @@ public function testFormatAddress() {
$this->assertSame($expected, $result);
}
/**
* Test that addresses are quoted correctly when they contain unicode and
* commas
*
* @return void
*/
public function testFormatAddressEncodeAndEscape()
{
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Website, ascii'
));
$expected = array('"Website, ascii" <test@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Wébsite, unicode'
));
$expected = array('=?UTF-8?B?V8OpYnNpdGUsIHVuaWNvZGU=?= <test@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Website, électric'
));
$expected = array('"Website, =?UTF-8?B?w6lsZWN0cmlj?=" <test@example.com>');
$this->assertSame($expected, $result);
}
/**
* testFormatAddressJapanese
*

0 comments on commit 738b20a

Please sign in to comment.
You can’t perform that action at this time.