summaryrefslogtreecommitdiff
path: root/zf-mail-2.4-fixes.patch
blob: 04faef29f694af098817e8ab0404e34aba2141e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
commit a29b8fb3146e318ba3fd9a084859f2e39553c084
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Wed Feb 10 09:35:53 2016 +0200

    test and fix for #64
    
    backport for 2.4
    
    Conflicts:
            src/Header/HeaderWrap.php

diff --git a/src/Header/HeaderWrap.php b/src/Header/HeaderWrap.php
index df532edc..e0be2f56 100644
--- a/src/Header/HeaderWrap.php
+++ b/src/Header/HeaderWrap.php
@@ -116,7 +116,21 @@ abstract class HeaderWrap
      */
     public static function canBeEncoded($value)
     {
-        $encoded = iconv_mime_encode('x-test', $value, array('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';
+        $line_length = strlen($value) * 4 + strlen($charset) + 16;
+
+        $preferences = array(
+            'scheme' => 'Q',
+            'input-charset' => $charset,
+            'output-charset' => $charset,
+            'line-length' => $line_length,
+        );
+
+        $encoded = iconv_mime_encode('x-test', $value, $preferences);
 
         return (false !== $encoded);
     }

commit 755b22727a126608611b6a58c289ad6744db21a9
Merge: 6034313f 393b43c9
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Mon Feb 15 11:51:30 2016 +0200

    Merge tag 'release-2.4.9' into develop-2.4
    
    zend-mail 2.4.9
    
     Conflicts:
            composer.json

commit 222ace2631198f7498ae7c3799caaf6fc3a7936a
Merge: 755b2272 c1c73d7f
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Fri Jan 13 17:39:32 2017 +0200

    Merge tag 'release-2.4.11' into develop-2.4
    
    zend-mail 2.4.11
    
    Added
    -----
    
    - Nothing.
    
    Deprecated
    ----------
    
    - Nothing.
    
    Removed
    -------
    
    - Nothing.
    
    Fixed
    -----
    
    - Fixes the [ZF2016-04 advisory](https://framework.zend.com/security/advisory/ZF2016-04)
      ("Potential remote code execution in zend-mail via Sendmail adapter").

commit 8493b2a0610c59fbeeaf0ffc44340810d4d84d93
Author: Etienne CHAMPETIER <etienne.champetier@fiducial.net>
Date:   Fri May 29 14:32:09 2015 +0200

    Headers: fix bad sprintf call
    
    Signed-off-by: Etienne CHAMPETIER <etienne.champetier@fiducial.net>

diff --git a/src/Headers.php b/src/Headers.php
index 3ceb10be..b416f52a 100644
--- a/src/Headers.php
+++ b/src/Headers.php
@@ -220,6 +220,7 @@ class Headers implements Countable, Iterator
         if (!is_string($headerFieldNameOrLine)) {
             throw new Exception\InvalidArgumentException(sprintf(
                 '%s expects its first argument to be a string; received "%s"',
+                __METHOD__,
                 (is_object($headerFieldNameOrLine)
                 ? get_class($headerFieldNameOrLine)
                 : gettype($headerFieldNameOrLine))

commit 66eeb12567335f3a23aea7538a82e9a144464427
Author: Denis Sokolov <denis@sokolov.cc>
Date:   Wed Jun 10 16:44:27 2015 +0300

    Handle simple comments in address lists

diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php
index e7db7240..b13f9ebd 100644
--- a/src/Header/AbstractAddressList.php
+++ b/src/Header/AbstractAddressList.php
@@ -63,6 +63,7 @@ abstract class AbstractAddressList implements HeaderInterface
             $values,
             function (&$value) {
                 $value = trim($value);
+                $value = self::stripComments($value);
             }
         );
 
@@ -155,4 +156,19 @@ abstract class AbstractAddressList implements HeaderInterface
         $value = $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);
         return (empty($value)) ? '' : sprintf('%s: %s', $name, $value);
     }
+
+    // Supposed to be private, protected as a workaround for PHP bug 68194
+    protected static function stripComments($value)
+    {
+        return preg_replace(
+            '/\\(
+                (
+                    \\\\.|
+                    [^\\\\)]
+                )+
+            \\)/x',
+            '',
+            $value
+        );
+    }
 }

commit 5064f95148c1d996b5b25bc556830da9a8458e6a
Author: Denis Sokolov <denis@sokolov.cc>
Date:   Thu Jun 11 13:27:04 2015 +0300

    Handle groups in address lists

diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php
index b13f9ebd..e0b4e78c 100644
--- a/src/Header/AbstractAddressList.php
+++ b/src/Header/AbstractAddressList.php
@@ -58,6 +58,7 @@ abstract class AbstractAddressList implements HeaderInterface
         }
         // split value on ","
         $fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
+        $fieldValue = preg_replace('/[^:]+:([^;]*);/', '$1,', $fieldValue);
         $values     = str_getcsv($fieldValue, ',');
         array_walk(
             $values,
@@ -66,6 +67,7 @@ abstract class AbstractAddressList implements HeaderInterface
                 $value = self::stripComments($value);
             }
         );
+        $values = array_filter($values);
 
         $addressList = $header->getAddressList();
         foreach ($values as $address) {

commit ebdc224fb6847c39e9691631eef23b3b1c3eb6a0
Author: Stefano Torresi <stefano@torresi.io>
Date:   Wed Jun 3 17:33:40 2015 +0200

    fixes zendframework/zf2#7555

diff --git a/src/Header/Sender.php b/src/Header/Sender.php
index 2efc23bf..e7bcac63 100644
--- a/src/Header/Sender.php
+++ b/src/Header/Sender.php
@@ -39,25 +39,23 @@ class Sender implements HeaderInterface
 
         // check to ensure proper header type for this factory
         if (strtolower($name) !== 'sender') {
-            throw new Exception\InvalidArgumentException('Invalid header line for Sender string');
+            throw new Exception\InvalidArgumentException('Invalid header name for Sender string');
         }
 
-        $header      = new static();
-        $senderName  = '';
-        $senderEmail = '';
+        $header     = new static();
+        $hasMatches = preg_match('/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', $value, $matches);
 
-        // Check for address, and set if found
-        if (preg_match('/^(?P<name>.*?)<(?P<email>[^>]+)>$/', $value, $matches)) {
-            $senderName = trim($matches['name']);
-            if (empty($senderName)) {
-                $senderName = null;
-            }
-            $senderEmail = $matches['email'];
-        } else {
-            $senderEmail = $value;
+        if ($hasMatches !== 1) {
+            throw new Exception\InvalidArgumentException('Invalid header value for Sender string');
+        }
+
+        $senderName = trim($matches['name']);
+
+        if (empty($senderName)) {
+            $senderName = null;
         }
 
-        $header->setAddress($senderEmail, $senderName);
+        $header->setAddress($matches['email'], $senderName);
 
         return $header;
     }

commit c012507f8ae08eb92edb022c290d84dd9966fb46
Author: Stefano Torresi <stefano@torresi.io>
Date:   Mon Oct 26 20:26:11 2015 +0100

    comment the regex

diff --git a/src/Header/Sender.php b/src/Header/Sender.php
index e7bcac63..9f532949 100644
--- a/src/Header/Sender.php
+++ b/src/Header/Sender.php
@@ -43,6 +43,12 @@ class Sender implements HeaderInterface
         }
 
         $header     = new static();
+
+        /**
+         * matches the header value so that the email must be enclosed by < > when a name is present
+         * 'name' and 'email' capture groups correspond respectively to 'display-name' and 'addr-spec' in the ABNF
+         * @see https://tools.ietf.org/html/rfc5322#section-3.4
+         */
         $hasMatches = preg_match('/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', $value, $matches);
 
         if ($hasMatches !== 1) {

commit bfe40077aeed5c2cf401d23d0508d63b5c44d8c6
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Sun Jan 31 00:03:58 2016 +0200

    add format param to toArray
    
    this allows exporting headers in raw or encoded form

diff --git a/src/Headers.php b/src/Headers.php
index b416f52a..c05cde1b 100644
--- a/src/Headers.php
+++ b/src/Headers.php
@@ -430,10 +430,11 @@ class Headers implements Countable, Iterator
     /**
      * Return the headers container as an array
      *
-     * @todo determine how to produce single line headers, if they are supported
+     * @param  bool $format Return the values in Mime::Encoded or in Raw format
      * @return array
+     * @todo determine how to produce single line headers, if they are supported
      */
-    public function toArray()
+    public function toArray($format = Header\HeaderInterface::FORMAT_RAW)
     {
         $headers = array();
         /* @var $header Header\HeaderInterface */
@@ -443,9 +444,9 @@ class Headers implements Countable, Iterator
                 if (!isset($headers[$name])) {
                     $headers[$name] = array();
                 }
-                $headers[$name][] = $header->getFieldValue();
+                $headers[$name][] = $header->getFieldValue($format);
             } else {
-                $headers[$header->getFieldName()] = $header->getFieldValue();
+                $headers[$header->getFieldName()] = $header->getFieldValue($format);
             }
         }
         return $headers;

commit 8892c77410b08d2f0df90d4813904c10d741bd20
Author: Daniel Król <daniel@krol.me>
Date:   Wed Dec 2 17:24:47 2015 +0100

    Inverse decode-split order, allow special char containing labels

diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php
index e0b4e78c..64e5f8f9 100644
--- a/src/Header/AbstractAddressList.php
+++ b/src/Header/AbstractAddressList.php
@@ -42,31 +42,44 @@ abstract class AbstractAddressList implements HeaderInterface
     public static function fromString($headerLine)
     {
         list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
-        $decodedValue = HeaderWrap::mimeDecodeValue($fieldValue);
-        $wasEncoded = ($decodedValue !== $fieldValue);
-        $fieldValue = $decodedValue;
-
         if (strtolower($fieldName) !== static::$type) {
             throw new Exception\InvalidArgumentException(sprintf(
-                'Invalid header line for "%s" string',
-                __CLASS__
-            ));
-        }
-        $header = new static();
-        if ($wasEncoded) {
-            $header->setEncoding('UTF-8');
+                    'Invalid header line for "%s" string',
+                    __CLASS__
+                ));
         }
+
         // split value on ","
         $fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
         $fieldValue = preg_replace('/[^:]+:([^;]*);/', '$1,', $fieldValue);
-        $values     = str_getcsv($fieldValue, ',');
+        $values = str_getcsv($fieldValue, ',');
+
+        $wasEncoded = false;
         array_walk(
             $values,
-            function (&$value) {
-                $value = trim($value);
+            function (&$value) use (&$wasEncoded) {
+                $decodedValue = HeaderWrap::mimeDecodeValue($value);
+                $wasEncoded = $wasEncoded || ($decodedValue !== $value);
+                $value = trim($decodedValue);
                 $value = self::stripComments($value);
+                $value = preg_replace(
+                    [
+                        '#(?<!\\\)"(.*)(?<!\\\)"#', //quoted-text
+                        '#\\\([\x01-\x09\x0b\x0c\x0e-\x7f])#' //quoted-pair
+                    ],
+                    [
+                        '\\1',
+                        '\\1'
+                    ],
+                    $value
+                );
             }
         );
+        $header = new static();
+        if ($wasEncoded) {
+            $header->setEncoding('UTF-8');
+        }
+
         $values = array_filter($values);
 
         $addressList = $header->getAddressList();

commit 9b54b914885a3c07fa7522fe1bedf7fb4482392b
Author: Daniel Król <daniel@krol.me>
Date:   Wed Dec 2 17:01:45 2015 +0100

    Use RFC compliant EOL to allow new lines in message body
    http://www.ietf.org/rfc/rfc2821.txt

diff --git a/src/Message.php b/src/Message.php
index e16c2438..f83c2961 100644
--- a/src/Message.php
+++ b/src/Message.php
@@ -551,7 +551,7 @@ class Message
         $message = new static();
         $headers = null;
         $content = null;
-        Mime\Decode::splitMessage($rawMessage, $headers, $content);
+        Mime\Decode::splitMessage($rawMessage, $headers, $content, Headers::EOL);
         if ($headers->has('mime-version')) {
             // todo - restore body to mime\message
         }

commit 788375fa8b156424a6b9afe40dac23ba6f00b916
Author: Marvin Feldmann <BreyndotEchse@users.noreply.github.com>
Date:   Fri Apr 15 16:53:17 2016 +0200

    Allow DNS Hostnames

diff --git a/src/Address.php b/src/Address.php
index e97878d5..e4c89d20 100644
--- a/src/Address.php
+++ b/src/Address.php
@@ -27,7 +27,7 @@ class Address implements Address\AddressInterface
      */
     public function __construct($email, $name = null)
     {
-        $emailAddressValidator = new EmailAddressValidator(Hostname::ALLOW_LOCAL);
+        $emailAddressValidator = new EmailAddressValidator(Hostname::ALLOW_DNS | Hostname::ALLOW_LOCAL);
         if (! is_string($email) || empty($email)) {
             throw new Exception\InvalidArgumentException('Email must be a valid email address');
         }

commit e37c5e15185143eaaff7f2c4c2a64f605926c978
Author: Marvin Feldmann <BreyndotEchse@users.noreply.github.com>
Date:   Tue Apr 19 16:24:38 2016 +0200

    Return email address(es) with ACE

diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php
index 64e5f8f9..db40486a 100644
--- a/src/Header/AbstractAddressList.php
+++ b/src/Header/AbstractAddressList.php
@@ -94,6 +94,19 @@ abstract class AbstractAddressList implements HeaderInterface
         return $this->fieldName;
     }
 
+    /**
+     * Safely convert UTF-8 encoded domain name to ASCII
+     * @param string $domainName  the UTF-8 encoded email
+     * @return string
+     */
+    protected function idnToAscii($domainName)
+    {
+        if (extension_loaded('intl')) {
+            return (idn_to_ascii($domainName) ?: $domainName);
+        }
+        return $domainName;
+    }
+
     public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
     {
         $emails   = array();
@@ -103,22 +116,29 @@ abstract class AbstractAddressList implements HeaderInterface
             $email = $address->getEmail();
             $name  = $address->getName();
 
-            if (empty($name)) {
-                $emails[] = $email;
-                continue;
-            }
-
-            if (false !== strstr($name, ',')) {
+            if (!empty($name) && false !== strstr($name, ',')) {
                 $name = sprintf('"%s"', $name);
             }
 
             if ($format === HeaderInterface::FORMAT_ENCODED
                 && 'ASCII' !== $encoding
             ) {
-                $name = HeaderWrap::mimeEncodeValue($name, $encoding);
+                if (!empty($name)) {
+                    $name = HeaderWrap::mimeEncodeValue($name, $encoding);
+                }
+
+                if (preg_match('/^(.+)@([^@]+)$/', $email, $matches)) {
+                    $localPart = $matches[1];
+                    $hostname  = $this->idnToAscii($matches[2]);
+                    $email = sprintf('%s@%s', $localPart, $hostname);
+                }
             }
 
-            $emails[] = sprintf('%s <%s>', $name, $email);
+            if (empty($name)) {
+                $emails[] = $email;
+            } else {
+                $emails[] = sprintf('%s <%s>', $name, $email);
+            }
         }
 
         // Ensure the values are valid before sending them.

commit 6bbdb6b5b8f549fa9f87cc5a6adbb558dfefeb99
Merge: 786a1418 e00ac010
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Sun May 14 15:16:24 2017 +0300

    Merge branch 'fix-129' into develop-2.4
    
    fixing:
    https://github.com/zendframework/zend-mail/issues/129

commit ddf2e8ec39394774e753b9a44793e845134a3524
Author: Matthew Weier O'Phinney <matthew@zend.com>
Date:   Thu May 5 12:56:11 2016 -0500

    Merge branch 'hotfix/86'
    
    Close #86

diff --git a/src/Headers.php b/src/Headers.php
index c05cde1b..eac2bf9f 100644
--- a/src/Headers.php
+++ b/src/Headers.php
@@ -228,7 +228,11 @@ class Headers implements Countable, Iterator
         }
 
         if ($fieldValue === null) {
-            $this->addHeader(Header\GenericHeader::fromString($headerFieldNameOrLine));
+            $headers = $this->loadHeader($headerFieldNameOrLine);
+            $headers = is_array($headers) ? $headers : [$headers];
+            foreach ($headers as $header) {
+                $this->addHeader($header);
+            }
         } elseif (is_array($fieldValue)) {
             foreach ($fieldValue as $i) {
                 $this->addHeader(Header\GenericMultiHeader::fromString($headerFieldNameOrLine . ':' . $i));
@@ -465,6 +469,19 @@ class Headers implements Countable, Iterator
         return true;
     }
 
+    /**
+     * Create Header object from header line
+     *
+     * @param string $headerLine
+     * @return Header\HeaderInterface|Header\HeaderInterface[]
+     */
+    public function loadHeader($headerLine)
+    {
+        list($name, ) = Header\GenericHeader::splitHeaderLine($headerLine);
+        $class = $this->getPluginClassLoader()->load($name) ?: Header\GenericHeader::class;
+        return $class::fromString($headerLine);
+    }
+
     /**
      * @param $index
      * @return mixed

commit c3ac503689ffd00ac51e43c97c311e8753ecd32c
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Tue Jun 13 00:54:18 2017 +0300

    fix MessageId having double brackets
    
    this got broken from pull/86 when header lazyloading was omitted

diff --git a/src/Header/MessageId.php b/src/Header/MessageId.php
index 850757ea..03c52a75 100644
--- a/src/Header/MessageId.php
+++ b/src/Header/MessageId.php
@@ -27,7 +27,7 @@ class MessageId implements HeaderInterface
         }
 
         $header = new static();
-        $header->setId($value);
+        $header->setId(trim($value, '<>'));
 
         return $header;
     }

commit 63ac228e6f883ed8e26a7b8a02130348e2332edf
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Wed Jun 28 00:19:11 2017 +0300

    skip lazy-load for array as well
    
    refs:
    - a4a93ef0
    - ddf2e8ec
    
    this should be sent upstream, but upstream doesn't seem to respond even
    to trivial pull-requests.

diff --git a/src/Headers.php b/src/Headers.php
index eac2bf9f..d4f9a9e7 100644
--- a/src/Headers.php
+++ b/src/Headers.php
@@ -207,9 +207,6 @@ class Headers implements Countable, Iterator
     /**
      * Add a raw header line, either in name => value, or as a single string 'name: value'
      *
-     * This method allows for lazy-loading in that the parsing and instantiation of HeaderInterface object
-     * will be delayed until they are retrieved by either get() or current()
-     *
      * @throws Exception\InvalidArgumentException
      * @param  string $headerFieldNameOrLine
      * @param  string $fieldValue optional
@@ -238,7 +235,9 @@ class Headers implements Countable, Iterator
                 $this->addHeader(Header\GenericMultiHeader::fromString($headerFieldNameOrLine . ':' . $i));
             }
         } else {
-            $this->addHeader(Header\GenericHeader::fromString($headerFieldNameOrLine . ':' . $fieldValue));
+            $class = $this->getPluginClassLoader()->load($headerFieldNameOrLine) ?: Header\GenericHeader::class;
+            $header = $class::fromString($headerFieldNameOrLine . ':' . $fieldValue);
+            $this->addHeader($header);
         }
 
         return $this;

commit a95c496b4ec67953970ba366eefd29ba55ad1988
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Tue Jun 13 00:54:18 2017 +0300

    update pull/156 to trim in setId, not in constructor
    
    otherwise it could get broken from other code paths as well

diff --git a/src/Header/MessageId.php b/src/Header/MessageId.php
index 03c52a75..e1bf2ff4 100644
--- a/src/Header/MessageId.php
+++ b/src/Header/MessageId.php
@@ -27,7 +27,7 @@ class MessageId implements HeaderInterface
         }
 
         $header = new static();
-        $header->setId(trim($value, '<>'));
+        $header->setId($value);
 
         return $header;
     }
@@ -68,6 +68,8 @@ class MessageId implements HeaderInterface
     {
         if ($id === null) {
             $id = $this->createMessageId();
+        } else {
+            $id = trim($id, '<>');
         }
 
         if (! HeaderValue::isValid($id)

commit 24aeac0f3d866e64fcb20320b677b49d30fce185
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Thu Dec 28 23:00:28 2017 +0200

    unfold before calling iconv_mime_decode

diff --git a/src/Header/HeaderWrap.php b/src/Header/HeaderWrap.php
index e0be2f56..674b4f64 100644
--- a/src/Header/HeaderWrap.php
+++ b/src/Header/HeaderWrap.php
@@ -103,6 +103,13 @@ abstract class HeaderWrap
      */
     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;

commit 8bde8f75ccb1b28ec81248379bc6aa222fd24d7d
Author: Elan Ruusamäe <glen@delfi.ee>
Date:   Wed Jan 31 10:57:53 2018 +0200

    format exception message properly

diff --git a/src/Headers.php b/src/Headers.php
index d4f9a9e7..4b2c0b9c 100644
--- a/src/Headers.php
+++ b/src/Headers.php
@@ -107,7 +107,7 @@ class Headers implements Countable, Iterator
 
             // Line does not match header format!
             throw new Exception\RuntimeException(sprintf(
-                'Line "%s"does not match header format!',
+                'Line "%s" does not match header format!',
                 $line
             ));
         }