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\CommentPart; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Serves as a base-consumer for ID headers (like Message-ID and Content-ID). |
14
|
|
|
* |
15
|
|
|
* IdBaseConsumer handles invalidly-formatted IDs not within '<' and '>' |
16
|
|
|
* characters. Processing for validly-formatted IDs are passed on to its |
17
|
|
|
* sub-consumer, IdConsumer. |
18
|
|
|
* |
19
|
|
|
* @author Zaahid Bateson |
20
|
|
|
*/ |
21
|
|
|
class IdBaseConsumer extends AbstractConsumer |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Returns the following as sub-consumers: |
25
|
|
|
* - {@see CommentConsumer} |
26
|
|
|
* - {@see QuotedStringConsumer} |
27
|
|
|
* - {@see IdConsumer} |
28
|
|
|
* |
29
|
|
|
* @return AbstractConsumer[] the sub-consumers |
30
|
|
|
*/ |
31
|
30 |
|
protected function getSubConsumers() : array |
32
|
|
|
{ |
33
|
30 |
|
return [ |
34
|
30 |
|
$this->consumerService->getCommentConsumer(), |
35
|
30 |
|
$this->consumerService->getQuotedStringConsumer(), |
36
|
30 |
|
$this->consumerService->getIdConsumer() |
37
|
30 |
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns '\s+' as a whitespace separator. |
42
|
|
|
* |
43
|
|
|
* @return string[] an array of regex pattern matchers. |
44
|
|
|
*/ |
45
|
30 |
|
protected function getTokenSeparators() : array |
46
|
|
|
{ |
47
|
30 |
|
return ['\s+']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* IdBaseConsumer doesn't have start/end tokens, and so always returns |
52
|
|
|
* false. |
53
|
|
|
*/ |
54
|
30 |
|
protected function isEndToken(string $token) : bool |
55
|
|
|
{ |
56
|
30 |
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* IdBaseConsumer doesn't have start/end tokens, and so always returns |
61
|
|
|
* 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 LiteralPart for anything else. |
72
|
|
|
* |
73
|
|
|
* @param string $token the token |
74
|
|
|
* @param bool $isLiteral set to true if the token represents a literal - |
75
|
|
|
* e.g. an escaped token |
76
|
|
|
* @return \ZBateson\MailMimeParser\Header\IHeaderPart|null the constructed |
77
|
|
|
* header part or null if the token should be ignored |
78
|
|
|
*/ |
79
|
3 |
|
protected function getPartForToken(string $token, bool $isLiteral) |
80
|
|
|
{ |
81
|
3 |
|
if (\preg_match('/^\s+$/', $token)) { |
82
|
2 |
|
return null; |
83
|
|
|
} |
84
|
1 |
|
return $this->partFactory->newLiteralPart($token); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Overridden to filter out any found CommentPart objects. |
89
|
|
|
* |
90
|
|
|
* @param \ZBateson\MailMimeParser\Header\IHeaderPart[] $parts |
91
|
|
|
* @return \ZBateson\MailMimeParser\Header\IHeaderPart[] |
92
|
|
|
*/ |
93
|
30 |
|
protected function processParts(array $parts) : array |
94
|
|
|
{ |
95
|
30 |
|
return \array_values(\array_filter($parts, function($part) { |
|
|
|
|
96
|
30 |
|
return !(empty($part) || $part instanceof CommentPart); |
97
|
30 |
|
})); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|