|
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
|
|
|
namespace ZBateson\MailMimeParser\Header\Consumer; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Parses a single ID from an ID header. |
|
11
|
|
|
* |
|
12
|
|
|
* Begins consuming greedily on anything except a space, to allow for |
|
13
|
|
|
* incorrectly-formatted ID headers. Ends consuming only when a '>' character |
|
14
|
|
|
* is found. This means an incorrectly-formatted header can't have multiple |
|
15
|
|
|
* IDs, but one surrounded by '<>' chars may contain spaces. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Zaahid Bateson |
|
18
|
|
|
*/ |
|
19
|
|
|
class IdConsumer extends AbstractConsumer |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the following as sub-consumers: |
|
23
|
|
|
* - \ZBateson\MailMimeParser\Header\Consumer\CommentConsumer |
|
24
|
|
|
* - \ZBateson\MailMimeParser\Header\Consumer\QuotedStringConsumer |
|
25
|
|
|
* |
|
26
|
|
|
* @return AbstractConsumer[] the sub-consumers |
|
27
|
|
|
*/ |
|
28
|
3 |
|
protected function getSubConsumers() |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
3 |
|
$this->consumerService->getCommentConsumer(), |
|
32
|
3 |
|
$this->consumerService->getQuotedStringConsumer(), |
|
33
|
|
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Overridden to return patterns matching the beginning part of an ID ("<" |
|
38
|
|
|
* and ">\s*" chars). |
|
39
|
|
|
* |
|
40
|
|
|
* @return string[] the patterns |
|
41
|
|
|
*/ |
|
42
|
3 |
|
public function getTokenSeparators() |
|
43
|
|
|
{ |
|
44
|
3 |
|
return ['<', '>']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns true for '>'. |
|
49
|
|
|
*/ |
|
50
|
3 |
|
protected function isEndToken($token) |
|
51
|
|
|
{ |
|
52
|
3 |
|
return ($token === '>'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* AddressConsumer is "greedy", so this always returns true unless the token |
|
57
|
|
|
* consists only of whitespace (as it would between '>' and '<' chars). |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $token |
|
60
|
|
|
* @return boolean false |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function isStartToken($token) |
|
63
|
|
|
{ |
|
64
|
|
|
return (preg_match('/^\s+$/', $token) !== 1); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Concatenates the passed parts into a single part and returns it. |
|
69
|
|
|
* |
|
70
|
|
|
* @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts |
|
71
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[] |
|
72
|
|
|
*/ |
|
73
|
3 |
|
protected function processParts(array $parts) |
|
74
|
|
|
{ |
|
75
|
3 |
|
$strValue = ''; |
|
76
|
3 |
|
foreach ($parts as $part) { |
|
77
|
3 |
|
$strValue .= $part->getValue(); |
|
78
|
|
|
} |
|
79
|
3 |
|
return [$this->partFactory->newLiteralPart($strValue)]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|