|
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
|
|
|
* The default email message class. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Chris Corbyn |
|
15
|
|
|
*/ |
|
16
|
|
|
class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime_Message |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
const PRIORITY_HIGHEST = 1; |
|
19
|
|
|
const PRIORITY_HIGH = 2; |
|
20
|
|
|
const PRIORITY_NORMAL = 3; |
|
21
|
|
|
const PRIORITY_LOW = 4; |
|
22
|
|
|
const PRIORITY_LOWEST = 5; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new SimpleMessage with $headers, $encoder and $cache. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Swift_Mime_HeaderSet $headers |
|
28
|
|
|
* @param Swift_Mime_ContentEncoder $encoder |
|
29
|
|
|
* @param Swift_KeyCache $cache |
|
30
|
|
|
* @param Swift_IdGenerator $idGenerator |
|
31
|
|
|
* @param string $charset |
|
32
|
|
|
*/ |
|
33
|
258 |
|
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) |
|
34
|
|
|
{ |
|
35
|
258 |
|
parent::__construct($headers, $encoder, $cache, $idGenerator, $charset); |
|
36
|
258 |
|
$this->getHeaders()->defineOrdering( |
|
37
|
|
|
array( |
|
38
|
258 |
|
'Return-Path', |
|
39
|
258 |
|
'Received', |
|
40
|
258 |
|
'DKIM-Signature', |
|
41
|
258 |
|
'DomainKey-Signature', |
|
42
|
258 |
|
'Sender', |
|
43
|
258 |
|
'Message-ID', |
|
44
|
258 |
|
'Date', |
|
45
|
258 |
|
'Subject', |
|
46
|
258 |
|
'From', |
|
47
|
258 |
|
'Reply-To', |
|
48
|
258 |
|
'To', |
|
49
|
258 |
|
'Cc', |
|
50
|
258 |
|
'Bcc', |
|
51
|
258 |
|
'MIME-Version', |
|
52
|
258 |
|
'Content-Type', |
|
53
|
258 |
|
'Content-Transfer-Encoding', |
|
54
|
|
|
) |
|
55
|
258 |
|
); |
|
56
|
258 |
|
$this->getHeaders()->setAlwaysDisplayed(array('Date', 'Message-ID', 'From')); |
|
57
|
258 |
|
$this->getHeaders()->addTextHeader('MIME-Version', '1.0'); |
|
58
|
258 |
|
$this->setDate(time()); |
|
59
|
258 |
|
$this->setId($this->getId()); |
|
60
|
258 |
|
$this->getHeaders()->addMailboxHeader('From'); |
|
61
|
258 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Always returns {@link LEVEL_TOP} for a message instance. |
|
65
|
|
|
* |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
20 |
|
public function getNestingLevel() |
|
69
|
|
|
{ |
|
70
|
20 |
|
return self::LEVEL_TOP; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Set the subject of this message. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $subject |
|
77
|
|
|
* |
|
78
|
|
|
* @return $this |
|
79
|
|
|
*/ |
|
80
|
148 |
|
public function setSubject($subject) |
|
81
|
|
|
{ |
|
82
|
148 |
|
if (!$this->_setHeaderFieldModel('Subject', $subject)) { |
|
83
|
147 |
|
$this->getHeaders()->addTextHeader('Subject', $subject); |
|
84
|
147 |
|
} |
|
85
|
|
|
|
|
86
|
148 |
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the subject of this message. |
|
91
|
|
|
* |
|
92
|
|
|
* @return null|string |
|
93
|
|
|
*/ |
|
94
|
1 |
|
public function getSubject() |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->_getHeaderFieldModel('Subject'); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Set the date at which this message was created. |
|
101
|
|
|
* |
|
102
|
|
|
* @param int $date |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
258 |
|
public function setDate($date) |
|
107
|
|
|
{ |
|
108
|
258 |
|
if (!$this->_setHeaderFieldModel('Date', $date)) { |
|
109
|
256 |
|
$this->getHeaders()->addDateHeader('Date', $date); |
|
110
|
256 |
|
} |
|
111
|
|
|
|
|
112
|
258 |
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get the date at which this message was created. |
|
117
|
|
|
* |
|
118
|
|
|
* @return null|string |
|
119
|
|
|
*/ |
|
120
|
113 |
|
public function getDate() |
|
121
|
|
|
{ |
|
122
|
113 |
|
return $this->_getHeaderFieldModel('Date'); |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set the return-path (the bounce address) of this message. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $address |
|
129
|
|
|
* |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
48 |
|
public function setReturnPath($address) |
|
133
|
|
|
{ |
|
134
|
48 |
|
if (!$this->_setHeaderFieldModel('Return-Path', $address)) { |
|
135
|
47 |
|
$this->getHeaders()->addPathHeader('Return-Path', $address); |
|
136
|
47 |
|
} |
|
137
|
|
|
|
|
138
|
48 |
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get the return-path (bounce address) of this message. |
|
143
|
|
|
* |
|
144
|
|
|
* @return null|string |
|
145
|
|
|
*/ |
|
146
|
5 |
|
public function getReturnPath() |
|
147
|
|
|
{ |
|
148
|
5 |
|
return $this->_getHeaderFieldModel('Return-Path'); |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Set the sender of this message. |
|
153
|
|
|
* |
|
154
|
|
|
* This does not override the From field, but it has a higher significance. |
|
155
|
|
|
* |
|
156
|
|
|
* @param string|array $address |
|
157
|
|
|
* @param string $name optional |
|
158
|
|
|
* |
|
159
|
|
|
* @return $this |
|
160
|
|
|
*/ |
|
161
|
12 |
View Code Duplication |
public function setSender($address, $name = null) |
|
|
|
|
|
|
162
|
|
|
{ |
|
163
|
12 |
|
if (!is_array($address) && isset($name)) { |
|
164
|
1 |
|
$address = array($address => $name); |
|
165
|
1 |
|
} |
|
166
|
|
|
|
|
167
|
12 |
|
if (!$this->_setHeaderFieldModel('Sender', (array)$address)) { |
|
168
|
11 |
|
$this->getHeaders()->addMailboxHeader('Sender', (array)$address); |
|
169
|
11 |
|
} |
|
170
|
|
|
|
|
171
|
12 |
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Get the sender of this message. |
|
176
|
|
|
* |
|
177
|
|
|
* @return null|string |
|
178
|
|
|
*/ |
|
179
|
5 |
|
public function getSender() |
|
180
|
|
|
{ |
|
181
|
5 |
|
return $this->_getHeaderFieldModel('Sender'); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Add a From: address to this message. |
|
186
|
|
|
* |
|
187
|
|
|
* If $name is passed this name will be associated with the address. |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $address |
|
190
|
|
|
* @param string $name optional |
|
191
|
|
|
* |
|
192
|
|
|
* @return $this |
|
193
|
|
|
*/ |
|
194
|
1 |
|
public function addFrom($address, $name = null) |
|
195
|
|
|
{ |
|
196
|
1 |
|
$current = $this->getFrom(); |
|
197
|
1 |
|
$current[$address] = $name; |
|
198
|
|
|
|
|
199
|
1 |
|
return $this->setFrom($current); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Set the from address of this message. |
|
204
|
|
|
* |
|
205
|
|
|
* You may pass an array of addresses if this message is from multiple people. |
|
206
|
|
|
* |
|
207
|
|
|
* If $name is passed and the first parameter is a string, this name will be |
|
208
|
|
|
* associated with the address. |
|
209
|
|
|
* |
|
210
|
|
|
* @param string|array $addresses |
|
211
|
|
|
* @param string $name optional |
|
212
|
|
|
* |
|
213
|
|
|
* @return $this |
|
214
|
|
|
*/ |
|
215
|
110 |
View Code Duplication |
public function setFrom($addresses, $name = null) |
|
|
|
|
|
|
216
|
|
|
{ |
|
217
|
110 |
|
if (!is_array($addresses) && isset($name)) { |
|
218
|
1 |
|
$addresses = array($addresses => $name); |
|
219
|
1 |
|
} |
|
220
|
|
|
|
|
221
|
110 |
|
if (!$this->_setHeaderFieldModel('From', (array)$addresses)) { |
|
222
|
3 |
|
$this->getHeaders()->addMailboxHeader('From', (array)$addresses); |
|
223
|
3 |
|
} |
|
224
|
|
|
|
|
225
|
110 |
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Get the from address of this message. |
|
230
|
|
|
* |
|
231
|
|
|
* @return null|string[] |
|
232
|
|
|
*/ |
|
233
|
6 |
|
public function getFrom() |
|
234
|
|
|
{ |
|
235
|
6 |
|
return $this->_getHeaderFieldModel('From'); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Add a Reply-To: address to this message. |
|
240
|
|
|
* |
|
241
|
|
|
* If $name is passed this name will be associated with the address. |
|
242
|
|
|
* |
|
243
|
|
|
* @param string $address |
|
244
|
|
|
* @param string $name optional |
|
245
|
|
|
* |
|
246
|
|
|
* @return $this |
|
247
|
|
|
*/ |
|
248
|
1 |
|
public function addReplyTo($address, $name = null) |
|
249
|
|
|
{ |
|
250
|
1 |
|
$current = $this->getReplyTo(); |
|
251
|
1 |
|
$current[$address] = $name; |
|
252
|
|
|
|
|
253
|
1 |
|
return $this->setReplyTo($current); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Set the reply-to address of this message. |
|
258
|
|
|
* |
|
259
|
|
|
* You may pass an array of addresses if replies will go to multiple people. |
|
260
|
|
|
* |
|
261
|
|
|
* If $name is passed and the first parameter is a string, this name will be |
|
262
|
|
|
* associated with the address. |
|
263
|
|
|
* |
|
264
|
|
|
* @param mixed $addresses |
|
265
|
|
|
* @param string $name optional |
|
266
|
|
|
* |
|
267
|
|
|
* @return $this |
|
268
|
|
|
*/ |
|
269
|
29 |
View Code Duplication |
public function setReplyTo($addresses, $name = null) |
|
|
|
|
|
|
270
|
|
|
{ |
|
271
|
29 |
|
if (!is_array($addresses) && isset($name)) { |
|
272
|
1 |
|
$addresses = array($addresses => $name); |
|
273
|
1 |
|
} |
|
274
|
|
|
|
|
275
|
29 |
|
if (!$this->_setHeaderFieldModel('Reply-To', (array)$addresses)) { |
|
276
|
27 |
|
$this->getHeaders()->addMailboxHeader('Reply-To', (array)$addresses); |
|
277
|
27 |
|
} |
|
278
|
|
|
|
|
279
|
29 |
|
return $this; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Get the reply-to address of this message. |
|
284
|
|
|
* |
|
285
|
|
|
* @return null|string[] |
|
286
|
|
|
*/ |
|
287
|
2 |
|
public function getReplyTo() |
|
288
|
|
|
{ |
|
289
|
2 |
|
return $this->_getHeaderFieldModel('Reply-To'); |
|
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Add a To: address to this message. |
|
294
|
|
|
* |
|
295
|
|
|
* If $name is passed this name will be associated with the address. |
|
296
|
|
|
* |
|
297
|
|
|
* @param string $address |
|
298
|
|
|
* @param string $name optional |
|
299
|
|
|
* |
|
300
|
|
|
* @return $this |
|
301
|
|
|
*/ |
|
302
|
5 |
|
public function addTo($address, $name = null) |
|
303
|
|
|
{ |
|
304
|
5 |
|
$current = $this->getTo(); |
|
305
|
5 |
|
$current[$address] = $name; |
|
306
|
|
|
|
|
307
|
5 |
|
return $this->setTo($current); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* Set the to addresses of this message. |
|
312
|
|
|
* |
|
313
|
|
|
* If multiple recipients will receive the message an array should be used. |
|
314
|
|
|
* Example: array('[email protected]', '[email protected]' => 'A name') |
|
315
|
|
|
* |
|
316
|
|
|
* If $name is passed and the first parameter is a string, this name will be |
|
317
|
|
|
* associated with the address. |
|
318
|
|
|
* |
|
319
|
|
|
* @param mixed $addresses |
|
320
|
|
|
* @param string $name optional |
|
321
|
|
|
* |
|
322
|
|
|
* @return $this |
|
323
|
|
|
*/ |
|
324
|
50 |
View Code Duplication |
public function setTo($addresses, $name = null) |
|
|
|
|
|
|
325
|
|
|
{ |
|
326
|
50 |
|
if (!is_array($addresses) && isset($name)) { |
|
327
|
1 |
|
$addresses = array($addresses => $name); |
|
328
|
1 |
|
} |
|
329
|
|
|
|
|
330
|
50 |
|
if (!$this->_setHeaderFieldModel('To', (array)$addresses)) { |
|
331
|
48 |
|
$this->getHeaders()->addMailboxHeader('To', (array)$addresses); |
|
332
|
48 |
|
} |
|
333
|
|
|
|
|
334
|
50 |
|
return $this; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* Get the To addresses of this message. |
|
339
|
|
|
* |
|
340
|
|
|
* @return null|string[] |
|
341
|
|
|
*/ |
|
342
|
11 |
|
public function getTo() |
|
343
|
|
|
{ |
|
344
|
11 |
|
return $this->_getHeaderFieldModel('To'); |
|
|
|
|
|
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* Add a Cc: address to this message. |
|
349
|
|
|
* |
|
350
|
|
|
* If $name is passed this name will be associated with the address. |
|
351
|
|
|
* |
|
352
|
|
|
* @param string $address |
|
353
|
|
|
* @param string $name optional |
|
354
|
|
|
* |
|
355
|
|
|
* @return $this |
|
356
|
|
|
*/ |
|
357
|
1 |
|
public function addCc($address, $name = null) |
|
358
|
|
|
{ |
|
359
|
1 |
|
$current = $this->getCc(); |
|
360
|
1 |
|
$current[$address] = $name; |
|
361
|
|
|
|
|
362
|
1 |
|
return $this->setCc($current); |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* Set the Cc addresses of this message. |
|
367
|
|
|
* |
|
368
|
|
|
* If $name is passed and the first parameter is a string, this name will be |
|
369
|
|
|
* associated with the address. |
|
370
|
|
|
* |
|
371
|
|
|
* @param string[]|string $addresses |
|
372
|
|
|
* @param string $name optional |
|
373
|
|
|
* |
|
374
|
|
|
* @return $this |
|
375
|
|
|
*/ |
|
376
|
25 |
View Code Duplication |
public function setCc($addresses, $name = null) |
|
|
|
|
|
|
377
|
|
|
{ |
|
378
|
25 |
|
if (!is_array($addresses) && isset($name)) { |
|
379
|
1 |
|
$addresses = array($addresses => $name); |
|
380
|
1 |
|
} |
|
381
|
|
|
|
|
382
|
25 |
|
if (!$this->_setHeaderFieldModel('Cc', (array)$addresses)) { |
|
383
|
23 |
|
$this->getHeaders()->addMailboxHeader('Cc', (array)$addresses); |
|
384
|
23 |
|
} |
|
385
|
|
|
|
|
386
|
25 |
|
return $this; |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Get the Cc address of this message. |
|
391
|
|
|
* |
|
392
|
|
|
* @return null|string[] |
|
393
|
|
|
*/ |
|
394
|
10 |
|
public function getCc() |
|
395
|
|
|
{ |
|
396
|
10 |
|
return $this->_getHeaderFieldModel('Cc'); |
|
|
|
|
|
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Add a Bcc: address to this message. |
|
401
|
|
|
* |
|
402
|
|
|
* If $name is passed this name will be associated with the address. |
|
403
|
|
|
* |
|
404
|
|
|
* @param string $address |
|
405
|
|
|
* @param string $name optional |
|
406
|
|
|
* |
|
407
|
|
|
* @return $this |
|
408
|
|
|
*/ |
|
409
|
1 |
|
public function addBcc($address, $name = null) |
|
410
|
|
|
{ |
|
411
|
1 |
|
$current = $this->getBcc(); |
|
412
|
1 |
|
$current[$address] = $name; |
|
413
|
|
|
|
|
414
|
1 |
|
return $this->setBcc($current); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* Set the Bcc addresses of this message. |
|
419
|
|
|
* |
|
420
|
|
|
* If $name is passed and the first parameter is a string, this name will be |
|
421
|
|
|
* associated with the address. |
|
422
|
|
|
* |
|
423
|
|
|
* @param mixed $addresses |
|
424
|
|
|
* @param string $name optional |
|
425
|
|
|
* |
|
426
|
|
|
* @return $this |
|
427
|
|
|
*/ |
|
428
|
19 |
View Code Duplication |
public function setBcc($addresses, $name = null) |
|
|
|
|
|
|
429
|
|
|
{ |
|
430
|
19 |
|
if (!is_array($addresses) && isset($name)) { |
|
431
|
1 |
|
$addresses = array($addresses => $name); |
|
432
|
1 |
|
} |
|
433
|
|
|
|
|
434
|
19 |
|
if (!$this->_setHeaderFieldModel('Bcc', (array)$addresses)) { |
|
435
|
17 |
|
$this->getHeaders()->addMailboxHeader('Bcc', (array)$addresses); |
|
436
|
17 |
|
} |
|
437
|
|
|
|
|
438
|
19 |
|
return $this; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Get the Bcc addresses of this message. |
|
443
|
|
|
* |
|
444
|
|
|
* @return null|string[] |
|
445
|
|
|
*/ |
|
446
|
10 |
|
public function getBcc() |
|
447
|
|
|
{ |
|
448
|
10 |
|
return $this->_getHeaderFieldModel('Bcc'); |
|
|
|
|
|
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* Set the priority of this message. |
|
453
|
|
|
* |
|
454
|
|
|
* The value is an integer where 1 is the highest priority and 5 is the lowest. |
|
455
|
|
|
* |
|
456
|
|
|
* @param int $priority |
|
457
|
|
|
* |
|
458
|
|
|
* @return $this |
|
459
|
|
|
*/ |
|
460
|
3 |
|
public function setPriority($priority) |
|
461
|
|
|
{ |
|
462
|
|
|
$priorityMap = array( |
|
463
|
3 |
|
self::PRIORITY_HIGHEST => 'Highest', |
|
464
|
3 |
|
self::PRIORITY_HIGH => 'High', |
|
465
|
3 |
|
self::PRIORITY_NORMAL => 'Normal', |
|
466
|
3 |
|
self::PRIORITY_LOW => 'Low', |
|
467
|
3 |
|
self::PRIORITY_LOWEST => 'Lowest', |
|
468
|
3 |
|
); |
|
469
|
3 |
|
$pMapKeys = array_keys($priorityMap); |
|
470
|
3 |
|
if ($priority > max($pMapKeys)) { |
|
471
|
|
|
$priority = max($pMapKeys); |
|
472
|
3 |
|
} elseif ($priority < min($pMapKeys)) { |
|
473
|
|
|
$priority = min($pMapKeys); |
|
474
|
|
|
} |
|
475
|
3 |
|
if (!$this->_setHeaderFieldModel('X-Priority', |
|
476
|
3 |
|
sprintf('%d (%s)', $priority, $priorityMap[$priority])) |
|
477
|
3 |
|
) { |
|
478
|
2 |
|
$this->getHeaders()->addTextHeader('X-Priority', |
|
479
|
2 |
|
sprintf('%d (%s)', $priority, $priorityMap[$priority])); |
|
480
|
2 |
|
} |
|
481
|
|
|
|
|
482
|
3 |
|
return $this; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
/** |
|
486
|
|
|
* Get the priority of this message. |
|
487
|
|
|
* |
|
488
|
|
|
* The returned value is an integer where 1 is the highest priority and 5 |
|
489
|
|
|
* is the lowest. |
|
490
|
|
|
* |
|
491
|
|
|
* @return int |
|
492
|
|
|
*/ |
|
493
|
1 |
|
public function getPriority() |
|
494
|
|
|
{ |
|
495
|
|
|
/** @noinspection PrintfScanfArgumentsInspection */ |
|
496
|
1 |
|
list($priority) = sscanf($this->_getHeaderFieldModel('X-Priority'), '%[1-5]'); |
|
497
|
|
|
|
|
498
|
1 |
|
return isset($priority) ? $priority : 3; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* Ask for a delivery receipt from the recipient to be sent to $addresses. |
|
503
|
|
|
* |
|
504
|
|
|
* @param array $addresses |
|
505
|
|
|
* |
|
506
|
|
|
* @return $this |
|
507
|
|
|
*/ |
|
508
|
3 |
|
public function setReadReceiptTo($addresses) |
|
509
|
|
|
{ |
|
510
|
3 |
|
if (!$this->_setHeaderFieldModel('Disposition-Notification-To', $addresses)) { |
|
511
|
2 |
|
$this->getHeaders()->addMailboxHeader('Disposition-Notification-To', $addresses); |
|
512
|
2 |
|
} |
|
513
|
|
|
|
|
514
|
3 |
|
return $this; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* Get the addresses to which a read-receipt will be sent. |
|
519
|
|
|
* |
|
520
|
|
|
* @return null|string[] |
|
521
|
|
|
*/ |
|
522
|
1 |
|
public function getReadReceiptTo() |
|
523
|
|
|
{ |
|
524
|
1 |
|
return $this->_getHeaderFieldModel('Disposition-Notification-To'); |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* Attach a {@link Swift_Mime_MimeEntity} such as an Attachment or MimePart. |
|
529
|
|
|
* |
|
530
|
|
|
* @param Swift_Mime_MimeEntity $entity |
|
531
|
|
|
* |
|
532
|
|
|
* @return $this |
|
533
|
|
|
*/ |
|
534
|
51 |
|
public function attach(Swift_Mime_MimeEntity $entity) |
|
535
|
|
|
{ |
|
536
|
51 |
|
$this->setChildren(array_merge($this->getChildren(), array($entity))); |
|
537
|
|
|
|
|
538
|
51 |
|
return $this; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
/** |
|
542
|
|
|
* Remove an already attached entity. |
|
543
|
|
|
* |
|
544
|
|
|
* @param Swift_Mime_MimeEntity $entity |
|
545
|
|
|
* |
|
546
|
|
|
* @return $this |
|
547
|
|
|
*/ |
|
548
|
8 |
|
public function detach(Swift_Mime_MimeEntity $entity) |
|
549
|
|
|
{ |
|
550
|
8 |
|
$newChildren = array(); |
|
551
|
8 |
|
foreach ($this->getChildren() as $child) { |
|
552
|
8 |
|
if ($entity !== $child) { |
|
553
|
7 |
|
$newChildren[] = $child; |
|
554
|
7 |
|
} |
|
555
|
8 |
|
} |
|
556
|
8 |
|
$this->setChildren($newChildren); |
|
557
|
|
|
|
|
558
|
8 |
|
return $this; |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
/** |
|
562
|
|
|
* Attach a {@link Swift_Mime_MimeEntity} and return it's CID source. |
|
563
|
|
|
* This method should be used when embedding images or other data in a message. |
|
564
|
|
|
* |
|
565
|
|
|
* @param Swift_Mime_MimeEntity $entity |
|
566
|
|
|
* |
|
567
|
|
|
* @return string |
|
568
|
|
|
*/ |
|
569
|
9 |
|
public function embed(Swift_Mime_MimeEntity $entity) |
|
570
|
|
|
{ |
|
571
|
9 |
|
$this->attach($entity); |
|
572
|
|
|
|
|
573
|
9 |
|
return 'cid:' . $entity->getId(); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
/** |
|
577
|
|
|
* Get this message as a complete string. |
|
578
|
|
|
* |
|
579
|
|
|
* @return string |
|
580
|
|
|
*/ |
|
581
|
133 |
View Code Duplication |
public function toString() |
|
|
|
|
|
|
582
|
|
|
{ |
|
583
|
133 |
|
$children = $this->getChildren(); |
|
584
|
|
|
|
|
585
|
|
|
if ( |
|
586
|
133 |
|
count($children) > 0 |
|
587
|
133 |
|
&& |
|
588
|
37 |
|
$this->getBody() // WARNING: don't try to use strict comparision here |
|
589
|
133 |
|
) { |
|
590
|
10 |
|
$this->setChildren(array_merge(array($this->_becomeMimePart()), $children)); |
|
591
|
10 |
|
$string = parent::toString(); |
|
592
|
10 |
|
$this->setChildren($children); |
|
593
|
10 |
|
} else { |
|
594
|
123 |
|
$string = parent::toString(); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
133 |
|
return $string; |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* Returns a string representation of this object. |
|
602
|
|
|
* |
|
603
|
|
|
* @see toString() |
|
604
|
|
|
* |
|
605
|
|
|
* @return string |
|
606
|
|
|
*/ |
|
607
|
|
|
public function __toString() |
|
608
|
|
|
{ |
|
609
|
|
|
return $this->toString(); |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
/** |
|
613
|
|
|
* Write this message to a {@link Swift_InputByteStream}. |
|
614
|
|
|
* |
|
615
|
|
|
* @param Swift_InputByteStream $is |
|
616
|
|
|
*/ |
|
617
|
21 |
View Code Duplication |
public function toByteStream(Swift_InputByteStream $is) |
|
|
|
|
|
|
618
|
|
|
{ |
|
619
|
21 |
|
$children = $this->getChildren(); |
|
620
|
|
|
|
|
621
|
|
|
if ( |
|
622
|
21 |
|
count($children) > 0 |
|
623
|
21 |
|
&& |
|
624
|
9 |
|
$this->getBody() // WARNING: don't try to use strict comparision here |
|
625
|
21 |
|
) { |
|
626
|
8 |
|
$this->setChildren(array_merge(array($this->_becomeMimePart()), $children)); |
|
627
|
8 |
|
parent::toByteStream($is); |
|
628
|
8 |
|
$this->setChildren($children); |
|
629
|
8 |
|
} else { |
|
630
|
13 |
|
parent::toByteStream($is); |
|
631
|
|
|
} |
|
632
|
21 |
|
} |
|
633
|
|
|
|
|
634
|
|
|
/** @see Swift_Mime_SimpleMimeEntity::_getIdField() */ |
|
635
|
258 |
|
protected function _getIdField() |
|
636
|
|
|
{ |
|
637
|
258 |
|
return 'Message-ID'; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
/** Turn the body of this message into a child of itself if needed */ |
|
641
|
19 |
|
protected function _becomeMimePart() |
|
642
|
|
|
{ |
|
643
|
19 |
|
$part = new parent( |
|
644
|
19 |
|
$this->getHeaders()->newInstance(), |
|
645
|
19 |
|
$this->getEncoder(), |
|
646
|
19 |
|
$this->_getCache(), |
|
647
|
19 |
|
$this->_getIdGenerator(), |
|
648
|
19 |
|
$this->_userCharset |
|
649
|
19 |
|
); |
|
650
|
19 |
|
$part->setContentType($this->_userContentType); |
|
651
|
19 |
|
$part->setBody($this->getBody()); |
|
652
|
19 |
|
$part->setFormat($this->_userFormat); |
|
653
|
19 |
|
$part->setDelSp($this->_userDelSp); |
|
654
|
19 |
|
$part->setMaxLineLength($this->getMaxLineLength()); |
|
655
|
19 |
|
$part->_setNestingLevel($this->_getTopNestingLevel()); |
|
656
|
|
|
|
|
657
|
19 |
|
return $part; |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** Get the highest nesting level nested inside this message */ |
|
661
|
19 |
|
private function _getTopNestingLevel() |
|
662
|
|
|
{ |
|
663
|
19 |
|
$highestLevel = $this->getNestingLevel(); |
|
664
|
19 |
|
foreach ($this->getChildren() as $child) { |
|
665
|
19 |
|
$childLevel = $child->getNestingLevel(); |
|
666
|
19 |
|
if ($highestLevel < $childLevel) { |
|
667
|
19 |
|
$highestLevel = $childLevel; |
|
668
|
19 |
|
} |
|
669
|
19 |
|
} |
|
670
|
|
|
|
|
671
|
19 |
|
return $highestLevel; |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|
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.