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\Consumer; |
9
|
|
|
|
10
|
|
|
use Iterator; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
use ZBateson\MailMimeParser\Header\IHeaderPart; |
13
|
|
|
use ZBateson\MailMimeParser\Header\Part\MimeToken; |
14
|
|
|
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Extends AbstractGenericConsumerService to use a MimeTokenPartFactory, and |
18
|
|
|
* to preserve all whitespace and escape sequences as-is (unlike other headers |
19
|
|
|
* subject headers don't have escape chars such as '\\' for a backslash). |
20
|
|
|
* |
21
|
|
|
* SubjectConsumerService doesn't define any sub-consumers. |
22
|
|
|
* |
23
|
|
|
* @author Zaahid Bateson |
24
|
|
|
*/ |
25
|
|
|
class SubjectConsumerService extends AbstractGenericConsumerService |
26
|
|
|
{ |
27
|
3 |
|
public function __construct(LoggerInterface $logger, MimeTokenPartFactory $partFactory) |
28
|
|
|
{ |
29
|
3 |
|
parent::__construct($logger, $partFactory); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Overridden to preserve whitespace. |
34
|
|
|
* |
35
|
|
|
* Whitespace between two words is preserved unless the whitespace begins |
36
|
|
|
* with a newline (\n or \r\n), in which case the entire string of |
37
|
|
|
* whitespace is discarded, and a single space ' ' character is used in its |
38
|
|
|
* place. |
39
|
|
|
*/ |
40
|
98 |
|
protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart |
41
|
|
|
{ |
42
|
98 |
|
if (\preg_match('/' . MimeToken::MIME_PART_PATTERN . '/', $token)) { |
43
|
29 |
|
return $this->partFactory->newMimeToken($token); |
44
|
|
|
} |
45
|
77 |
|
return $this->partFactory->newSubjectToken($token); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns an array of \ZBateson\MailMimeParser\Header\Part\HeaderPart for |
50
|
|
|
* the current token on the iterator. |
51
|
|
|
* |
52
|
|
|
* Overridden from AbstractConsumerService to remove special filtering for |
53
|
|
|
* backslash escaping, which also seems to not apply to Subject headers at |
54
|
|
|
* least in ThunderBird's implementation. |
55
|
|
|
* |
56
|
|
|
* @return IHeaderPart[] |
57
|
|
|
*/ |
58
|
98 |
|
protected function getTokenParts(Iterator $tokens) : array |
59
|
|
|
{ |
60
|
98 |
|
return $this->getConsumerTokenParts($tokens); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|