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

Commit c8dd3c6

Browse files
committed
Merge branch 'hotfix/78'
Close #78 Fixes #64 Fixes #33
2 parents ff509a0 + e1b0ed6 commit c8dd3c6

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ All notable changes to this project will be documented in this file, in reverse
2424
- [#45](https://github.com/zendframework/zend-mail/pull/45) ensures that the
2525
message parser allows deserializing message bodies containing multiple EOL
2626
sequences.
27+
- [#78](https://github.com/zendframework/zend-mail/pull/78) fixes the logic of
28+
`HeaderWrap::canBeEncoded()` to ensure it returns correctly for header lines
29+
containing at least one multibyte character, and particularly when that
30+
character falls at specific locations (per a
31+
[reported bug at php.net](https://bugs.php.net/bug.php?id=53891)).
2732

2833
## 2.6.1 - 2016-02-24
2934

src/Header/HeaderWrap.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,21 @@ public static function mimeDecodeValue($value)
116116
*/
117117
public static function canBeEncoded($value)
118118
{
119-
$encoded = iconv_mime_encode('x-test', $value, ['scheme' => 'Q']);
119+
// avoid any wrapping by specifying line length long enough
120+
// "test" -> 4
121+
// "x-test: =?ISO-8859-1?B?dGVzdA==?=" -> 33
122+
// 8 +2 +3 +3 -> 16
123+
$charset = 'UTF-8';
124+
$lineLength = strlen($value) * 4 + strlen($charset) + 16;
125+
126+
$preferences = [
127+
'scheme' => 'Q',
128+
'input-charset' => $charset,
129+
'output-charset' => $charset,
130+
'line-length' => $lineLength,
131+
];
132+
133+
$encoded = iconv_mime_encode('x-test', $value, $preferences);
120134

121135
return (false !== $encoded);
122136
}

test/Header/HeaderWrapTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Mail\Header;
1111

12+
use Zend\Mail\Header\GenericHeader;
1213
use Zend\Mail\Header\HeaderWrap;
1314

1415
/**
@@ -71,4 +72,24 @@ public function testMimeDecoding()
7172

7273
$this->assertEquals($expected, $decoded);
7374
}
75+
76+
/**
77+
* Test that fails with HeaderWrap::canBeEncoded at lowest level:
78+
* iconv_mime_encode(): Unknown error (7)
79+
*
80+
* which can be triggered as:
81+
* $header = new GenericHeader($name, $value);
82+
*/
83+
public function testCanBeEncoded()
84+
{
85+
$name = 'Subject';
86+
$value = "[#77675] New Issue:xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxx, tähtaeg xx.xx, xxxx";
87+
$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?=";
88+
$res = HeaderWrap::canBeEncoded($value);
89+
$this->assertTrue($res);
90+
91+
$header = new GenericHeader($name, $value);
92+
$res = $header->toString();
93+
$this->assertEquals($encoded, $res);
94+
}
7495
}

0 commit comments

Comments
 (0)