|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of SwiftMailer. |
|
5
|
|
|
* (c) 2004-2009 Chris Corbyn |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A Path Header in Swift Mailer, such a Return-Path. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Chris Corbyn |
|
15
|
|
|
*/ |
|
16
|
|
|
class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The address in this Header (if specified). |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_address; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The strict EmailValidator |
|
27
|
|
|
* |
|
28
|
|
|
* @var Swift_EmailValidatorBridge |
|
29
|
|
|
*/ |
|
30
|
|
|
private $_emailValidator; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Creates a new PathHeader with the given $name. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $name |
|
36
|
|
|
* @param Swift_EmailValidatorBridge $emailValidator |
|
37
|
|
|
*/ |
|
38
|
11 |
|
public function __construct($name, $emailValidator) |
|
39
|
|
|
{ |
|
40
|
11 |
|
$this->setFieldName($name); |
|
41
|
11 |
|
$this->_emailValidator = $emailValidator; |
|
42
|
11 |
|
parent::__construct(); |
|
43
|
11 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the type of Header that this instance represents. |
|
47
|
|
|
* |
|
48
|
|
|
* @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
49
|
|
|
* @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
50
|
|
|
* |
|
51
|
|
|
* @return int |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function getFieldType() |
|
54
|
|
|
{ |
|
55
|
1 |
|
return self::TYPE_PATH; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Set the model for the field body. |
|
60
|
|
|
* This method takes a string for an address. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $model |
|
63
|
|
|
* |
|
64
|
|
|
* @throws Swift_RfcComplianceException |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function setFieldBodyModel($model) |
|
67
|
|
|
{ |
|
68
|
2 |
|
$this->setAddress($model); |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the model for the field body. |
|
73
|
|
|
* This method returns a string email address. |
|
74
|
|
|
* |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function getFieldBodyModel() |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->getAddress(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Set the Address which should appear in this Header. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $address |
|
86
|
|
|
* |
|
87
|
|
|
* @throws Swift_RfcComplianceException |
|
88
|
|
|
*/ |
|
89
|
8 |
|
public function setAddress($address) |
|
90
|
|
|
{ |
|
91
|
8 |
|
if (null === $address) { |
|
92
|
|
|
$this->_address = null; |
|
93
|
8 |
|
} elseif ('' === $address) { |
|
94
|
1 |
|
$this->_address = ''; |
|
95
|
|
|
} else { |
|
96
|
7 |
|
$this->_assertValidAddress($address); |
|
97
|
6 |
|
$this->_address = $address; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
7 |
|
$this->setCachedValue(null); |
|
101
|
7 |
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get the address which is used in this Header (if any). |
|
105
|
|
|
* |
|
106
|
|
|
* Null is returned if no address is set. |
|
107
|
|
|
* |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
4 |
|
public function getAddress() |
|
111
|
|
|
{ |
|
112
|
4 |
|
return $this->_address; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get the string value of the body in this Header. |
|
117
|
|
|
* |
|
118
|
|
|
* This is not necessarily RFC 2822 compliant since folding white space will |
|
119
|
|
|
* not be added at this stage (see {@link toString()} for that). |
|
120
|
|
|
* |
|
121
|
|
|
* @see toString() |
|
122
|
|
|
* |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
3 |
|
public function getFieldBody() |
|
126
|
|
|
{ |
|
127
|
3 |
|
if (!$this->getCachedValue()) { |
|
|
|
|
|
|
128
|
3 |
|
if (isset($this->_address)) { |
|
129
|
3 |
|
$this->setCachedValue('<' . $this->_address . '>'); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
3 |
|
return $this->getCachedValue(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Throws an Exception if the address passed does not comply with RFC 2822. |
|
138
|
|
|
* |
|
139
|
|
|
* @param string $address |
|
140
|
|
|
* |
|
141
|
|
|
* @throws Swift_RfcComplianceException If address is invalid |
|
142
|
|
|
*/ |
|
143
|
7 |
|
private function _assertValidAddress($address) |
|
144
|
|
|
{ |
|
145
|
7 |
|
if ($this->_emailValidator->isValidWrapper($address) === false) { |
|
146
|
1 |
|
throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.'); |
|
147
|
|
|
} |
|
148
|
6 |
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.