zbateson /
mail-mime-parser
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the ZBateson\MailMimeParser project. |
||
| 4 | * |
||
| 5 | * @license http://opensource.org/licenses/bsd-license.php BSD |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace ZBateson\MailMimeParser\Header\Part; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * A quoted literal header string part. The value of the part is stripped of CR |
||
| 12 | * and LF characters, and whitespace between two adjacent MimeTokens is removed. |
||
| 13 | * |
||
| 14 | * @author Zaahid Bateson |
||
| 15 | */ |
||
| 16 | class QuotedLiteralPart extends ContainerPart |
||
| 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 | */ |
||
| 25 | 102 | protected function filterIgnoredSpaces(array $parts) : array |
|
| 26 | { |
||
| 27 | 102 | $filtered = \array_reduce( |
|
| 28 | 102 | \array_keys($parts), |
|
| 29 | 102 | function($carry, $key) use ($parts) { |
|
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 30 | 102 | $cur = $parts[$key]; |
|
| 31 | 102 | $last = ($carry !== null) ? \end($carry) : null; |
|
| 32 | 102 | $next = (count($parts) > $key + 1) ? $parts[$key + 1] : null; |
|
| 33 | 102 | if ($last !== null && $next !== null && $cur->isSpace && ( |
|
| 34 | 102 | $last->canIgnoreSpacesAfter |
|
| 35 | 102 | && $next->canIgnoreSpacesBefore |
|
| 36 | 102 | && $last instanceof MimeToken |
|
| 37 | 102 | && $next instanceof MimeToken |
|
| 38 | )) { |
||
| 39 | return $carry; |
||
| 40 | } |
||
| 41 | 102 | return \array_merge($carry ?? [], [$cur]); |
|
| 42 | 102 | } |
|
| 43 | 102 | ); |
|
| 44 | 102 | return $filtered; |
|
| 45 | } |
||
| 46 | } |
||
| 47 |