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; |
8
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Header\Consumer\ConsumerService; |
10
|
|
|
use ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer; |
11
|
|
|
use ZBateson\MailMimeParser\Header\Part\CommentPart; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Represents a Content-ID, Message-ID, In-Reply-To or Reference header. |
15
|
|
|
* |
16
|
|
|
* For a multi-id header like In-Reply-To or Reference, all IDs can be retrieved |
17
|
|
|
* by calling 'getIds()'. Otherwise, to retrieve the first (or only) ID call |
18
|
|
|
* 'getValue()'. |
19
|
|
|
* |
20
|
|
|
* @author Zaahid Bateson |
21
|
|
|
*/ |
22
|
|
|
class IdHeader extends GenericHeader |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string[] an array of ids found. |
26
|
|
|
*/ |
27
|
|
|
protected $ids = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns an IdBaseConsumer. |
31
|
|
|
* |
32
|
|
|
* @param ConsumerService $consumerService |
33
|
|
|
* @return \ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer |
34
|
|
|
*/ |
35
|
6 |
|
protected function getConsumer(ConsumerService $consumerService) |
36
|
|
|
{ |
37
|
6 |
|
return $consumerService->getIdBaseConsumer(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Overridden to extract all IDs into ids array. |
42
|
|
|
* |
43
|
|
|
* @param AbstractConsumer $consumer |
44
|
|
|
*/ |
45
|
6 |
|
protected function setParseHeaderValue(AbstractConsumer $consumer) |
46
|
|
|
{ |
47
|
6 |
|
parent::setParseHeaderValue($consumer); |
48
|
6 |
|
foreach ($this->parts as $part) { |
49
|
5 |
|
if (!($part instanceof CommentPart)) { |
50
|
5 |
|
$this->ids[] = $part->getValue(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
6 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the first parsed ID or null if none exist. |
57
|
|
|
* |
58
|
|
|
* @return string|null |
59
|
|
|
*/ |
60
|
6 |
|
public function getValue() |
61
|
|
|
{ |
62
|
6 |
|
if (!empty($this->ids)) { |
63
|
5 |
|
return $this->ids[0]; |
64
|
|
|
} |
65
|
1 |
|
return null; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns all IDs parsed for a multi-id header like Reference or |
70
|
|
|
* In-Reply-To. |
71
|
|
|
* |
72
|
|
|
* @return string[] |
73
|
|
|
*/ |
74
|
4 |
|
public function getIds() |
75
|
|
|
{ |
76
|
4 |
|
return $this->ids; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|