| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* +-----------------------------------------------------------------------+ |
| 5 |
* | This file is part of the Roundcube Webmail client | |
| 6 |
* | | |
| 7 |
* | Copyright (C) The Roundcube Dev Team | |
| 8 |
* | Copyright (C) Kolab Systems AG | |
| 9 |
* | | |
| 10 |
* | Licensed under the GNU General Public License version 3 or | |
| 11 |
* | any later version with exceptions for skins & plugins. | |
| 12 |
* | See the README file for a full license statement. | |
| 13 |
* | | |
| 14 |
* | PURPOSE: | |
| 15 |
* | E-mail message headers representation | |
| 16 |
* +-----------------------------------------------------------------------+ |
| 17 |
* | Author: Aleksander Machniak <[email protected]> | |
| 18 |
* +-----------------------------------------------------------------------+ |
| 19 |
*/ |
| 20 |
|
| 21 |
namespace AcyMailing\Libraries\Imap2\Roundcube; |
| 22 |
|
| 23 |
/** |
| 24 |
* Struct representing an e-mail message header |
| 25 |
* |
| 26 |
* @package Framework |
| 27 |
* @subpackage Storage |
| 28 |
*/ |
| 29 |
class MessageHeader |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Message sequence number |
| 33 |
* |
| 34 |
* @var int |
| 35 |
*/ |
| 36 |
public $id; |
| 37 |
|
| 38 |
/** |
| 39 |
* Message unique identifier |
| 40 |
* |
| 41 |
* @var int |
| 42 |
*/ |
| 43 |
public $uid; |
| 44 |
|
| 45 |
/** |
| 46 |
* Message subject |
| 47 |
* |
| 48 |
* @var string |
| 49 |
*/ |
| 50 |
public $subject; |
| 51 |
|
| 52 |
/** |
| 53 |
* Message sender (From) |
| 54 |
* |
| 55 |
* @var string |
| 56 |
*/ |
| 57 |
public $from; |
| 58 |
|
| 59 |
/** |
| 60 |
* Message recipient (To) |
| 61 |
* |
| 62 |
* @var string |
| 63 |
*/ |
| 64 |
public $to; |
| 65 |
|
| 66 |
/** |
| 67 |
* Message additional recipients (Cc) |
| 68 |
* |
| 69 |
* @var string |
| 70 |
*/ |
| 71 |
public $cc; |
| 72 |
|
| 73 |
/** |
| 74 |
* Message Reply-To header |
| 75 |
* |
| 76 |
* @var string |
| 77 |
*/ |
| 78 |
public $replyto; |
| 79 |
|
| 80 |
/** |
| 81 |
* Message In-Reply-To header |
| 82 |
* |
| 83 |
* @var string |
| 84 |
*/ |
| 85 |
public $in_reply_to; |
| 86 |
|
| 87 |
/** |
| 88 |
* Message date (Date) |
| 89 |
* |
| 90 |
* @var string |
| 91 |
*/ |
| 92 |
public $date; |
| 93 |
|
| 94 |
/** |
| 95 |
* Message identifier (Message-ID) |
| 96 |
* |
| 97 |
* @var string |
| 98 |
*/ |
| 99 |
public $messageID; |
| 100 |
|
| 101 |
/** |
| 102 |
* Message size |
| 103 |
* |
| 104 |
* @var int |
| 105 |
*/ |
| 106 |
public $size; |
| 107 |
|
| 108 |
/** |
| 109 |
* Message encoding |
| 110 |
* |
| 111 |
* @var string |
| 112 |
*/ |
| 113 |
public $encoding; |
| 114 |
|
| 115 |
/** |
| 116 |
* Message charset |
| 117 |
* |
| 118 |
* @var string |
| 119 |
*/ |
| 120 |
public $charset; |
| 121 |
|
| 122 |
/** |
| 123 |
* Message Content-type |
| 124 |
* |
| 125 |
* @var string |
| 126 |
*/ |
| 127 |
public $ctype; |
| 128 |
|
| 129 |
/** |
| 130 |
* Message timestamp (based on message date) |
| 131 |
* |
| 132 |
* @var int |
| 133 |
*/ |
| 134 |
public $timestamp; |
| 135 |
|
| 136 |
/** |
| 137 |
* IMAP bodystructure string |
| 138 |
* |
| 139 |
* @var string |
| 140 |
*/ |
| 141 |
public $bodystructure; |
| 142 |
|
| 143 |
/** |
| 144 |
* IMAP internal date |
| 145 |
* |
| 146 |
* @var string |
| 147 |
*/ |
| 148 |
public $internaldate; |
| 149 |
|
| 150 |
/** |
| 151 |
* Message References header |
| 152 |
* |
| 153 |
* @var string |
| 154 |
*/ |
| 155 |
public $references; |
| 156 |
|
| 157 |
/** |
| 158 |
* Message priority (X-Priority) |
| 159 |
* |
| 160 |
* @var int |
| 161 |
*/ |
| 162 |
public $priority; |
| 163 |
|
| 164 |
/** |
| 165 |
* Message receipt recipient |
| 166 |
* |
| 167 |
* @var string |
| 168 |
*/ |
| 169 |
public $mdn_to; |
| 170 |
|
| 171 |
/** |
| 172 |
* IMAP folder this message is stored in |
| 173 |
* |
| 174 |
* @var string |
| 175 |
*/ |
| 176 |
public $folder; |
| 177 |
|
| 178 |
/** |
| 179 |
* Other message headers |
| 180 |
* |
| 181 |
* @var array |
| 182 |
*/ |
| 183 |
public $others = []; |
| 184 |
|
| 185 |
/** |
| 186 |
* Message flags |
| 187 |
* |
| 188 |
* @var array |
| 189 |
*/ |
| 190 |
public $flags = []; |
| 191 |
|
| 192 |
// map header to rcube_message_header object property |
| 193 |
private $obj_headers = [ |
| 194 |
'date' => 'date', |
| 195 |
'from' => 'from', |
| 196 |
'to' => 'to', |
| 197 |
'subject' => 'subject', |
| 198 |
'reply-to' => 'replyto', |
| 199 |
'cc' => 'cc', |
| 200 |
'bcc' => 'bcc', |
| 201 |
'mbox' => 'folder', |
| 202 |
'folder' => 'folder', |
| 203 |
'content-transfer-encoding' => 'encoding', |
| 204 |
'in-reply-to' => 'in_reply_to', |
| 205 |
'content-type' => 'ctype', |
| 206 |
'charset' => 'charset', |
| 207 |
'references' => 'references', |
| 208 |
'return-receipt-to' => 'mdn_to', |
| 209 |
'disposition-notification-to' => 'mdn_to', |
| 210 |
'x-confirm-reading-to' => 'mdn_to', |
| 211 |
'message-id' => 'messageID', |
| 212 |
'x-priority' => 'priority', |
| 213 |
]; |
| 214 |
|
| 215 |
/** |
| 216 |
* Returns header value |
| 217 |
*/ |
| 218 |
public function get($name, $decode = true) |
| 219 |
{ |
| 220 |
$name = strtolower($name); |
| 221 |
|
| 222 |
if (isset($this->obj_headers[$name])) { |
| 223 |
$value = $this->{$this->obj_headers[$name]}; |
| 224 |
} else { |
| 225 |
$value = $this->others[$name]; |
| 226 |
} |
| 227 |
|
| 228 |
if ($decode) { |
| 229 |
if (is_array($value)) { |
| 230 |
foreach ($value as $key => $val) { |
| 231 |
$val = Mime::decode_header($val, $this->charset); |
| 232 |
$value[$key] = Charset::clean($val); |
| 233 |
} |
| 234 |
} else { |
| 235 |
$value = Mime::decode_header($value, $this->charset); |
| 236 |
$value = Charset::clean($value); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
return $value; |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Sets header value |
| 245 |
*/ |
| 246 |
public function set($name, $value) |
| 247 |
{ |
| 248 |
$name = strtolower($name); |
| 249 |
|
| 250 |
if (isset($this->obj_headers[$name])) { |
| 251 |
$this->{$this->obj_headers[$name]} = $value; |
| 252 |
} else { |
| 253 |
$this->others[$name] = $value; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
/** |
| 259 |
* Factory method to instantiate headers from a data array |
| 260 |
* |
| 261 |
* @param array Hash array with header values |
| 262 |
* |
| 263 |
* @return object rcube_message_header instance filled with headers values |
| 264 |
*/ |
| 265 |
public static function from_array($arr) |
| 266 |
{ |
| 267 |
$obj = new MessageHeader; |
| 268 |
foreach ($arr as $k => $v) { |
| 269 |
$obj->set($k, $v); |
| 270 |
} |
| 271 |
|
| 272 |
return $obj; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
|