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

Commit

Permalink
Merge branch 'hotfix/78' into develop
Browse files Browse the repository at this point in the history
Forward port #78
  • Loading branch information
weierophinney committed Apr 11, 2016
2 parents 34018c4 + e1b0ed6 commit 4c99c0e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ All notable changes to this project will be documented in this file, in reverse
- [#45](https://github.com/zendframework/zend-mail/pull/45) ensures that the
message parser allows deserializing message bodies containing multiple EOL
sequences.
- [#78](https://github.com/zendframework/zend-mail/pull/78) fixes the logic of
`HeaderWrap::canBeEncoded()` to ensure it returns correctly for header lines
containing at least one multibyte character, and particularly when that
character falls at specific locations (per a
[reported bug at php.net](https://bugs.php.net/bug.php?id=53891)).

## 2.6.1 - 2016-02-24

Expand Down
16 changes: 15 additions & 1 deletion src/Header/HeaderWrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@ public static function mimeDecodeValue($value)
*/
public static function canBeEncoded($value)
{
$encoded = iconv_mime_encode('x-test', $value, ['scheme' => 'Q']);
// avoid any wrapping by specifying line length long enough
// "test" -> 4
// "x-test: =?ISO-8859-1?B?dGVzdA==?=" -> 33
// 8 +2 +3 +3 -> 16
$charset = 'UTF-8';
$lineLength = strlen($value) * 4 + strlen($charset) + 16;

$preferences = [
'scheme' => 'Q',
'input-charset' => $charset,
'output-charset' => $charset,
'line-length' => $lineLength,
];

$encoded = iconv_mime_encode('x-test', $value, $preferences);

return (false !== $encoded);
}
Expand Down
21 changes: 21 additions & 0 deletions test/Header/HeaderWrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Mail\Header;

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

/**
Expand Down Expand Up @@ -71,4 +72,24 @@ public function testMimeDecoding()

$this->assertEquals($expected, $decoded);
}

/**
* Test that fails with HeaderWrap::canBeEncoded at lowest level:
* iconv_mime_encode(): Unknown error (7)
*
* which can be triggered as:
* $header = new GenericHeader($name, $value);
*/
public function testCanBeEncoded()
{
$name = 'Subject';
$value = "[#77675] New Issue:xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxx, tähtaeg xx.xx, xxxx";
$encoded = "Subject: =?UTF-8?Q?[#77675]=20New=20Issue:xxxxxxxxx=20xxxxxxx=20xxxxxxxx=20?=\r\n =?UTF-8?Q?xxxxxxxxxxxxx=20xxxxxxxxxx=20xxxxxxxx,=20t=C3=A4htaeg=20xx.xx,=20xxxx?=";
$res = HeaderWrap::canBeEncoded($value);
$this->assertTrue($res);

$header = new GenericHeader($name, $value);
$res = $header->toString();
$this->assertEquals($encoded, $res);
}
}

0 comments on commit 4c99c0e

Please sign in to comment.