blob: 55ff73730d39c32d28574f58b5a3c74d92ec139e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
//@require 'Swift/Mime/Headers/AbstractHeader.php';
//@require 'Swift/RfcComplianceException.php';
/**
* An ID MIME Header for something like Message-ID or Content-ID.
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
*/
class Swift_Mime_Headers_IdentificationHeader
extends Swift_Mime_Headers_AbstractHeader
{
/**
* The IDs used in the value of this Header.
* This may hold multiple IDs or just a single ID.
* @var string[]
* @access private
*/
private $_ids = array();
/**
* Creates a new IdentificationHeader with the given $name and $id.
* @param string $name
*/
public function __construct($name)
{
$this->setFieldName($name);
$this->initializeGrammar();
}
/**
* Get the type of Header that this instance represents.
* @return int
* @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
* @see TYPE_DATE, TYPE_ID, TYPE_PATH
*/
public function getFieldType()
{
return self::TYPE_ID;
}
/**
* Set the model for the field body.
* This method takes a string ID, or an array of IDs
* @param mixed $model
* @throws Swift_RfcComplianceException
*/
public function setFieldBodyModel($model)
{
$this->setId($model);
}
/**
* Get the model for the field body.
* This method returns an array of IDs
* @return array
*/
public function getFieldBodyModel()
{
return $this->getIds();
}
/**
* Set the ID used in the value of this header.
* @param string $id
* @throws Swift_RfcComplianceException
*/
public function setId($id)
{
return $this->setIds(array($id));
}
/**
* Get the ID used in the value of this Header.
* If multiple IDs are set only the first is returned.
* @return string
*/
public function getId()
{
if (count($this->_ids) > 0)
{
return $this->_ids[0];
}
}
/**
* Set a collection of IDs to use in the value of this Header.
* @param string[] $ids
* @throws Swift_RfcComplianceException
*/
public function setIds(array $ids)
{
$actualIds = array();
foreach ($ids as $k => $id)
{
if (preg_match(
'/^' . $this->getGrammar('id-left') . '@' .
$this->getGrammar('id-right') . '$/D',
$id
))
{
$actualIds[] = $id;
}
else
{
throw new Swift_RfcComplianceException(
'Invalid ID given <' . $id . '>'
);
}
}
$this->clearCachedValueIf($this->_ids != $actualIds);
$this->_ids = $actualIds;
}
/**
* Get the list of IDs used in this Header.
* @return string[]
*/
public function getIds()
{
return $this->_ids;
}
/**
* Get the string value of the body in this Header.
* This is not necessarily RFC 2822 compliant since folding white space will
* not be added at this stage (see {@link toString()} for that).
* @return string
* @see toString()
* @throws Swift_RfcComplianceException
*/
public function getFieldBody()
{
if (!$this->getCachedValue())
{
$angleAddrs = array();
foreach ($this->_ids as $id)
{
$angleAddrs[] = '<' . $id . '>';
}
$this->setCachedValue(implode(' ', $angleAddrs));
}
return $this->getCachedValue();
}
}
|