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 the Address portion of an email address header, for an address part |
11
|
|
|
* that contains both a name and an email address, e.g. "name" <[email protected]>. |
12
|
|
|
* |
13
|
|
|
* The address portion found within the '<' and '>' chars may contain comments |
14
|
|
|
* and quoted portions. |
15
|
|
|
* |
16
|
|
|
* @author Zaahid Bateson |
17
|
|
|
*/ |
18
|
|
|
class AddressEmailConsumer extends AbstractConsumer |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Returns the following as sub-consumers: |
22
|
|
|
* - {@see AddressGroupConsumer} |
23
|
|
|
* - {@see CommentConsumer} |
24
|
|
|
* - {@see QuotedStringConsumer} |
25
|
|
|
* |
26
|
|
|
* @return AbstractConsumer[] the sub-consumers |
27
|
|
|
*/ |
28
|
98 |
|
protected function getSubConsumers() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
98 |
|
$this->consumerService->getCommentConsumer(), |
32
|
98 |
|
$this->consumerService->getQuotedStringConsumer(), |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Overridden to return patterns matching the beginning/end part of an |
38
|
|
|
* address in a name/address part ("<" and ">" chars). |
39
|
|
|
* |
40
|
|
|
* @return string[] the patterns |
41
|
|
|
*/ |
42
|
98 |
|
public function getTokenSeparators() |
43
|
|
|
{ |
44
|
98 |
|
return [ '<', '>' ]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns true for the '>' char. |
49
|
|
|
* |
50
|
|
|
* @param string $token |
51
|
|
|
* @return boolean false |
52
|
|
|
*/ |
53
|
97 |
|
protected function isEndToken($token) |
54
|
|
|
{ |
55
|
97 |
|
return ($token === '>'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns true for the '<' char. |
60
|
|
|
* |
61
|
|
|
* @param string $token |
62
|
|
|
* @return boolean false |
63
|
|
|
*/ |
64
|
94 |
|
protected function isStartToken($token) |
65
|
|
|
{ |
66
|
94 |
|
return ($token === '<'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns a single AddressPart with its 'email' portion set, so an |
71
|
|
|
* AddressConsumer can identify it and create an AddressPart with both a |
72
|
|
|
* name and email set. |
73
|
|
|
* |
74
|
|
|
* @param \ZBateson\MailMimeParser\Header\IHeaderPart[] $parts |
75
|
|
|
* @return \ZBateson\MailMimeParser\Header\IHeaderPart[]|array |
76
|
|
|
*/ |
77
|
97 |
|
protected function processParts(array $parts) |
78
|
|
|
{ |
79
|
97 |
|
$strEmail = ''; |
80
|
97 |
|
foreach ($parts as $p) { |
81
|
97 |
|
$strEmail .= $p->getValue(); |
82
|
|
|
} |
83
|
97 |
|
return [ $this->partFactory->newAddressPart('', $strEmail) ]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|