|
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 ZBateson\MailMimeParser\Header\Part\HeaderPartFactory; |
|
11
|
|
|
use ZBateson\MailMimeParser\Header\IHeaderPart; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Serves as a base-consumer for ID headers (like Message-ID and Content-ID). |
|
15
|
|
|
* |
|
16
|
|
|
* IdBaseConsumerService handles invalidly-formatted IDs not within '<' and '>' |
|
17
|
|
|
* characters. Processing for validly-formatted IDs are passed on to its |
|
18
|
|
|
* sub-consumer, IdConsumer. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Zaahid Bateson |
|
21
|
|
|
*/ |
|
22
|
|
|
class IdBaseConsumerService extends AbstractConsumerService |
|
23
|
|
|
{ |
|
24
|
3 |
|
public function __construct( |
|
25
|
|
|
HeaderPartFactory $partFactory, |
|
26
|
|
|
CommentConsumerService $commentConsumerService, |
|
27
|
|
|
QuotedStringConsumerService $quotedStringConsumerService, |
|
28
|
|
|
IdConsumerService $idConsumerService |
|
29
|
|
|
) { |
|
30
|
3 |
|
parent::__construct( |
|
31
|
3 |
|
$partFactory, |
|
32
|
3 |
|
[ |
|
33
|
3 |
|
$commentConsumerService, |
|
34
|
3 |
|
$quotedStringConsumerService, |
|
35
|
3 |
|
$idConsumerService |
|
36
|
3 |
|
] |
|
37
|
3 |
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns '\s+' as a whitespace separator. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string[] an array of regex pattern matchers. |
|
44
|
|
|
*/ |
|
45
|
4 |
|
protected function getTokenSeparators() : array |
|
46
|
|
|
{ |
|
47
|
4 |
|
return ['\s+']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* IdBaseConsumerService doesn't have start/end tokens, and so always |
|
52
|
|
|
* returns false. |
|
53
|
|
|
*/ |
|
54
|
85 |
|
protected function isEndToken(string $token) : bool |
|
55
|
|
|
{ |
|
56
|
85 |
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* IdBaseConsumerService doesn't have start/end tokens, and so always |
|
61
|
|
|
* returns false. |
|
62
|
|
|
* |
|
63
|
|
|
* @codeCoverageIgnore |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function isStartToken(string $token) : bool |
|
66
|
|
|
{ |
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns null for whitespace, and |
|
72
|
|
|
* {@see ZBateson\MailMimeParser\Header\Part\LiteralPart} for anything else. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $token the token |
|
75
|
|
|
* @param bool $isLiteral set to true if the token represents a literal - |
|
76
|
|
|
* e.g. an escaped token |
|
77
|
|
|
* @return ?IHeaderPart The constructed header part or null if the token |
|
78
|
|
|
* should be ignored |
|
79
|
|
|
*/ |
|
80
|
3 |
|
protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart |
|
81
|
|
|
{ |
|
82
|
3 |
|
if (\preg_match('/^\s+$/', $token)) { |
|
83
|
2 |
|
return null; |
|
84
|
|
|
} |
|
85
|
1 |
|
return $this->partFactory->newLiteralPart($token); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|