Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'pr/187' into develop-2.4
  • Loading branch information
glensc committed Dec 28, 2017
2 parents a95c496 + 194a7bf commit 37d646c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Header/HeaderWrap.php
Expand Up @@ -103,6 +103,13 @@ public static function mimeEncodeValue($value, $encoding, $lineLength = 998)
*/
public static function mimeDecodeValue($value)
{
// unfold first, because iconv_mime_decode is discarding "\n" with no apparent reason
// making the resulting value no longer valid.

// see https://tools.ietf.org/html/rfc2822#section-2.2.3 about unfolding
$parts = explode(Headers::FOLDING, $value);
$value = implode(' ', $parts);

$decodedValue = iconv_mime_decode($value, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');

return $decodedValue;
Expand Down
21 changes: 21 additions & 0 deletions test/Header/HeaderWrapTest.php
Expand Up @@ -11,6 +11,7 @@

use Zend\Mail\Header\GenericHeader;
use Zend\Mail\Header\HeaderWrap;
use Zend\Mail\Storage;

/**
* @group Zend_Mail
Expand Down Expand Up @@ -72,6 +73,26 @@ public function testMimeDecoding()
$this->assertEquals($expected, $decoded);
}

/**
* Test that header lazy-loading doesn't break later header access
* because undocumented behavior on
* @see https://github.com/zendframework/zend-mail/pull/187
*/
public function testMimeDecodeBreakageBug()
{
$headerValue = "v=1; a=rsa-sha25; c=relaxed/simple; d=example.org; h=\r\n\tcontent-language:content-type:content-type:in-reply-to";
$headers = "DKIM-Signature: {$headerValue}";

$message = new Storage\Message(array('headers' => $headers, 'content' => 'irrelevant'));
$headers = $message->getHeaders();
// calling toString will lazy load all headers
// and would break DKIM-Signature header access
$headers->toString();

$header = $headers->get('DKIM-Signature');
$this->assertEquals('v=1; a=rsa-sha25; c=relaxed/simple; d=example.org; h= content-language:content-type:content-type:in-reply-to', $header->getFieldValue());
}

/**
* Test that fails with HeaderWrap::canBeEncoded at lowest level:
* iconv_mime_encode(): Unknown error (7)
Expand Down

0 comments on commit 37d646c

Please sign in to comment.