Skip to content

Commit

Permalink
Bug: 14456 Ensure address-type headers are MIME decoded.
Browse files Browse the repository at this point in the history
This got lost during the refactoring to the individual
Horde_Mime_Header* objects. Fixes incorrect parsing of email
address lists when source headers are MIME encoded.
  • Loading branch information
mrubinsk committed Sep 5, 2016
1 parent b0ad380 commit 9cf5454
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions framework/Mime/lib/Horde/Mime/Headers/Addresses.php
Expand Up @@ -64,6 +64,14 @@ public function getAddressList($first = false)
: array($this->_values);
}

protected function _decodeMime($value)
{
if (is_object($value)) {
return $value;
}
return Horde_Mime::decode($value);
}

/**
*
* @throws Horde_Mime_Exception
Expand All @@ -73,6 +81,16 @@ protected function _setValue($value)
/* @todo Implement with traits */
$rfc822 = new Horde_Mail_Rfc822();

// Ensure values are MIME decoded.
// @see Bug 14456
if (is_array($value)) {
foreach ($value as &$adr) {
$adr = $this->_decodeMime($adr);
}
} else {
$value = $this->_decodeMime($value);
}

try {
$addr_list = $rfc822->parseAddressList($value);
} catch (Horde_Mail_Exception $e) {
Expand Down
36 changes: 36 additions & 0 deletions framework/Mime/test/Horde/Mime/HeadersTest.php
Expand Up @@ -109,6 +109,42 @@ public function serializeProvider()
);
}

/**
* @dataProvider mimeEncodedAddressProvider
*/
public function testBug14456($header, $value, $decoded)
{
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader($header, $value);
$this->assertEquals($decoded, $hdrs->getValue($header));
}

public function mimeEncodedAddressProvider()
{
return array(
array(
'To',
'=?utf-8?Q?"Mike,_H=C3=A5vard"?= <mike@example.com>',
'"Mike, Håvard" <mike@example.com>'
),
array(
'To',
'=?utf-8?Q?"Steve,_H=C3=A5vard"?= <steve@example.com>, =?utf-8?Q?"Bob,_H=C3=A5vard"?= <bob@example.com>',
'"Steve, Håvard" <steve@example.com>, "Bob, Håvard" <bob@example.com>'
),
array(
'To',
'sheldon@example.com',
'sheldon@example.com'
),
array(
'From',
'=?utf-8?Q?"Mike,_H=C3=A5vard"?= <mike@example.com>',
'"Mike, Håvard" <mike@example.com>'
)
);
}

/**
* @dataProvider normalHeaderDecodeProvider
*/
Expand Down

0 comments on commit 9cf5454

Please sign in to comment.