Added feature #15998: Create a new API to send mails based on SwiftMailer to replace...
[Packages/TYPO3.CMS.git] / typo3 / contrib / swiftmailer / classes / Swift / Mime / Headers / PathHeader.php
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 //@require 'Swift/Mime/Headers/AbstractHeader.php';
12 //@require 'Swift/RfcComplianceException.php';
13
14 /**
15 * A Path Header in Swift Mailer, such a Return-Path.
16 * @package Swift
17 * @subpackage Mime
18 * @author Chris Corbyn
19 */
20 class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
21 {
22
23 /**
24 * The address in this Header (if specified).
25 * @var string
26 * @access private
27 */
28 private $_address;
29
30 /**
31 * Creates a new PathHeader with the given $name.
32 * @param string $name
33 */
34 public function __construct($name)
35 {
36 $this->setFieldName($name);
37 $this->initializeGrammar();
38 }
39
40 /**
41 * Get the type of Header that this instance represents.
42 * @return int
43 * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
44 * @see TYPE_DATE, TYPE_ID, TYPE_PATH
45 */
46 public function getFieldType()
47 {
48 return self::TYPE_PATH;
49 }
50
51 /**
52 * Set the model for the field body.
53 * This method takes a string for an address.
54 * @param string $model
55 * @throws Swift_RfcComplianceException
56 */
57 public function setFieldBodyModel($model)
58 {
59 $this->setAddress($model);
60 }
61
62 /**
63 * Get the model for the field body.
64 * This method returns a string email address.
65 * @return mixed
66 */
67 public function getFieldBodyModel()
68 {
69 return $this->getAddress();
70 }
71
72 /**
73 * Set the Address which should appear in this Header.
74 * @param string $address
75 * @throws Swift_RfcComplianceException
76 */
77 public function setAddress($address)
78 {
79 if (is_null($address))
80 {
81 $this->_address = null;
82 }
83 elseif ('' == $address
84 || preg_match('/^' . $this->getGrammar('addr-spec') . '$/D', $address))
85 {
86 $this->_address = $address;
87 }
88 else
89 {
90 throw new Swift_RfcComplianceException(
91 'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
92 );
93 }
94 $this->setCachedValue(null);
95 }
96
97 /**
98 * Get the address which is used in this Header (if any).
99 * Null is returned if no address is set.
100 * @return string
101 */
102 public function getAddress()
103 {
104 return $this->_address;
105 }
106
107 /**
108 * Get the string value of the body in this Header.
109 * This is not necessarily RFC 2822 compliant since folding white space will
110 * not be added at this stage (see {@link toString()} for that).
111 * @return string
112 * @see toString()
113 */
114 public function getFieldBody()
115 {
116 if (!$this->getCachedValue())
117 {
118 if (isset($this->_address))
119 {
120 $this->setCachedValue('<' . $this->_address . '>');
121 }
122 }
123 return $this->getCachedValue();
124 }
125
126 }