File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 9
9
10
10
/**
11
11
* A quoted literal header string part. The value of the part is stripped of CR
12
- * and LF characters, but otherwise not transformed or changed in any way .
12
+ * and LF characters, and whitespace between two adjacent MimeTokens is removed .
13
13
*
14
14
* @author Zaahid Bateson
15
15
*/
16
16
class QuotedLiteralPart extends ContainerPart
17
17
{
18
+ /**
19
+ * Strips spaces found between two adjacent MimeToken parts.
20
+ * Other whitespace is returned as-is.
21
+ *
22
+ * @param HeaderPart[] $parts
23
+ * @return HeaderPart[]
24
+ */
18
25
protected function filterIgnoredSpaces (array $ parts ) : array
19
26
{
20
- return $ parts ;
27
+ $ filtered = \array_reduce (
28
+ \array_keys ($ parts ),
29
+ function ($ carry , $ key ) use ($ parts ) {
30
+ $ cur = $ parts [$ key ];
31
+ $ last = ($ carry !== null ) ? \end ($ carry ) : null ;
32
+ $ next = (count ($ parts ) > $ key + 1 ) ? $ parts [$ key + 1 ] : null ;
33
+ if ($ last !== null && $ next !== null && $ cur ->isSpace && (
34
+ $ last ->canIgnoreSpacesAfter
35
+ && $ next ->canIgnoreSpacesBefore
36
+ && $ last instanceof MimeToken
37
+ && $ next instanceof MimeToken
38
+ )) {
39
+ return $ carry ;
40
+ }
41
+ return \array_merge ($ carry ?? [], [$ cur ]);
42
+ }
43
+ );
44
+ return $ filtered ;
21
45
}
22
46
}
Original file line number Diff line number Diff line change @@ -98,4 +98,16 @@ public function testWithQuotedHeaderEncodedValue() : void
98
98
$ ret = $ this ->consumer ->__invoke ('"=?US-ASCII?Q?value?=" ' );
99
99
$ this ->assertEquals ('value ' , $ ret [0 ]->getValue ());
100
100
}
101
+
102
+ public function testWithQuotedHeaderMultipleEncodedValues () : void
103
+ {
104
+ $ ret = $ this ->consumer ->__invoke ('"=?US-ASCII?Q?Kilgore?= =?US-ASCII?Q?Trout?=" ' );
105
+ $ this ->assertEquals ('KilgoreTrout ' , $ ret [0 ]->getValue ());
106
+ }
107
+
108
+ public function testWithQuotedHeaderMultipleEncodedValuesAndLinesBetween () : void
109
+ {
110
+ $ ret = $ this ->consumer ->__invoke ("\"=?US-ASCII?Q?Kilg?= \r\n =?US-ASCII?Q?or?= =?US-ASCII?Q?e_Trout?= \"" );
111
+ $ this ->assertEquals ('Kilgore Trout ' , $ ret [0 ]->getValue ());
112
+ }
101
113
}
Original file line number Diff line number Diff line change @@ -63,4 +63,20 @@ public function testConsumeMimeEncodedValue() : void
63
63
$ this ->assertInstanceOf (QuotedLiteralPart::class, $ ret [0 ]);
64
64
$ this ->assertEquals ('Kilgore Trout ' , $ ret [0 ]->getValue ());
65
65
}
66
+
67
+ public function testWithQuotedHeaderMultipleEncodedValues () : void
68
+ {
69
+ $ ret = $ this ->consumer ->__invoke ('=?US-ASCII?Q?Kilgore?= =?US-ASCII?Q?Trout?= ' );
70
+ $ this ->assertNotEmpty ($ ret );
71
+ $ this ->assertCount (1 , $ ret );
72
+ $ this ->assertEquals ('KilgoreTrout ' , $ ret [0 ]->getValue ());
73
+ }
74
+
75
+ public function testWithQuotedHeaderMultipleEncodedValuesAndLinesBetween () : void
76
+ {
77
+ $ ret = $ this ->consumer ->__invoke ("=?US-ASCII?Q?Kilg?= \r\n =?US-ASCII?Q?or?= =?US-ASCII?Q?e_Trout?= " );
78
+ $ this ->assertNotEmpty ($ ret );
79
+ $ this ->assertCount (1 , $ ret );
80
+ $ this ->assertEquals ('Kilgore Trout ' , $ ret [0 ]->getValue ());
81
+ }
66
82
}
You can’t perform that action at this time.
0 commit comments