@@ -15,41 +15,41 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Get the name of this encoding scheme. |
|
| 20 | - * Returns the string 'B'. |
|
| 21 | - * |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - public function getName() |
|
| 25 | - { |
|
| 26 | - return 'B'; |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Get the name of this encoding scheme. |
|
| 20 | + * Returns the string 'B'. |
|
| 21 | + * |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + public function getName() |
|
| 25 | + { |
|
| 26 | + return 'B'; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Takes an unencoded string and produces a Base64 encoded string from it. |
|
| 31 | - * |
|
| 32 | - * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of |
|
| 33 | - * default encodeString, otherwise pass to the parent method. |
|
| 34 | - * |
|
| 35 | - * @param string $string string to encode |
|
| 36 | - * @param int $firstLineOffset |
|
| 37 | - * @param int $maxLineLength optional, 0 indicates the default of 76 bytes |
|
| 38 | - * @param string $charset |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') |
|
| 43 | - { |
|
| 44 | - if ('iso-2022-jp' === strtolower($charset ?? '')) { |
|
| 45 | - $old = mb_internal_encoding(); |
|
| 46 | - mb_internal_encoding('utf-8'); |
|
| 47 | - $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); |
|
| 48 | - mb_internal_encoding($old); |
|
| 29 | + /** |
|
| 30 | + * Takes an unencoded string and produces a Base64 encoded string from it. |
|
| 31 | + * |
|
| 32 | + * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of |
|
| 33 | + * default encodeString, otherwise pass to the parent method. |
|
| 34 | + * |
|
| 35 | + * @param string $string string to encode |
|
| 36 | + * @param int $firstLineOffset |
|
| 37 | + * @param int $maxLineLength optional, 0 indicates the default of 76 bytes |
|
| 38 | + * @param string $charset |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') |
|
| 43 | + { |
|
| 44 | + if ('iso-2022-jp' === strtolower($charset ?? '')) { |
|
| 45 | + $old = mb_internal_encoding(); |
|
| 46 | + mb_internal_encoding('utf-8'); |
|
| 47 | + $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); |
|
| 48 | + mb_internal_encoding($old); |
|
| 49 | 49 | |
| 50 | - return $newstring; |
|
| 51 | - } |
|
| 50 | + return $newstring; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return parent::encodeString($string, $firstLineOffset, $maxLineLength); |
|
| 54 | - } |
|
| 53 | + return parent::encodeString($string, $firstLineOffset, $maxLineLength); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -15,51 +15,51 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_HeaderEncoder |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Creates a new QpHeaderEncoder for the given CharacterStream. |
|
| 20 | - * |
|
| 21 | - * @param Swift_CharacterStream $charStream to use for reading characters |
|
| 22 | - */ |
|
| 23 | - public function __construct(Swift_CharacterStream $charStream) |
|
| 24 | - { |
|
| 25 | - parent::__construct($charStream); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Creates a new QpHeaderEncoder for the given CharacterStream. |
|
| 20 | + * |
|
| 21 | + * @param Swift_CharacterStream $charStream to use for reading characters |
|
| 22 | + */ |
|
| 23 | + public function __construct(Swift_CharacterStream $charStream) |
|
| 24 | + { |
|
| 25 | + parent::__construct($charStream); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function initSafeMap() |
|
| 29 | - { |
|
| 30 | - foreach (array_merge( |
|
| 31 | - range(0x61, 0x7A), range(0x41, 0x5A), |
|
| 32 | - range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F] |
|
| 33 | - ) as $byte) { |
|
| 34 | - $this->safeMap[$byte] = \chr($byte); |
|
| 35 | - } |
|
| 36 | - } |
|
| 28 | + protected function initSafeMap() |
|
| 29 | + { |
|
| 30 | + foreach (array_merge( |
|
| 31 | + range(0x61, 0x7A), range(0x41, 0x5A), |
|
| 32 | + range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F] |
|
| 33 | + ) as $byte) { |
|
| 34 | + $this->safeMap[$byte] = \chr($byte); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Get the name of this encoding scheme. |
|
| 40 | - * |
|
| 41 | - * Returns the string 'Q'. |
|
| 42 | - * |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function getName() |
|
| 46 | - { |
|
| 47 | - return 'Q'; |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * Get the name of this encoding scheme. |
|
| 40 | + * |
|
| 41 | + * Returns the string 'Q'. |
|
| 42 | + * |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function getName() |
|
| 46 | + { |
|
| 47 | + return 'Q'; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Takes an unencoded string and produces a QP encoded string from it. |
|
| 52 | - * |
|
| 53 | - * @param string $string string to encode |
|
| 54 | - * @param int $firstLineOffset optional |
|
| 55 | - * @param int $maxLineLength optional, 0 indicates the default of 76 chars |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
| 60 | - { |
|
| 61 | - return str_replace([' ', '=20', "=\r\n"], ['_', '_', "\r\n"], |
|
| 62 | - parent::encodeString($string, $firstLineOffset, $maxLineLength) |
|
| 63 | - ); |
|
| 64 | - } |
|
| 50 | + /** |
|
| 51 | + * Takes an unencoded string and produces a QP encoded string from it. |
|
| 52 | + * |
|
| 53 | + * @param string $string string to encode |
|
| 54 | + * @param int $firstLineOffset optional |
|
| 55 | + * @param int $maxLineLength optional, 0 indicates the default of 76 chars |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
| 60 | + { |
|
| 61 | + return str_replace([' ', '=20', "=\r\n"], ['_', '_', "\r\n"], |
|
| 62 | + parent::encodeString($string, $firstLineOffset, $maxLineLength) |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -19,171 +19,171 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_AbstractHeader |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * The IDs used in the value of this Header. |
|
| 24 | - * |
|
| 25 | - * This may hold multiple IDs or just a single ID. |
|
| 26 | - * |
|
| 27 | - * @var string[] |
|
| 28 | - */ |
|
| 29 | - private $ids = []; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The strict EmailValidator. |
|
| 33 | - * |
|
| 34 | - * @var EmailValidator |
|
| 35 | - */ |
|
| 36 | - private $emailValidator; |
|
| 37 | - |
|
| 38 | - private $addressEncoder; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Creates a new IdentificationHeader with the given $name and $id. |
|
| 42 | - * |
|
| 43 | - * @param string $name |
|
| 44 | - */ |
|
| 45 | - public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 46 | - { |
|
| 47 | - $this->setFieldName($name); |
|
| 48 | - $this->emailValidator = $emailValidator; |
|
| 49 | - $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Get the type of Header that this instance represents. |
|
| 54 | - * |
|
| 55 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 56 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 57 | - * |
|
| 58 | - * @return int |
|
| 59 | - */ |
|
| 60 | - public function getFieldType() |
|
| 61 | - { |
|
| 62 | - return self::TYPE_ID; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Set the model for the field body. |
|
| 67 | - * |
|
| 68 | - * This method takes a string ID, or an array of IDs. |
|
| 69 | - * |
|
| 70 | - * @param mixed $model |
|
| 71 | - * |
|
| 72 | - * @throws Swift_RfcComplianceException |
|
| 73 | - */ |
|
| 74 | - public function setFieldBodyModel($model) |
|
| 75 | - { |
|
| 76 | - $this->setId($model); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Get the model for the field body. |
|
| 81 | - * |
|
| 82 | - * This method returns an array of IDs |
|
| 83 | - * |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - public function getFieldBodyModel() |
|
| 87 | - { |
|
| 88 | - return $this->getIds(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set the ID used in the value of this header. |
|
| 93 | - * |
|
| 94 | - * @param string|array $id |
|
| 95 | - * |
|
| 96 | - * @throws Swift_RfcComplianceException |
|
| 97 | - */ |
|
| 98 | - public function setId($id) |
|
| 99 | - { |
|
| 100 | - $this->setIds(\is_array($id) ? $id : [$id]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get the ID used in the value of this Header. |
|
| 105 | - * |
|
| 106 | - * If multiple IDs are set only the first is returned. |
|
| 107 | - * |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function getId() |
|
| 111 | - { |
|
| 112 | - if (\count($this->ids) > 0) { |
|
| 113 | - return $this->ids[0]; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Set a collection of IDs to use in the value of this Header. |
|
| 119 | - * |
|
| 120 | - * @param string[] $ids |
|
| 121 | - * |
|
| 122 | - * @throws Swift_RfcComplianceException |
|
| 123 | - */ |
|
| 124 | - public function setIds(array $ids) |
|
| 125 | - { |
|
| 126 | - $actualIds = []; |
|
| 127 | - |
|
| 128 | - foreach ($ids as $id) { |
|
| 129 | - $this->assertValidId($id); |
|
| 130 | - $actualIds[] = $id; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $this->clearCachedValueIf($this->ids != $actualIds); |
|
| 134 | - $this->ids = $actualIds; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Get the list of IDs used in this Header. |
|
| 139 | - * |
|
| 140 | - * @return string[] |
|
| 141 | - */ |
|
| 142 | - public function getIds() |
|
| 143 | - { |
|
| 144 | - return $this->ids; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Get the string value of the body in this Header. |
|
| 149 | - * |
|
| 150 | - * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 151 | - * not be added at this stage (see {@see toString()} for that). |
|
| 152 | - * |
|
| 153 | - * @see toString() |
|
| 154 | - * |
|
| 155 | - * @throws Swift_RfcComplianceException |
|
| 156 | - * |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function getFieldBody() |
|
| 160 | - { |
|
| 161 | - if (!$this->getCachedValue()) { |
|
| 162 | - $angleAddrs = []; |
|
| 163 | - |
|
| 164 | - foreach ($this->ids as $id) { |
|
| 165 | - $angleAddrs[] = '<'.$this->addressEncoder->encodeString($id).'>'; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $this->setCachedValue(implode(' ', $angleAddrs)); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $this->getCachedValue(); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Throws an Exception if the id passed does not comply with RFC 2822. |
|
| 176 | - * |
|
| 177 | - * @param string $id |
|
| 178 | - * |
|
| 179 | - * @throws Swift_RfcComplianceException |
|
| 180 | - */ |
|
| 181 | - private function assertValidId($id) |
|
| 182 | - { |
|
| 183 | - $emailValidation = class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation(); |
|
| 184 | - |
|
| 185 | - if (!$this->emailValidator->isValid($id, $emailValidation)) { |
|
| 186 | - throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>'); |
|
| 187 | - } |
|
| 188 | - } |
|
| 22 | + /** |
|
| 23 | + * The IDs used in the value of this Header. |
|
| 24 | + * |
|
| 25 | + * This may hold multiple IDs or just a single ID. |
|
| 26 | + * |
|
| 27 | + * @var string[] |
|
| 28 | + */ |
|
| 29 | + private $ids = []; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The strict EmailValidator. |
|
| 33 | + * |
|
| 34 | + * @var EmailValidator |
|
| 35 | + */ |
|
| 36 | + private $emailValidator; |
|
| 37 | + |
|
| 38 | + private $addressEncoder; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Creates a new IdentificationHeader with the given $name and $id. |
|
| 42 | + * |
|
| 43 | + * @param string $name |
|
| 44 | + */ |
|
| 45 | + public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 46 | + { |
|
| 47 | + $this->setFieldName($name); |
|
| 48 | + $this->emailValidator = $emailValidator; |
|
| 49 | + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Get the type of Header that this instance represents. |
|
| 54 | + * |
|
| 55 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 56 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 57 | + * |
|
| 58 | + * @return int |
|
| 59 | + */ |
|
| 60 | + public function getFieldType() |
|
| 61 | + { |
|
| 62 | + return self::TYPE_ID; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Set the model for the field body. |
|
| 67 | + * |
|
| 68 | + * This method takes a string ID, or an array of IDs. |
|
| 69 | + * |
|
| 70 | + * @param mixed $model |
|
| 71 | + * |
|
| 72 | + * @throws Swift_RfcComplianceException |
|
| 73 | + */ |
|
| 74 | + public function setFieldBodyModel($model) |
|
| 75 | + { |
|
| 76 | + $this->setId($model); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Get the model for the field body. |
|
| 81 | + * |
|
| 82 | + * This method returns an array of IDs |
|
| 83 | + * |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + public function getFieldBodyModel() |
|
| 87 | + { |
|
| 88 | + return $this->getIds(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set the ID used in the value of this header. |
|
| 93 | + * |
|
| 94 | + * @param string|array $id |
|
| 95 | + * |
|
| 96 | + * @throws Swift_RfcComplianceException |
|
| 97 | + */ |
|
| 98 | + public function setId($id) |
|
| 99 | + { |
|
| 100 | + $this->setIds(\is_array($id) ? $id : [$id]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get the ID used in the value of this Header. |
|
| 105 | + * |
|
| 106 | + * If multiple IDs are set only the first is returned. |
|
| 107 | + * |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function getId() |
|
| 111 | + { |
|
| 112 | + if (\count($this->ids) > 0) { |
|
| 113 | + return $this->ids[0]; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Set a collection of IDs to use in the value of this Header. |
|
| 119 | + * |
|
| 120 | + * @param string[] $ids |
|
| 121 | + * |
|
| 122 | + * @throws Swift_RfcComplianceException |
|
| 123 | + */ |
|
| 124 | + public function setIds(array $ids) |
|
| 125 | + { |
|
| 126 | + $actualIds = []; |
|
| 127 | + |
|
| 128 | + foreach ($ids as $id) { |
|
| 129 | + $this->assertValidId($id); |
|
| 130 | + $actualIds[] = $id; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $this->clearCachedValueIf($this->ids != $actualIds); |
|
| 134 | + $this->ids = $actualIds; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Get the list of IDs used in this Header. |
|
| 139 | + * |
|
| 140 | + * @return string[] |
|
| 141 | + */ |
|
| 142 | + public function getIds() |
|
| 143 | + { |
|
| 144 | + return $this->ids; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Get the string value of the body in this Header. |
|
| 149 | + * |
|
| 150 | + * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 151 | + * not be added at this stage (see {@see toString()} for that). |
|
| 152 | + * |
|
| 153 | + * @see toString() |
|
| 154 | + * |
|
| 155 | + * @throws Swift_RfcComplianceException |
|
| 156 | + * |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function getFieldBody() |
|
| 160 | + { |
|
| 161 | + if (!$this->getCachedValue()) { |
|
| 162 | + $angleAddrs = []; |
|
| 163 | + |
|
| 164 | + foreach ($this->ids as $id) { |
|
| 165 | + $angleAddrs[] = '<'.$this->addressEncoder->encodeString($id).'>'; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $this->setCachedValue(implode(' ', $angleAddrs)); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $this->getCachedValue(); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Throws an Exception if the id passed does not comply with RFC 2822. |
|
| 176 | + * |
|
| 177 | + * @param string $id |
|
| 178 | + * |
|
| 179 | + * @throws Swift_RfcComplianceException |
|
| 180 | + */ |
|
| 181 | + private function assertValidId($id) |
|
| 182 | + { |
|
| 183 | + $emailValidation = class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation(); |
|
| 184 | + |
|
| 185 | + if (!$this->emailValidator->isValid($id, $emailValidation)) { |
|
| 186 | + throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>'); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | 189 | } |
@@ -15,241 +15,241 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_UnstructuredHeader |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * RFC 2231's definition of a token. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - const TOKEN_REGEX = '(?:[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E]+)'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The Encoder used to encode the parameters. |
|
| 27 | - * |
|
| 28 | - * @var Swift_Encoder |
|
| 29 | - */ |
|
| 30 | - private $paramEncoder; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The parameters as an associative array. |
|
| 34 | - * |
|
| 35 | - * @var string[] |
|
| 36 | - */ |
|
| 37 | - private $params = []; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Creates a new ParameterizedHeader with $name. |
|
| 41 | - * |
|
| 42 | - * @param string $name |
|
| 43 | - */ |
|
| 44 | - public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null) |
|
| 45 | - { |
|
| 46 | - parent::__construct($name, $encoder); |
|
| 47 | - $this->paramEncoder = $paramEncoder; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Get the type of Header that this instance represents. |
|
| 52 | - * |
|
| 53 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 54 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 55 | - * |
|
| 56 | - * @return int |
|
| 57 | - */ |
|
| 58 | - public function getFieldType() |
|
| 59 | - { |
|
| 60 | - return self::TYPE_PARAMETERIZED; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Set the character set used in this Header. |
|
| 65 | - * |
|
| 66 | - * @param string $charset |
|
| 67 | - */ |
|
| 68 | - public function setCharset($charset) |
|
| 69 | - { |
|
| 70 | - parent::setCharset($charset); |
|
| 71 | - if (isset($this->paramEncoder)) { |
|
| 72 | - $this->paramEncoder->charsetChanged($charset); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Set the value of $parameter. |
|
| 78 | - * |
|
| 79 | - * @param string $parameter |
|
| 80 | - * @param string $value |
|
| 81 | - */ |
|
| 82 | - public function setParameter($parameter, $value) |
|
| 83 | - { |
|
| 84 | - $this->setParameters(array_merge($this->getParameters(), [$parameter => $value])); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Get the value of $parameter. |
|
| 89 | - * |
|
| 90 | - * @param string $parameter |
|
| 91 | - * |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function getParameter($parameter) |
|
| 95 | - { |
|
| 96 | - $params = $this->getParameters(); |
|
| 97 | - |
|
| 98 | - return $params[$parameter] ?? null; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Set an associative array of parameter names mapped to values. |
|
| 103 | - * |
|
| 104 | - * @param string[] $parameters |
|
| 105 | - */ |
|
| 106 | - public function setParameters(array $parameters) |
|
| 107 | - { |
|
| 108 | - $this->clearCachedValueIf($this->params != $parameters); |
|
| 109 | - $this->params = $parameters; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns an associative array of parameter names mapped to values. |
|
| 114 | - * |
|
| 115 | - * @return string[] |
|
| 116 | - */ |
|
| 117 | - public function getParameters() |
|
| 118 | - { |
|
| 119 | - return $this->params; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Get the value of this header prepared for rendering. |
|
| 124 | - * |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function getFieldBody() //TODO: Check caching here |
|
| 128 | - { |
|
| 129 | - $body = parent::getFieldBody(); |
|
| 130 | - foreach ($this->params as $name => $value) { |
|
| 131 | - if (null !== $value) { |
|
| 132 | - // Add the parameter |
|
| 133 | - $body .= '; '.$this->createParameter($name, $value); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $body; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Generate a list of all tokens in the final header. |
|
| 142 | - * |
|
| 143 | - * This doesn't need to be overridden in theory, but it is for implementation |
|
| 144 | - * reasons to prevent potential breakage of attributes. |
|
| 145 | - * |
|
| 146 | - * @param string $string The string to tokenize |
|
| 147 | - * |
|
| 148 | - * @return array An array of tokens as strings |
|
| 149 | - */ |
|
| 150 | - protected function toTokens($string = null) |
|
| 151 | - { |
|
| 152 | - $tokens = parent::toTokens(parent::getFieldBody()); |
|
| 153 | - |
|
| 154 | - // Try creating any parameters |
|
| 155 | - foreach ($this->params as $name => $value) { |
|
| 156 | - if (null !== $value) { |
|
| 157 | - // Add the semi-colon separator |
|
| 158 | - $tokens[\count($tokens) - 1] .= ';'; |
|
| 159 | - $tokens = array_merge($tokens, $this->generateTokenLines( |
|
| 160 | - ' '.$this->createParameter($name, $value) |
|
| 161 | - )); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $tokens; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Render a RFC 2047 compliant header parameter from the $name and $value. |
|
| 170 | - * |
|
| 171 | - * @param string $name |
|
| 172 | - * @param string $value |
|
| 173 | - * |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - private function createParameter($name, $value) |
|
| 177 | - { |
|
| 178 | - $origValue = $value; |
|
| 179 | - |
|
| 180 | - $encoded = false; |
|
| 181 | - // Allow room for parameter name, indices, "=" and DQUOTEs |
|
| 182 | - $maxValueLength = $this->getMaxLineLength() - \strlen($name.'=*N"";') - 1; |
|
| 183 | - $firstLineOffset = 0; |
|
| 184 | - |
|
| 185 | - // If it's not already a valid parameter value... |
|
| 186 | - if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) { |
|
| 187 | - // TODO: text, or something else?? |
|
| 188 | - // ... and it's not ascii |
|
| 189 | - if (!preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $value)) { |
|
| 190 | - $encoded = true; |
|
| 191 | - // Allow space for the indices, charset and language |
|
| 192 | - $maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1; |
|
| 193 | - $firstLineOffset = \strlen( |
|
| 194 | - $this->getCharset()."'".$this->getLanguage()."'" |
|
| 195 | - ); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // Encode if we need to |
|
| 200 | - if ($encoded || \strlen($value) > $maxValueLength) { |
|
| 201 | - if (isset($this->paramEncoder)) { |
|
| 202 | - $value = $this->paramEncoder->encodeString( |
|
| 203 | - $origValue, $firstLineOffset, $maxValueLength, $this->getCharset() |
|
| 204 | - ); |
|
| 205 | - } else { |
|
| 206 | - // We have to go against RFC 2183/2231 in some areas for interoperability |
|
| 207 | - $value = $this->getTokenAsEncodedWord($origValue); |
|
| 208 | - $encoded = false; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : [$value]; |
|
| 213 | - |
|
| 214 | - // Need to add indices |
|
| 215 | - if (\count($valueLines) > 1) { |
|
| 216 | - $paramLines = []; |
|
| 217 | - foreach ($valueLines as $i => $line) { |
|
| 218 | - $paramLines[] = $name.'*'.$i. |
|
| 219 | - $this->getEndOfParameterValue($line, true, 0 == $i); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return implode(";\r\n ", $paramLines); |
|
| 223 | - } else { |
|
| 224 | - return $name.$this->getEndOfParameterValue( |
|
| 225 | - $valueLines[0], $encoded, true |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Returns the parameter value from the "=" and beyond. |
|
| 232 | - * |
|
| 233 | - * @param string $value to append |
|
| 234 | - * @param bool $encoded |
|
| 235 | - * @param bool $firstLine |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - private function getEndOfParameterValue($value, $encoded = false, $firstLine = false) |
|
| 240 | - { |
|
| 241 | - if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) { |
|
| 242 | - $value = '"'.$value.'"'; |
|
| 243 | - } |
|
| 244 | - $prepend = '='; |
|
| 245 | - if ($encoded) { |
|
| 246 | - $prepend = '*='; |
|
| 247 | - if ($firstLine) { |
|
| 248 | - $prepend = '*='.$this->getCharset()."'".$this->getLanguage(). |
|
| 249 | - "'"; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - return $prepend.$value; |
|
| 254 | - } |
|
| 18 | + /** |
|
| 19 | + * RFC 2231's definition of a token. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + const TOKEN_REGEX = '(?:[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E]+)'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The Encoder used to encode the parameters. |
|
| 27 | + * |
|
| 28 | + * @var Swift_Encoder |
|
| 29 | + */ |
|
| 30 | + private $paramEncoder; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The parameters as an associative array. |
|
| 34 | + * |
|
| 35 | + * @var string[] |
|
| 36 | + */ |
|
| 37 | + private $params = []; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Creates a new ParameterizedHeader with $name. |
|
| 41 | + * |
|
| 42 | + * @param string $name |
|
| 43 | + */ |
|
| 44 | + public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null) |
|
| 45 | + { |
|
| 46 | + parent::__construct($name, $encoder); |
|
| 47 | + $this->paramEncoder = $paramEncoder; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Get the type of Header that this instance represents. |
|
| 52 | + * |
|
| 53 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 54 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 55 | + * |
|
| 56 | + * @return int |
|
| 57 | + */ |
|
| 58 | + public function getFieldType() |
|
| 59 | + { |
|
| 60 | + return self::TYPE_PARAMETERIZED; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Set the character set used in this Header. |
|
| 65 | + * |
|
| 66 | + * @param string $charset |
|
| 67 | + */ |
|
| 68 | + public function setCharset($charset) |
|
| 69 | + { |
|
| 70 | + parent::setCharset($charset); |
|
| 71 | + if (isset($this->paramEncoder)) { |
|
| 72 | + $this->paramEncoder->charsetChanged($charset); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Set the value of $parameter. |
|
| 78 | + * |
|
| 79 | + * @param string $parameter |
|
| 80 | + * @param string $value |
|
| 81 | + */ |
|
| 82 | + public function setParameter($parameter, $value) |
|
| 83 | + { |
|
| 84 | + $this->setParameters(array_merge($this->getParameters(), [$parameter => $value])); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Get the value of $parameter. |
|
| 89 | + * |
|
| 90 | + * @param string $parameter |
|
| 91 | + * |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function getParameter($parameter) |
|
| 95 | + { |
|
| 96 | + $params = $this->getParameters(); |
|
| 97 | + |
|
| 98 | + return $params[$parameter] ?? null; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Set an associative array of parameter names mapped to values. |
|
| 103 | + * |
|
| 104 | + * @param string[] $parameters |
|
| 105 | + */ |
|
| 106 | + public function setParameters(array $parameters) |
|
| 107 | + { |
|
| 108 | + $this->clearCachedValueIf($this->params != $parameters); |
|
| 109 | + $this->params = $parameters; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns an associative array of parameter names mapped to values. |
|
| 114 | + * |
|
| 115 | + * @return string[] |
|
| 116 | + */ |
|
| 117 | + public function getParameters() |
|
| 118 | + { |
|
| 119 | + return $this->params; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Get the value of this header prepared for rendering. |
|
| 124 | + * |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function getFieldBody() //TODO: Check caching here |
|
| 128 | + { |
|
| 129 | + $body = parent::getFieldBody(); |
|
| 130 | + foreach ($this->params as $name => $value) { |
|
| 131 | + if (null !== $value) { |
|
| 132 | + // Add the parameter |
|
| 133 | + $body .= '; '.$this->createParameter($name, $value); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $body; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Generate a list of all tokens in the final header. |
|
| 142 | + * |
|
| 143 | + * This doesn't need to be overridden in theory, but it is for implementation |
|
| 144 | + * reasons to prevent potential breakage of attributes. |
|
| 145 | + * |
|
| 146 | + * @param string $string The string to tokenize |
|
| 147 | + * |
|
| 148 | + * @return array An array of tokens as strings |
|
| 149 | + */ |
|
| 150 | + protected function toTokens($string = null) |
|
| 151 | + { |
|
| 152 | + $tokens = parent::toTokens(parent::getFieldBody()); |
|
| 153 | + |
|
| 154 | + // Try creating any parameters |
|
| 155 | + foreach ($this->params as $name => $value) { |
|
| 156 | + if (null !== $value) { |
|
| 157 | + // Add the semi-colon separator |
|
| 158 | + $tokens[\count($tokens) - 1] .= ';'; |
|
| 159 | + $tokens = array_merge($tokens, $this->generateTokenLines( |
|
| 160 | + ' '.$this->createParameter($name, $value) |
|
| 161 | + )); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $tokens; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Render a RFC 2047 compliant header parameter from the $name and $value. |
|
| 170 | + * |
|
| 171 | + * @param string $name |
|
| 172 | + * @param string $value |
|
| 173 | + * |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + private function createParameter($name, $value) |
|
| 177 | + { |
|
| 178 | + $origValue = $value; |
|
| 179 | + |
|
| 180 | + $encoded = false; |
|
| 181 | + // Allow room for parameter name, indices, "=" and DQUOTEs |
|
| 182 | + $maxValueLength = $this->getMaxLineLength() - \strlen($name.'=*N"";') - 1; |
|
| 183 | + $firstLineOffset = 0; |
|
| 184 | + |
|
| 185 | + // If it's not already a valid parameter value... |
|
| 186 | + if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) { |
|
| 187 | + // TODO: text, or something else?? |
|
| 188 | + // ... and it's not ascii |
|
| 189 | + if (!preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $value)) { |
|
| 190 | + $encoded = true; |
|
| 191 | + // Allow space for the indices, charset and language |
|
| 192 | + $maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1; |
|
| 193 | + $firstLineOffset = \strlen( |
|
| 194 | + $this->getCharset()."'".$this->getLanguage()."'" |
|
| 195 | + ); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // Encode if we need to |
|
| 200 | + if ($encoded || \strlen($value) > $maxValueLength) { |
|
| 201 | + if (isset($this->paramEncoder)) { |
|
| 202 | + $value = $this->paramEncoder->encodeString( |
|
| 203 | + $origValue, $firstLineOffset, $maxValueLength, $this->getCharset() |
|
| 204 | + ); |
|
| 205 | + } else { |
|
| 206 | + // We have to go against RFC 2183/2231 in some areas for interoperability |
|
| 207 | + $value = $this->getTokenAsEncodedWord($origValue); |
|
| 208 | + $encoded = false; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : [$value]; |
|
| 213 | + |
|
| 214 | + // Need to add indices |
|
| 215 | + if (\count($valueLines) > 1) { |
|
| 216 | + $paramLines = []; |
|
| 217 | + foreach ($valueLines as $i => $line) { |
|
| 218 | + $paramLines[] = $name.'*'.$i. |
|
| 219 | + $this->getEndOfParameterValue($line, true, 0 == $i); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return implode(";\r\n ", $paramLines); |
|
| 223 | + } else { |
|
| 224 | + return $name.$this->getEndOfParameterValue( |
|
| 225 | + $valueLines[0], $encoded, true |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Returns the parameter value from the "=" and beyond. |
|
| 232 | + * |
|
| 233 | + * @param string $value to append |
|
| 234 | + * @param bool $encoded |
|
| 235 | + * @param bool $firstLine |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + private function getEndOfParameterValue($value, $encoded = false, $firstLine = false) |
|
| 240 | + { |
|
| 241 | + if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) { |
|
| 242 | + $value = '"'.$value.'"'; |
|
| 243 | + } |
|
| 244 | + $prepend = '='; |
|
| 245 | + if ($encoded) { |
|
| 246 | + $prepend = '*='; |
|
| 247 | + if ($firstLine) { |
|
| 248 | + $prepend = '*='.$this->getCharset()."'".$this->getLanguage(). |
|
| 249 | + "'"; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + return $prepend.$value; |
|
| 254 | + } |
|
| 255 | 255 | } |
@@ -18,136 +18,136 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * The address in this Header (if specified). |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private $address; |
|
| 21 | + /** |
|
| 22 | + * The address in this Header (if specified). |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private $address; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The strict EmailValidator. |
|
| 30 | - * |
|
| 31 | - * @var EmailValidator |
|
| 32 | - */ |
|
| 33 | - private $emailValidator; |
|
| 28 | + /** |
|
| 29 | + * The strict EmailValidator. |
|
| 30 | + * |
|
| 31 | + * @var EmailValidator |
|
| 32 | + */ |
|
| 33 | + private $emailValidator; |
|
| 34 | 34 | |
| 35 | - private $addressEncoder; |
|
| 35 | + private $addressEncoder; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Creates a new PathHeader with the given $name. |
|
| 39 | - * |
|
| 40 | - * @param string $name |
|
| 41 | - */ |
|
| 42 | - public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 43 | - { |
|
| 44 | - $this->setFieldName($name); |
|
| 45 | - $this->emailValidator = $emailValidator; |
|
| 46 | - $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Creates a new PathHeader with the given $name. |
|
| 39 | + * |
|
| 40 | + * @param string $name |
|
| 41 | + */ |
|
| 42 | + public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 43 | + { |
|
| 44 | + $this->setFieldName($name); |
|
| 45 | + $this->emailValidator = $emailValidator; |
|
| 46 | + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Get the type of Header that this instance represents. |
|
| 51 | - * |
|
| 52 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 53 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 54 | - * |
|
| 55 | - * @return int |
|
| 56 | - */ |
|
| 57 | - public function getFieldType() |
|
| 58 | - { |
|
| 59 | - return self::TYPE_PATH; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * Get the type of Header that this instance represents. |
|
| 51 | + * |
|
| 52 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 53 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 54 | + * |
|
| 55 | + * @return int |
|
| 56 | + */ |
|
| 57 | + public function getFieldType() |
|
| 58 | + { |
|
| 59 | + return self::TYPE_PATH; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Set the model for the field body. |
|
| 64 | - * This method takes a string for an address. |
|
| 65 | - * |
|
| 66 | - * @param string $model |
|
| 67 | - * |
|
| 68 | - * @throws Swift_RfcComplianceException |
|
| 69 | - */ |
|
| 70 | - public function setFieldBodyModel($model) |
|
| 71 | - { |
|
| 72 | - $this->setAddress($model); |
|
| 73 | - } |
|
| 62 | + /** |
|
| 63 | + * Set the model for the field body. |
|
| 64 | + * This method takes a string for an address. |
|
| 65 | + * |
|
| 66 | + * @param string $model |
|
| 67 | + * |
|
| 68 | + * @throws Swift_RfcComplianceException |
|
| 69 | + */ |
|
| 70 | + public function setFieldBodyModel($model) |
|
| 71 | + { |
|
| 72 | + $this->setAddress($model); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Get the model for the field body. |
|
| 77 | - * This method returns a string email address. |
|
| 78 | - * |
|
| 79 | - * @return mixed |
|
| 80 | - */ |
|
| 81 | - public function getFieldBodyModel() |
|
| 82 | - { |
|
| 83 | - return $this->getAddress(); |
|
| 84 | - } |
|
| 75 | + /** |
|
| 76 | + * Get the model for the field body. |
|
| 77 | + * This method returns a string email address. |
|
| 78 | + * |
|
| 79 | + * @return mixed |
|
| 80 | + */ |
|
| 81 | + public function getFieldBodyModel() |
|
| 82 | + { |
|
| 83 | + return $this->getAddress(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Set the Address which should appear in this Header. |
|
| 88 | - * |
|
| 89 | - * @param string $address |
|
| 90 | - * |
|
| 91 | - * @throws Swift_RfcComplianceException |
|
| 92 | - */ |
|
| 93 | - public function setAddress($address) |
|
| 94 | - { |
|
| 95 | - if (null === $address) { |
|
| 96 | - $this->address = null; |
|
| 97 | - } elseif ('' == $address) { |
|
| 98 | - $this->address = ''; |
|
| 99 | - } else { |
|
| 100 | - $this->assertValidAddress($address); |
|
| 101 | - $this->address = $address; |
|
| 102 | - } |
|
| 103 | - $this->setCachedValue(null); |
|
| 104 | - } |
|
| 86 | + /** |
|
| 87 | + * Set the Address which should appear in this Header. |
|
| 88 | + * |
|
| 89 | + * @param string $address |
|
| 90 | + * |
|
| 91 | + * @throws Swift_RfcComplianceException |
|
| 92 | + */ |
|
| 93 | + public function setAddress($address) |
|
| 94 | + { |
|
| 95 | + if (null === $address) { |
|
| 96 | + $this->address = null; |
|
| 97 | + } elseif ('' == $address) { |
|
| 98 | + $this->address = ''; |
|
| 99 | + } else { |
|
| 100 | + $this->assertValidAddress($address); |
|
| 101 | + $this->address = $address; |
|
| 102 | + } |
|
| 103 | + $this->setCachedValue(null); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Get the address which is used in this Header (if any). |
|
| 108 | - * |
|
| 109 | - * Null is returned if no address is set. |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function getAddress() |
|
| 114 | - { |
|
| 115 | - return $this->address; |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * Get the address which is used in this Header (if any). |
|
| 108 | + * |
|
| 109 | + * Null is returned if no address is set. |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function getAddress() |
|
| 114 | + { |
|
| 115 | + return $this->address; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Get the string value of the body in this Header. |
|
| 120 | - * |
|
| 121 | - * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 122 | - * not be added at this stage (see {@link toString()} for that). |
|
| 123 | - * |
|
| 124 | - * @see toString() |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function getFieldBody() |
|
| 129 | - { |
|
| 130 | - if (!$this->getCachedValue()) { |
|
| 131 | - if (isset($this->address)) { |
|
| 132 | - $address = $this->addressEncoder->encodeString($this->address); |
|
| 133 | - $this->setCachedValue('<'.$address.'>'); |
|
| 134 | - } |
|
| 135 | - } |
|
| 118 | + /** |
|
| 119 | + * Get the string value of the body in this Header. |
|
| 120 | + * |
|
| 121 | + * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 122 | + * not be added at this stage (see {@link toString()} for that). |
|
| 123 | + * |
|
| 124 | + * @see toString() |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function getFieldBody() |
|
| 129 | + { |
|
| 130 | + if (!$this->getCachedValue()) { |
|
| 131 | + if (isset($this->address)) { |
|
| 132 | + $address = $this->addressEncoder->encodeString($this->address); |
|
| 133 | + $this->setCachedValue('<'.$address.'>'); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $this->getCachedValue(); |
|
| 138 | - } |
|
| 137 | + return $this->getCachedValue(); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Throws an Exception if the address passed does not comply with RFC 2822. |
|
| 142 | - * |
|
| 143 | - * @param string $address |
|
| 144 | - * |
|
| 145 | - * @throws Swift_RfcComplianceException If address is invalid |
|
| 146 | - */ |
|
| 147 | - private function assertValidAddress($address) |
|
| 148 | - { |
|
| 149 | - if (!$this->emailValidator->isValid($address, new RFCValidation())) { |
|
| 150 | - throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 140 | + /** |
|
| 141 | + * Throws an Exception if the address passed does not comply with RFC 2822. |
|
| 142 | + * |
|
| 143 | + * @param string $address |
|
| 144 | + * |
|
| 145 | + * @throws Swift_RfcComplianceException If address is invalid |
|
| 146 | + */ |
|
| 147 | + private function assertValidAddress($address) |
|
| 148 | + { |
|
| 149 | + if (!$this->emailValidator->isValid($address, new RFCValidation())) { |
|
| 150 | + throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -17,119 +17,119 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * The value of this Header. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - private $value; |
|
| 20 | + /** |
|
| 21 | + * The value of this Header. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + private $value; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * The name of this Header. |
|
| 29 | - * |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private $fieldName; |
|
| 27 | + /** |
|
| 28 | + * The name of this Header. |
|
| 29 | + * |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private $fieldName; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $name |
|
| 36 | - */ |
|
| 37 | - public function __construct($name) |
|
| 38 | - { |
|
| 39 | - $this->fieldName = $name; |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $name |
|
| 36 | + */ |
|
| 37 | + public function __construct($name) |
|
| 38 | + { |
|
| 39 | + $this->fieldName = $name; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Get the type of Header that this instance represents. |
|
| 44 | - * |
|
| 45 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 46 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 47 | - * |
|
| 48 | - * @return int |
|
| 49 | - */ |
|
| 50 | - public function getFieldType() |
|
| 51 | - { |
|
| 52 | - return self::TYPE_TEXT; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * Get the type of Header that this instance represents. |
|
| 44 | + * |
|
| 45 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 46 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 47 | + * |
|
| 48 | + * @return int |
|
| 49 | + */ |
|
| 50 | + public function getFieldType() |
|
| 51 | + { |
|
| 52 | + return self::TYPE_TEXT; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Set the model for the field body. |
|
| 57 | - * |
|
| 58 | - * This method takes a string for the field value. |
|
| 59 | - * |
|
| 60 | - * @param string $model |
|
| 61 | - */ |
|
| 62 | - public function setFieldBodyModel($model) |
|
| 63 | - { |
|
| 64 | - $this->setValue($model); |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * Set the model for the field body. |
|
| 57 | + * |
|
| 58 | + * This method takes a string for the field value. |
|
| 59 | + * |
|
| 60 | + * @param string $model |
|
| 61 | + */ |
|
| 62 | + public function setFieldBodyModel($model) |
|
| 63 | + { |
|
| 64 | + $this->setValue($model); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get the model for the field body. |
|
| 69 | - * |
|
| 70 | - * This method returns a string. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getFieldBodyModel() |
|
| 75 | - { |
|
| 76 | - return $this->getValue(); |
|
| 77 | - } |
|
| 67 | + /** |
|
| 68 | + * Get the model for the field body. |
|
| 69 | + * |
|
| 70 | + * This method returns a string. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getFieldBodyModel() |
|
| 75 | + { |
|
| 76 | + return $this->getValue(); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get the (unencoded) value of this header. |
|
| 81 | - * |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function getValue() |
|
| 85 | - { |
|
| 86 | - return $this->value; |
|
| 87 | - } |
|
| 79 | + /** |
|
| 80 | + * Get the (unencoded) value of this header. |
|
| 81 | + * |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function getValue() |
|
| 85 | + { |
|
| 86 | + return $this->value; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Set the (unencoded) value of this header. |
|
| 91 | - * |
|
| 92 | - * @param string $value |
|
| 93 | - */ |
|
| 94 | - public function setValue($value) |
|
| 95 | - { |
|
| 96 | - $this->value = $value; |
|
| 97 | - } |
|
| 89 | + /** |
|
| 90 | + * Set the (unencoded) value of this header. |
|
| 91 | + * |
|
| 92 | + * @param string $value |
|
| 93 | + */ |
|
| 94 | + public function setValue($value) |
|
| 95 | + { |
|
| 96 | + $this->value = $value; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get the value of this header prepared for rendering. |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function getFieldBody() |
|
| 105 | - { |
|
| 106 | - return $this->value; |
|
| 107 | - } |
|
| 99 | + /** |
|
| 100 | + * Get the value of this header prepared for rendering. |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function getFieldBody() |
|
| 105 | + { |
|
| 106 | + return $this->value; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Get this Header rendered as a RFC 2822 compliant string. |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function toString() |
|
| 115 | - { |
|
| 116 | - return $this->fieldName.': '.$this->value."\r\n"; |
|
| 117 | - } |
|
| 109 | + /** |
|
| 110 | + * Get this Header rendered as a RFC 2822 compliant string. |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function toString() |
|
| 115 | + { |
|
| 116 | + return $this->fieldName.': '.$this->value."\r\n"; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Set the Header FieldName. |
|
| 121 | - * |
|
| 122 | - * @see Swift_Mime_Header::getFieldName() |
|
| 123 | - */ |
|
| 124 | - public function getFieldName() |
|
| 125 | - { |
|
| 126 | - return $this->fieldName; |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * Set the Header FieldName. |
|
| 121 | + * |
|
| 122 | + * @see Swift_Mime_Header::getFieldName() |
|
| 123 | + */ |
|
| 124 | + public function getFieldName() |
|
| 125 | + { |
|
| 126 | + return $this->fieldName; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Ignored. |
|
| 131 | - */ |
|
| 132 | - public function setCharset($charset) |
|
| 133 | - { |
|
| 134 | - } |
|
| 129 | + /** |
|
| 130 | + * Ignored. |
|
| 131 | + */ |
|
| 132 | + public function setCharset($charset) |
|
| 133 | + { |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -15,95 +15,95 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * The value of this Header. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - private $value; |
|
| 18 | + /** |
|
| 19 | + * The value of this Header. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + private $value; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Creates a new SimpleHeader with $name. |
|
| 27 | - * |
|
| 28 | - * @param string $name |
|
| 29 | - */ |
|
| 30 | - public function __construct($name, Swift_Mime_HeaderEncoder $encoder) |
|
| 31 | - { |
|
| 32 | - $this->setFieldName($name); |
|
| 33 | - $this->setEncoder($encoder); |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * Creates a new SimpleHeader with $name. |
|
| 27 | + * |
|
| 28 | + * @param string $name |
|
| 29 | + */ |
|
| 30 | + public function __construct($name, Swift_Mime_HeaderEncoder $encoder) |
|
| 31 | + { |
|
| 32 | + $this->setFieldName($name); |
|
| 33 | + $this->setEncoder($encoder); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Get the type of Header that this instance represents. |
|
| 38 | - * |
|
| 39 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 40 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 41 | - * |
|
| 42 | - * @return int |
|
| 43 | - */ |
|
| 44 | - public function getFieldType() |
|
| 45 | - { |
|
| 46 | - return self::TYPE_TEXT; |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * Get the type of Header that this instance represents. |
|
| 38 | + * |
|
| 39 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 40 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 41 | + * |
|
| 42 | + * @return int |
|
| 43 | + */ |
|
| 44 | + public function getFieldType() |
|
| 45 | + { |
|
| 46 | + return self::TYPE_TEXT; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Set the model for the field body. |
|
| 51 | - * |
|
| 52 | - * This method takes a string for the field value. |
|
| 53 | - * |
|
| 54 | - * @param string $model |
|
| 55 | - */ |
|
| 56 | - public function setFieldBodyModel($model) |
|
| 57 | - { |
|
| 58 | - $this->setValue($model); |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * Set the model for the field body. |
|
| 51 | + * |
|
| 52 | + * This method takes a string for the field value. |
|
| 53 | + * |
|
| 54 | + * @param string $model |
|
| 55 | + */ |
|
| 56 | + public function setFieldBodyModel($model) |
|
| 57 | + { |
|
| 58 | + $this->setValue($model); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the model for the field body. |
|
| 63 | - * |
|
| 64 | - * This method returns a string. |
|
| 65 | - * |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function getFieldBodyModel() |
|
| 69 | - { |
|
| 70 | - return $this->getValue(); |
|
| 71 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the model for the field body. |
|
| 63 | + * |
|
| 64 | + * This method returns a string. |
|
| 65 | + * |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function getFieldBodyModel() |
|
| 69 | + { |
|
| 70 | + return $this->getValue(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get the (unencoded) value of this header. |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getValue() |
|
| 79 | - { |
|
| 80 | - return $this->value; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Get the (unencoded) value of this header. |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getValue() |
|
| 79 | + { |
|
| 80 | + return $this->value; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Set the (unencoded) value of this header. |
|
| 85 | - * |
|
| 86 | - * @param string $value |
|
| 87 | - */ |
|
| 88 | - public function setValue($value) |
|
| 89 | - { |
|
| 90 | - $this->clearCachedValueIf($this->value != $value); |
|
| 91 | - $this->value = $value; |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * Set the (unencoded) value of this header. |
|
| 85 | + * |
|
| 86 | + * @param string $value |
|
| 87 | + */ |
|
| 88 | + public function setValue($value) |
|
| 89 | + { |
|
| 90 | + $this->clearCachedValueIf($this->value != $value); |
|
| 91 | + $this->value = $value; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Get the value of this header prepared for rendering. |
|
| 96 | - * |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function getFieldBody() |
|
| 100 | - { |
|
| 101 | - if (!$this->getCachedValue()) { |
|
| 102 | - $this->setCachedValue( |
|
| 103 | - $this->encodeWords($this, $this->value) |
|
| 104 | - ); |
|
| 105 | - } |
|
| 94 | + /** |
|
| 95 | + * Get the value of this header prepared for rendering. |
|
| 96 | + * |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function getFieldBody() |
|
| 100 | + { |
|
| 101 | + if (!$this->getCachedValue()) { |
|
| 102 | + $this->setCachedValue( |
|
| 103 | + $this->encodeWords($this, $this->value) |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return $this->getCachedValue(); |
|
| 108 | - } |
|
| 107 | + return $this->getCachedValue(); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -18,341 +18,341 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * The mailboxes used in this Header. |
|
| 23 | - * |
|
| 24 | - * @var string[] |
|
| 25 | - */ |
|
| 26 | - private $mailboxes = []; |
|
| 21 | + /** |
|
| 22 | + * The mailboxes used in this Header. |
|
| 23 | + * |
|
| 24 | + * @var string[] |
|
| 25 | + */ |
|
| 26 | + private $mailboxes = []; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The strict EmailValidator. |
|
| 30 | - * |
|
| 31 | - * @var EmailValidator |
|
| 32 | - */ |
|
| 33 | - private $emailValidator; |
|
| 28 | + /** |
|
| 29 | + * The strict EmailValidator. |
|
| 30 | + * |
|
| 31 | + * @var EmailValidator |
|
| 32 | + */ |
|
| 33 | + private $emailValidator; |
|
| 34 | 34 | |
| 35 | - private $addressEncoder; |
|
| 35 | + private $addressEncoder; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Creates a new MailboxHeader with $name. |
|
| 39 | - * |
|
| 40 | - * @param string $name of Header |
|
| 41 | - */ |
|
| 42 | - public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 43 | - { |
|
| 44 | - $this->setFieldName($name); |
|
| 45 | - $this->setEncoder($encoder); |
|
| 46 | - $this->emailValidator = $emailValidator; |
|
| 47 | - $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 48 | - } |
|
| 37 | + /** |
|
| 38 | + * Creates a new MailboxHeader with $name. |
|
| 39 | + * |
|
| 40 | + * @param string $name of Header |
|
| 41 | + */ |
|
| 42 | + public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) |
|
| 43 | + { |
|
| 44 | + $this->setFieldName($name); |
|
| 45 | + $this->setEncoder($encoder); |
|
| 46 | + $this->emailValidator = $emailValidator; |
|
| 47 | + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Get the type of Header that this instance represents. |
|
| 52 | - * |
|
| 53 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 54 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 55 | - * |
|
| 56 | - * @return int |
|
| 57 | - */ |
|
| 58 | - public function getFieldType() |
|
| 59 | - { |
|
| 60 | - return self::TYPE_MAILBOX; |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * Get the type of Header that this instance represents. |
|
| 52 | + * |
|
| 53 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 54 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 55 | + * |
|
| 56 | + * @return int |
|
| 57 | + */ |
|
| 58 | + public function getFieldType() |
|
| 59 | + { |
|
| 60 | + return self::TYPE_MAILBOX; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Set the model for the field body. |
|
| 65 | - * |
|
| 66 | - * This method takes a string, or an array of addresses. |
|
| 67 | - * |
|
| 68 | - * @param mixed $model |
|
| 69 | - * |
|
| 70 | - * @throws Swift_RfcComplianceException |
|
| 71 | - */ |
|
| 72 | - public function setFieldBodyModel($model) |
|
| 73 | - { |
|
| 74 | - $this->setNameAddresses($model); |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * Set the model for the field body. |
|
| 65 | + * |
|
| 66 | + * This method takes a string, or an array of addresses. |
|
| 67 | + * |
|
| 68 | + * @param mixed $model |
|
| 69 | + * |
|
| 70 | + * @throws Swift_RfcComplianceException |
|
| 71 | + */ |
|
| 72 | + public function setFieldBodyModel($model) |
|
| 73 | + { |
|
| 74 | + $this->setNameAddresses($model); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Get the model for the field body. |
|
| 79 | - * |
|
| 80 | - * This method returns an associative array like {@link getNameAddresses()} |
|
| 81 | - * |
|
| 82 | - * @throws Swift_RfcComplianceException |
|
| 83 | - * |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - public function getFieldBodyModel() |
|
| 87 | - { |
|
| 88 | - return $this->getNameAddresses(); |
|
| 89 | - } |
|
| 77 | + /** |
|
| 78 | + * Get the model for the field body. |
|
| 79 | + * |
|
| 80 | + * This method returns an associative array like {@link getNameAddresses()} |
|
| 81 | + * |
|
| 82 | + * @throws Swift_RfcComplianceException |
|
| 83 | + * |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + public function getFieldBodyModel() |
|
| 87 | + { |
|
| 88 | + return $this->getNameAddresses(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Set a list of mailboxes to be shown in this Header. |
|
| 93 | - * |
|
| 94 | - * The mailboxes can be a simple array of addresses, or an array of |
|
| 95 | - * key=>value pairs where (email => personalName). |
|
| 96 | - * Example: |
|
| 97 | - * <code> |
|
| 98 | - * <?php |
|
| 99 | - * //Sets two mailboxes in the Header, one with a personal name |
|
| 100 | - * $header->setNameAddresses(array( |
|
| 101 | - * '[email protected]' => 'Chris Corbyn', |
|
| 102 | - * '[email protected]' //No associated personal name |
|
| 103 | - * )); |
|
| 104 | - * ?> |
|
| 105 | - * </code> |
|
| 106 | - * |
|
| 107 | - * @see __construct() |
|
| 108 | - * @see setAddresses() |
|
| 109 | - * @see setValue() |
|
| 110 | - * |
|
| 111 | - * @param string|string[] $mailboxes |
|
| 112 | - * |
|
| 113 | - * @throws Swift_RfcComplianceException |
|
| 114 | - */ |
|
| 115 | - public function setNameAddresses($mailboxes) |
|
| 116 | - { |
|
| 117 | - $this->mailboxes = $this->normalizeMailboxes((array) $mailboxes); |
|
| 118 | - $this->setCachedValue(null); //Clear any cached value |
|
| 119 | - } |
|
| 91 | + /** |
|
| 92 | + * Set a list of mailboxes to be shown in this Header. |
|
| 93 | + * |
|
| 94 | + * The mailboxes can be a simple array of addresses, or an array of |
|
| 95 | + * key=>value pairs where (email => personalName). |
|
| 96 | + * Example: |
|
| 97 | + * <code> |
|
| 98 | + * <?php |
|
| 99 | + * //Sets two mailboxes in the Header, one with a personal name |
|
| 100 | + * $header->setNameAddresses(array( |
|
| 101 | + * '[email protected]' => 'Chris Corbyn', |
|
| 102 | + * '[email protected]' //No associated personal name |
|
| 103 | + * )); |
|
| 104 | + * ?> |
|
| 105 | + * </code> |
|
| 106 | + * |
|
| 107 | + * @see __construct() |
|
| 108 | + * @see setAddresses() |
|
| 109 | + * @see setValue() |
|
| 110 | + * |
|
| 111 | + * @param string|string[] $mailboxes |
|
| 112 | + * |
|
| 113 | + * @throws Swift_RfcComplianceException |
|
| 114 | + */ |
|
| 115 | + public function setNameAddresses($mailboxes) |
|
| 116 | + { |
|
| 117 | + $this->mailboxes = $this->normalizeMailboxes((array) $mailboxes); |
|
| 118 | + $this->setCachedValue(null); //Clear any cached value |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Get the full mailbox list of this Header as an array of valid RFC 2822 strings. |
|
| 123 | - * |
|
| 124 | - * Example: |
|
| 125 | - * <code> |
|
| 126 | - * <?php |
|
| 127 | - * $header = new Swift_Mime_Headers_MailboxHeader('From', |
|
| 128 | - * array('[email protected]' => 'Chris Corbyn', |
|
| 129 | - * '[email protected]' => 'Mark Corbyn') |
|
| 130 | - * ); |
|
| 131 | - * print_r($header->getNameAddressStrings()); |
|
| 132 | - * // array ( |
|
| 133 | - * // 0 => Chris Corbyn <[email protected]>, |
|
| 134 | - * // 1 => Mark Corbyn <[email protected]> |
|
| 135 | - * // ) |
|
| 136 | - * ?> |
|
| 137 | - * </code> |
|
| 138 | - * |
|
| 139 | - * @see getNameAddresses() |
|
| 140 | - * @see toString() |
|
| 141 | - * |
|
| 142 | - * @throws Swift_RfcComplianceException |
|
| 143 | - * |
|
| 144 | - * @return string[] |
|
| 145 | - */ |
|
| 146 | - public function getNameAddressStrings() |
|
| 147 | - { |
|
| 148 | - return $this->createNameAddressStrings($this->getNameAddresses()); |
|
| 149 | - } |
|
| 121 | + /** |
|
| 122 | + * Get the full mailbox list of this Header as an array of valid RFC 2822 strings. |
|
| 123 | + * |
|
| 124 | + * Example: |
|
| 125 | + * <code> |
|
| 126 | + * <?php |
|
| 127 | + * $header = new Swift_Mime_Headers_MailboxHeader('From', |
|
| 128 | + * array('[email protected]' => 'Chris Corbyn', |
|
| 129 | + * '[email protected]' => 'Mark Corbyn') |
|
| 130 | + * ); |
|
| 131 | + * print_r($header->getNameAddressStrings()); |
|
| 132 | + * // array ( |
|
| 133 | + * // 0 => Chris Corbyn <[email protected]>, |
|
| 134 | + * // 1 => Mark Corbyn <[email protected]> |
|
| 135 | + * // ) |
|
| 136 | + * ?> |
|
| 137 | + * </code> |
|
| 138 | + * |
|
| 139 | + * @see getNameAddresses() |
|
| 140 | + * @see toString() |
|
| 141 | + * |
|
| 142 | + * @throws Swift_RfcComplianceException |
|
| 143 | + * |
|
| 144 | + * @return string[] |
|
| 145 | + */ |
|
| 146 | + public function getNameAddressStrings() |
|
| 147 | + { |
|
| 148 | + return $this->createNameAddressStrings($this->getNameAddresses()); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get all mailboxes in this Header as key=>value pairs. |
|
| 153 | - * |
|
| 154 | - * The key is the address and the value is the name (or null if none set). |
|
| 155 | - * Example: |
|
| 156 | - * <code> |
|
| 157 | - * <?php |
|
| 158 | - * $header = new Swift_Mime_Headers_MailboxHeader('From', |
|
| 159 | - * array('[email protected]' => 'Chris Corbyn', |
|
| 160 | - * '[email protected]' => 'Mark Corbyn') |
|
| 161 | - * ); |
|
| 162 | - * print_r($header->getNameAddresses()); |
|
| 163 | - * // array ( |
|
| 164 | - * // [email protected] => Chris Corbyn, |
|
| 165 | - * // [email protected] => Mark Corbyn |
|
| 166 | - * // ) |
|
| 167 | - * ?> |
|
| 168 | - * </code> |
|
| 169 | - * |
|
| 170 | - * @see getAddresses() |
|
| 171 | - * @see getNameAddressStrings() |
|
| 172 | - * |
|
| 173 | - * @return string[] |
|
| 174 | - */ |
|
| 175 | - public function getNameAddresses() |
|
| 176 | - { |
|
| 177 | - return $this->mailboxes; |
|
| 178 | - } |
|
| 151 | + /** |
|
| 152 | + * Get all mailboxes in this Header as key=>value pairs. |
|
| 153 | + * |
|
| 154 | + * The key is the address and the value is the name (or null if none set). |
|
| 155 | + * Example: |
|
| 156 | + * <code> |
|
| 157 | + * <?php |
|
| 158 | + * $header = new Swift_Mime_Headers_MailboxHeader('From', |
|
| 159 | + * array('[email protected]' => 'Chris Corbyn', |
|
| 160 | + * '[email protected]' => 'Mark Corbyn') |
|
| 161 | + * ); |
|
| 162 | + * print_r($header->getNameAddresses()); |
|
| 163 | + * // array ( |
|
| 164 | + * // [email protected] => Chris Corbyn, |
|
| 165 | + * // [email protected] => Mark Corbyn |
|
| 166 | + * // ) |
|
| 167 | + * ?> |
|
| 168 | + * </code> |
|
| 169 | + * |
|
| 170 | + * @see getAddresses() |
|
| 171 | + * @see getNameAddressStrings() |
|
| 172 | + * |
|
| 173 | + * @return string[] |
|
| 174 | + */ |
|
| 175 | + public function getNameAddresses() |
|
| 176 | + { |
|
| 177 | + return $this->mailboxes; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Makes this Header represent a list of plain email addresses with no names. |
|
| 182 | - * |
|
| 183 | - * Example: |
|
| 184 | - * <code> |
|
| 185 | - * <?php |
|
| 186 | - * //Sets three email addresses as the Header data |
|
| 187 | - * $header->setAddresses( |
|
| 188 | - * array('[email protected]', '[email protected]', '[email protected]') |
|
| 189 | - * ); |
|
| 190 | - * ?> |
|
| 191 | - * </code> |
|
| 192 | - * |
|
| 193 | - * @see setNameAddresses() |
|
| 194 | - * @see setValue() |
|
| 195 | - * |
|
| 196 | - * @param string[] $addresses |
|
| 197 | - * |
|
| 198 | - * @throws Swift_RfcComplianceException |
|
| 199 | - */ |
|
| 200 | - public function setAddresses($addresses) |
|
| 201 | - { |
|
| 202 | - $this->setNameAddresses(array_values((array) $addresses)); |
|
| 203 | - } |
|
| 180 | + /** |
|
| 181 | + * Makes this Header represent a list of plain email addresses with no names. |
|
| 182 | + * |
|
| 183 | + * Example: |
|
| 184 | + * <code> |
|
| 185 | + * <?php |
|
| 186 | + * //Sets three email addresses as the Header data |
|
| 187 | + * $header->setAddresses( |
|
| 188 | + * array('[email protected]', '[email protected]', '[email protected]') |
|
| 189 | + * ); |
|
| 190 | + * ?> |
|
| 191 | + * </code> |
|
| 192 | + * |
|
| 193 | + * @see setNameAddresses() |
|
| 194 | + * @see setValue() |
|
| 195 | + * |
|
| 196 | + * @param string[] $addresses |
|
| 197 | + * |
|
| 198 | + * @throws Swift_RfcComplianceException |
|
| 199 | + */ |
|
| 200 | + public function setAddresses($addresses) |
|
| 201 | + { |
|
| 202 | + $this->setNameAddresses(array_values((array) $addresses)); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Get all email addresses in this Header. |
|
| 207 | - * |
|
| 208 | - * @see getNameAddresses() |
|
| 209 | - * |
|
| 210 | - * @return string[] |
|
| 211 | - */ |
|
| 212 | - public function getAddresses() |
|
| 213 | - { |
|
| 214 | - return array_keys($this->mailboxes); |
|
| 215 | - } |
|
| 205 | + /** |
|
| 206 | + * Get all email addresses in this Header. |
|
| 207 | + * |
|
| 208 | + * @see getNameAddresses() |
|
| 209 | + * |
|
| 210 | + * @return string[] |
|
| 211 | + */ |
|
| 212 | + public function getAddresses() |
|
| 213 | + { |
|
| 214 | + return array_keys($this->mailboxes); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Remove one or more addresses from this Header. |
|
| 219 | - * |
|
| 220 | - * @param string|string[] $addresses |
|
| 221 | - */ |
|
| 222 | - public function removeAddresses($addresses) |
|
| 223 | - { |
|
| 224 | - $this->setCachedValue(null); |
|
| 225 | - foreach ((array) $addresses as $address) { |
|
| 226 | - unset($this->mailboxes[$address]); |
|
| 227 | - } |
|
| 228 | - } |
|
| 217 | + /** |
|
| 218 | + * Remove one or more addresses from this Header. |
|
| 219 | + * |
|
| 220 | + * @param string|string[] $addresses |
|
| 221 | + */ |
|
| 222 | + public function removeAddresses($addresses) |
|
| 223 | + { |
|
| 224 | + $this->setCachedValue(null); |
|
| 225 | + foreach ((array) $addresses as $address) { |
|
| 226 | + unset($this->mailboxes[$address]); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Get the string value of the body in this Header. |
|
| 232 | - * |
|
| 233 | - * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 234 | - * not be added at this stage (see {@link toString()} for that). |
|
| 235 | - * |
|
| 236 | - * @see toString() |
|
| 237 | - * |
|
| 238 | - * @throws Swift_RfcComplianceException |
|
| 239 | - * |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public function getFieldBody() |
|
| 243 | - { |
|
| 244 | - // Compute the string value of the header only if needed |
|
| 245 | - if (null === $this->getCachedValue()) { |
|
| 246 | - $this->setCachedValue($this->createMailboxListString($this->mailboxes)); |
|
| 247 | - } |
|
| 230 | + /** |
|
| 231 | + * Get the string value of the body in this Header. |
|
| 232 | + * |
|
| 233 | + * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 234 | + * not be added at this stage (see {@link toString()} for that). |
|
| 235 | + * |
|
| 236 | + * @see toString() |
|
| 237 | + * |
|
| 238 | + * @throws Swift_RfcComplianceException |
|
| 239 | + * |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public function getFieldBody() |
|
| 243 | + { |
|
| 244 | + // Compute the string value of the header only if needed |
|
| 245 | + if (null === $this->getCachedValue()) { |
|
| 246 | + $this->setCachedValue($this->createMailboxListString($this->mailboxes)); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $this->getCachedValue(); |
|
| 250 | - } |
|
| 249 | + return $this->getCachedValue(); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Normalizes a user-input list of mailboxes into consistent key=>value pairs. |
|
| 254 | - * |
|
| 255 | - * @param string[] $mailboxes |
|
| 256 | - * |
|
| 257 | - * @return string[] |
|
| 258 | - */ |
|
| 259 | - protected function normalizeMailboxes(array $mailboxes) |
|
| 260 | - { |
|
| 261 | - $actualMailboxes = []; |
|
| 252 | + /** |
|
| 253 | + * Normalizes a user-input list of mailboxes into consistent key=>value pairs. |
|
| 254 | + * |
|
| 255 | + * @param string[] $mailboxes |
|
| 256 | + * |
|
| 257 | + * @return string[] |
|
| 258 | + */ |
|
| 259 | + protected function normalizeMailboxes(array $mailboxes) |
|
| 260 | + { |
|
| 261 | + $actualMailboxes = []; |
|
| 262 | 262 | |
| 263 | - foreach ($mailboxes as $key => $value) { |
|
| 264 | - if (\is_string($key)) { |
|
| 265 | - //key is email addr |
|
| 266 | - $address = $key; |
|
| 267 | - $name = $value; |
|
| 268 | - } else { |
|
| 269 | - $address = $value; |
|
| 270 | - $name = null; |
|
| 271 | - } |
|
| 272 | - $this->assertValidAddress($address); |
|
| 273 | - $actualMailboxes[$address] = $name; |
|
| 274 | - } |
|
| 263 | + foreach ($mailboxes as $key => $value) { |
|
| 264 | + if (\is_string($key)) { |
|
| 265 | + //key is email addr |
|
| 266 | + $address = $key; |
|
| 267 | + $name = $value; |
|
| 268 | + } else { |
|
| 269 | + $address = $value; |
|
| 270 | + $name = null; |
|
| 271 | + } |
|
| 272 | + $this->assertValidAddress($address); |
|
| 273 | + $actualMailboxes[$address] = $name; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - return $actualMailboxes; |
|
| 277 | - } |
|
| 276 | + return $actualMailboxes; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Produces a compliant, formatted display-name based on the string given. |
|
| 281 | - * |
|
| 282 | - * @param string $displayName as displayed |
|
| 283 | - * @param bool $shorten the first line to make remove for header name |
|
| 284 | - * |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - protected function createDisplayNameString($displayName, $shorten = false) |
|
| 288 | - { |
|
| 289 | - return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten); |
|
| 290 | - } |
|
| 279 | + /** |
|
| 280 | + * Produces a compliant, formatted display-name based on the string given. |
|
| 281 | + * |
|
| 282 | + * @param string $displayName as displayed |
|
| 283 | + * @param bool $shorten the first line to make remove for header name |
|
| 284 | + * |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + protected function createDisplayNameString($displayName, $shorten = false) |
|
| 288 | + { |
|
| 289 | + return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Creates a string form of all the mailboxes in the passed array. |
|
| 294 | - * |
|
| 295 | - * @param string[] $mailboxes |
|
| 296 | - * |
|
| 297 | - * @throws Swift_RfcComplianceException |
|
| 298 | - * |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - protected function createMailboxListString(array $mailboxes) |
|
| 302 | - { |
|
| 303 | - return implode(', ', $this->createNameAddressStrings($mailboxes)); |
|
| 304 | - } |
|
| 292 | + /** |
|
| 293 | + * Creates a string form of all the mailboxes in the passed array. |
|
| 294 | + * |
|
| 295 | + * @param string[] $mailboxes |
|
| 296 | + * |
|
| 297 | + * @throws Swift_RfcComplianceException |
|
| 298 | + * |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + protected function createMailboxListString(array $mailboxes) |
|
| 302 | + { |
|
| 303 | + return implode(', ', $this->createNameAddressStrings($mailboxes)); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Redefine the encoding requirements for mailboxes. |
|
| 308 | - * |
|
| 309 | - * All "specials" must be encoded as the full header value will not be quoted |
|
| 310 | - * |
|
| 311 | - * @see RFC 2822 3.2.1 |
|
| 312 | - * |
|
| 313 | - * @param string $token |
|
| 314 | - * |
|
| 315 | - * @return bool |
|
| 316 | - */ |
|
| 317 | - protected function tokenNeedsEncoding($token) |
|
| 318 | - { |
|
| 319 | - return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token); |
|
| 320 | - } |
|
| 306 | + /** |
|
| 307 | + * Redefine the encoding requirements for mailboxes. |
|
| 308 | + * |
|
| 309 | + * All "specials" must be encoded as the full header value will not be quoted |
|
| 310 | + * |
|
| 311 | + * @see RFC 2822 3.2.1 |
|
| 312 | + * |
|
| 313 | + * @param string $token |
|
| 314 | + * |
|
| 315 | + * @return bool |
|
| 316 | + */ |
|
| 317 | + protected function tokenNeedsEncoding($token) |
|
| 318 | + { |
|
| 319 | + return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token); |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Return an array of strings conforming the the name-addr spec of RFC 2822. |
|
| 324 | - * |
|
| 325 | - * @param string[] $mailboxes |
|
| 326 | - * |
|
| 327 | - * @return string[] |
|
| 328 | - */ |
|
| 329 | - private function createNameAddressStrings(array $mailboxes) |
|
| 330 | - { |
|
| 331 | - $strings = []; |
|
| 322 | + /** |
|
| 323 | + * Return an array of strings conforming the the name-addr spec of RFC 2822. |
|
| 324 | + * |
|
| 325 | + * @param string[] $mailboxes |
|
| 326 | + * |
|
| 327 | + * @return string[] |
|
| 328 | + */ |
|
| 329 | + private function createNameAddressStrings(array $mailboxes) |
|
| 330 | + { |
|
| 331 | + $strings = []; |
|
| 332 | 332 | |
| 333 | - foreach ($mailboxes as $email => $name) { |
|
| 334 | - $mailboxStr = $this->addressEncoder->encodeString($email); |
|
| 335 | - if (null !== $name) { |
|
| 336 | - $nameStr = $this->createDisplayNameString($name, empty($strings)); |
|
| 337 | - $mailboxStr = $nameStr.' <'.$mailboxStr.'>'; |
|
| 338 | - } |
|
| 339 | - $strings[] = $mailboxStr; |
|
| 340 | - } |
|
| 333 | + foreach ($mailboxes as $email => $name) { |
|
| 334 | + $mailboxStr = $this->addressEncoder->encodeString($email); |
|
| 335 | + if (null !== $name) { |
|
| 336 | + $nameStr = $this->createDisplayNameString($name, empty($strings)); |
|
| 337 | + $mailboxStr = $nameStr.' <'.$mailboxStr.'>'; |
|
| 338 | + } |
|
| 339 | + $strings[] = $mailboxStr; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - return $strings; |
|
| 343 | - } |
|
| 342 | + return $strings; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Throws an Exception if the address passed does not comply with RFC 2822. |
|
| 347 | - * |
|
| 348 | - * @param string $address |
|
| 349 | - * |
|
| 350 | - * @throws Swift_RfcComplianceException if invalid |
|
| 351 | - */ |
|
| 352 | - private function assertValidAddress($address) |
|
| 353 | - { |
|
| 354 | - if (!$this->emailValidator->isValid($address, new RFCValidation())) { |
|
| 355 | - throw new Swift_RfcComplianceException('Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'); |
|
| 356 | - } |
|
| 357 | - } |
|
| 345 | + /** |
|
| 346 | + * Throws an Exception if the address passed does not comply with RFC 2822. |
|
| 347 | + * |
|
| 348 | + * @param string $address |
|
| 349 | + * |
|
| 350 | + * @throws Swift_RfcComplianceException if invalid |
|
| 351 | + */ |
|
| 352 | + private function assertValidAddress($address) |
|
| 353 | + { |
|
| 354 | + if (!$this->emailValidator->isValid($address, new RFCValidation())) { |
|
| 355 | + throw new Swift_RfcComplianceException('Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | 358 | } |
@@ -15,99 +15,99 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Date-time value of this Header. |
|
| 20 | - * |
|
| 21 | - * @var DateTimeImmutable |
|
| 22 | - */ |
|
| 23 | - private $dateTime; |
|
| 18 | + /** |
|
| 19 | + * Date-time value of this Header. |
|
| 20 | + * |
|
| 21 | + * @var DateTimeImmutable |
|
| 22 | + */ |
|
| 23 | + private $dateTime; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Creates a new DateHeader with $name. |
|
| 27 | - * |
|
| 28 | - * @param string $name of Header |
|
| 29 | - */ |
|
| 30 | - public function __construct($name) |
|
| 31 | - { |
|
| 32 | - $this->setFieldName($name); |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * Creates a new DateHeader with $name. |
|
| 27 | + * |
|
| 28 | + * @param string $name of Header |
|
| 29 | + */ |
|
| 30 | + public function __construct($name) |
|
| 31 | + { |
|
| 32 | + $this->setFieldName($name); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the type of Header that this instance represents. |
|
| 37 | - * |
|
| 38 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 39 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 40 | - * |
|
| 41 | - * @return int |
|
| 42 | - */ |
|
| 43 | - public function getFieldType() |
|
| 44 | - { |
|
| 45 | - return self::TYPE_DATE; |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * Get the type of Header that this instance represents. |
|
| 37 | + * |
|
| 38 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 39 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 40 | + * |
|
| 41 | + * @return int |
|
| 42 | + */ |
|
| 43 | + public function getFieldType() |
|
| 44 | + { |
|
| 45 | + return self::TYPE_DATE; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Set the model for the field body. |
|
| 50 | - * |
|
| 51 | - * @param DateTimeInterface $model |
|
| 52 | - */ |
|
| 53 | - public function setFieldBodyModel($model) |
|
| 54 | - { |
|
| 55 | - $this->setDateTime($model); |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * Set the model for the field body. |
|
| 50 | + * |
|
| 51 | + * @param DateTimeInterface $model |
|
| 52 | + */ |
|
| 53 | + public function setFieldBodyModel($model) |
|
| 54 | + { |
|
| 55 | + $this->setDateTime($model); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Get the model for the field body. |
|
| 60 | - * |
|
| 61 | - * @return DateTimeImmutable |
|
| 62 | - */ |
|
| 63 | - public function getFieldBodyModel() |
|
| 64 | - { |
|
| 65 | - return $this->getDateTime(); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Get the model for the field body. |
|
| 60 | + * |
|
| 61 | + * @return DateTimeImmutable |
|
| 62 | + */ |
|
| 63 | + public function getFieldBodyModel() |
|
| 64 | + { |
|
| 65 | + return $this->getDateTime(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the date-time representing the Date in this Header. |
|
| 70 | - * |
|
| 71 | - * @return DateTimeImmutable |
|
| 72 | - */ |
|
| 73 | - public function getDateTime() |
|
| 74 | - { |
|
| 75 | - return $this->dateTime; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the date-time representing the Date in this Header. |
|
| 70 | + * |
|
| 71 | + * @return DateTimeImmutable |
|
| 72 | + */ |
|
| 73 | + public function getDateTime() |
|
| 74 | + { |
|
| 75 | + return $this->dateTime; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Set the date-time of the Date in this Header. |
|
| 80 | - * |
|
| 81 | - * If a DateTime instance is provided, it is converted to DateTimeImmutable. |
|
| 82 | - */ |
|
| 83 | - public function setDateTime(DateTimeInterface $dateTime) |
|
| 84 | - { |
|
| 85 | - $this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822)); |
|
| 86 | - if ($dateTime instanceof DateTime) { |
|
| 87 | - $immutable = new DateTimeImmutable('@'.$dateTime->getTimestamp()); |
|
| 88 | - $dateTime = $immutable->setTimezone($dateTime->getTimezone()); |
|
| 89 | - } |
|
| 90 | - $this->dateTime = $dateTime; |
|
| 91 | - } |
|
| 78 | + /** |
|
| 79 | + * Set the date-time of the Date in this Header. |
|
| 80 | + * |
|
| 81 | + * If a DateTime instance is provided, it is converted to DateTimeImmutable. |
|
| 82 | + */ |
|
| 83 | + public function setDateTime(DateTimeInterface $dateTime) |
|
| 84 | + { |
|
| 85 | + $this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822)); |
|
| 86 | + if ($dateTime instanceof DateTime) { |
|
| 87 | + $immutable = new DateTimeImmutable('@'.$dateTime->getTimestamp()); |
|
| 88 | + $dateTime = $immutable->setTimezone($dateTime->getTimezone()); |
|
| 89 | + } |
|
| 90 | + $this->dateTime = $dateTime; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Get the string value of the body in this Header. |
|
| 95 | - * |
|
| 96 | - * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 97 | - * not be added at this stage (see {@link toString()} for that). |
|
| 98 | - * |
|
| 99 | - * @see toString() |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getFieldBody() |
|
| 104 | - { |
|
| 105 | - if (!$this->getCachedValue()) { |
|
| 106 | - if (isset($this->dateTime)) { |
|
| 107 | - $this->setCachedValue($this->dateTime->format(DateTime::RFC2822)); |
|
| 108 | - } |
|
| 109 | - } |
|
| 93 | + /** |
|
| 94 | + * Get the string value of the body in this Header. |
|
| 95 | + * |
|
| 96 | + * This is not necessarily RFC 2822 compliant since folding white space will |
|
| 97 | + * not be added at this stage (see {@link toString()} for that). |
|
| 98 | + * |
|
| 99 | + * @see toString() |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getFieldBody() |
|
| 104 | + { |
|
| 105 | + if (!$this->getCachedValue()) { |
|
| 106 | + if (isset($this->dateTime)) { |
|
| 107 | + $this->setCachedValue($this->dateTime->format(DateTime::RFC2822)); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - return $this->getCachedValue(); |
|
| 112 | - } |
|
| 111 | + return $this->getCachedValue(); |
|
| 112 | + } |
|
| 113 | 113 | } |