Mercurial > hg > rc2
annotate program/lib/Roundcube/rcube_message_header.php @ 19:b6a96bdd6b29
More cleaning up php8 Warnings/deprecations
| author | Charlie Root |
|---|---|
| date | Wed, 08 Oct 2025 08:50:44 -0400 |
| parents | 1866b439e6d3 |
| children | 73124dd49283 |
| rev | line source |
|---|---|
| 0 | 1 <?php |
| 2 | |
| 3 /** | |
| 4 +-----------------------------------------------------------------------+ | |
| 5 | This file is part of the Roundcube Webmail client | | |
| 6 | Copyright (C) 2005-2012, The Roundcube Dev Team | | |
| 7 | Copyright (C) 2011-2012, Kolab Systems AG | | |
| 8 | | | |
| 9 | Licensed under the GNU General Public License version 3 or | | |
| 10 | any later version with exceptions for skins & plugins. | | |
| 11 | See the README file for a full license statement. | | |
| 12 | | | |
| 13 | PURPOSE: | | |
| 14 | E-mail message headers representation | | |
| 15 +-----------------------------------------------------------------------+ | |
| 16 | Author: Aleksander Machniak <alec@alec.pl> | | |
| 17 +-----------------------------------------------------------------------+ | |
| 18 */ | |
| 19 | |
| 20 /** | |
| 21 * Struct representing an e-mail message header | |
| 22 * | |
| 23 * @package Framework | |
| 24 * @subpackage Storage | |
| 25 * @author Aleksander Machniak <alec@alec.pl> | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
26 * HST added the abstraction level below because of plugins/thunderbird_labels |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
27 * use of a new property 'list_flags' |
| 0 | 28 */ |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
29 |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
30 abstract class r_m_h_base |
| 0 | 31 { |
| 32 /** | |
| 33 * Message sequence number | |
| 34 * | |
| 35 * @var int | |
| 36 */ | |
| 37 public $id; | |
| 38 | |
| 39 /** | |
| 40 * Message unique identifier | |
| 41 * | |
| 42 * @var int | |
| 43 */ | |
| 44 public $uid; | |
| 45 | |
| 46 /** | |
| 47 * Message subject | |
| 48 * | |
| 49 * @var string | |
| 50 */ | |
| 51 public $subject; | |
| 52 | |
| 53 /** | |
| 54 * Message sender (From) | |
| 55 * | |
| 56 * @var string | |
| 57 */ | |
| 58 public $from; | |
| 59 | |
| 60 /** | |
| 61 * Message recipient (To) | |
| 62 * | |
| 63 * @var string | |
| 64 */ | |
| 65 public $to; | |
| 66 | |
| 67 /** | |
| 68 * Message additional recipients (Cc) | |
| 69 * | |
| 70 * @var string | |
| 71 */ | |
| 72 public $cc; | |
| 73 | |
| 74 /** | |
| 75 * Message Reply-To header | |
| 76 * | |
| 77 * @var string | |
| 78 */ | |
| 79 public $replyto; | |
| 80 | |
| 81 /** | |
| 82 * Message In-Reply-To header | |
| 83 * | |
| 84 * @var string | |
| 85 */ | |
| 86 public $in_reply_to; | |
| 87 | |
| 88 /** | |
| 89 * Message date (Date) | |
| 90 * | |
| 91 * @var string | |
| 92 */ | |
| 93 public $date; | |
| 94 | |
| 95 /** | |
| 96 * Message identifier (Message-ID) | |
| 97 * | |
| 98 * @var string | |
| 99 */ | |
| 100 public $messageID; | |
| 101 | |
| 102 /** | |
| 103 * Message size | |
| 104 * | |
| 105 * @var int | |
| 106 */ | |
| 107 public $size; | |
| 108 | |
| 109 /** | |
| 110 * Message encoding | |
| 111 * | |
| 112 * @var string | |
| 113 */ | |
| 114 public $encoding; | |
| 115 | |
| 116 /** | |
| 117 * Message charset | |
| 118 * | |
| 119 * @var string | |
| 120 */ | |
| 121 public $charset; | |
| 122 | |
| 123 /** | |
| 124 * Message Content-type | |
| 125 * | |
| 126 * @var string | |
| 127 */ | |
| 128 public $ctype; | |
| 129 | |
| 130 /** | |
| 131 * Message timestamp (based on message date) | |
| 132 * | |
| 133 * @var int | |
| 134 */ | |
| 135 public $timestamp; | |
| 136 | |
| 137 /** | |
| 138 * IMAP bodystructure string | |
| 139 * | |
| 140 * @var string | |
| 141 */ | |
| 142 public $bodystructure; | |
| 143 | |
| 144 /** | |
| 19 | 145 * IMAP structure |
| 146 * | |
| 147 * @var rcube_message_part | |
| 148 */ | |
| 149 public $structure; | |
| 150 | |
| 151 /** | |
| 0 | 152 * IMAP internal date |
| 153 * | |
| 154 * @var string | |
| 155 */ | |
| 156 public $internaldate; | |
| 157 | |
| 158 /** | |
| 159 * Message References header | |
| 160 * | |
| 161 * @var string | |
| 162 */ | |
| 163 public $references; | |
| 164 | |
| 165 /** | |
| 166 * Message priority (X-Priority) | |
| 167 * | |
| 168 * @var int | |
| 169 */ | |
| 170 public $priority; | |
| 171 | |
| 172 /** | |
| 173 * Message receipt recipient | |
| 174 * | |
| 175 * @var string | |
| 176 */ | |
| 177 public $mdn_to; | |
| 178 | |
| 179 /** | |
| 180 * IMAP folder this message is stored in | |
| 181 * | |
| 182 * @var string | |
| 183 */ | |
| 184 public $folder; | |
| 185 | |
| 186 /** | |
| 187 * Other message headers | |
| 188 * | |
| 189 * @var array | |
| 190 */ | |
| 191 public $others = array(); | |
| 192 | |
| 193 /** | |
| 194 * Message flags | |
| 195 * | |
| 196 * @var array | |
| 197 */ | |
| 198 public $flags = array(); | |
| 199 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
200 /** |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
201 * Threaded message property, HST added |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
202 * |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
203 * @var int |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
204 */ |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
205 public $parent_uid; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
206 |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
207 /** |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
208 * Threaded message property, HST added |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
209 * |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
210 * @var int |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
211 */ |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
212 public $depth; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
213 |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
214 /** |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
215 * Threaded message property, HST added |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
216 * |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
217 * @var array |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
218 */ |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
219 public $has_children; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
220 |
| 0 | 221 // map header to rcube_message_header object property |
| 222 private $obj_headers = array( | |
| 223 'date' => 'date', | |
| 224 'from' => 'from', | |
| 225 'to' => 'to', | |
| 226 'subject' => 'subject', | |
| 227 'reply-to' => 'replyto', | |
| 228 'cc' => 'cc', | |
| 229 'bcc' => 'bcc', | |
| 230 'mbox' => 'folder', | |
| 231 'folder' => 'folder', | |
| 232 'content-transfer-encoding' => 'encoding', | |
| 233 'in-reply-to' => 'in_reply_to', | |
| 234 'content-type' => 'ctype', | |
| 235 'charset' => 'charset', | |
| 236 'references' => 'references', | |
| 237 'return-receipt-to' => 'mdn_to', | |
| 238 'disposition-notification-to' => 'mdn_to', | |
| 239 'x-confirm-reading-to' => 'mdn_to', | |
| 240 'message-id' => 'messageID', | |
| 241 'x-priority' => 'priority', | |
| 242 ); | |
| 243 | |
| 244 /** | |
| 245 * Returns header value | |
| 246 */ | |
| 247 public function get($name, $decode = true) | |
| 248 { | |
| 249 $name = strtolower($name); | |
| 250 | |
| 251 if (isset($this->obj_headers[$name])) { | |
| 252 $value = $this->{$this->obj_headers[$name]}; | |
| 253 } | |
| 254 else { | |
| 255 $value = $this->others[$name]; | |
| 256 } | |
| 257 | |
| 258 if ($decode) { | |
| 259 if (is_array($value)) { | |
| 260 foreach ($value as $key => $val) { | |
| 261 $val = rcube_mime::decode_header($val, $this->charset); | |
| 262 $value[$key] = rcube_charset::clean($val); | |
| 263 } | |
| 264 } | |
| 265 else { | |
| 266 $value = rcube_mime::decode_header($value, $this->charset); | |
| 267 $value = rcube_charset::clean($value); | |
| 268 } | |
| 269 } | |
| 270 | |
| 271 return $value; | |
| 272 } | |
| 273 | |
| 274 /** | |
| 275 * Sets header value | |
| 276 */ | |
| 277 public function set($name, $value) | |
| 278 { | |
| 279 $name = strtolower($name); | |
| 280 | |
| 281 if (isset($this->obj_headers[$name])) { | |
| 282 $this->{$this->obj_headers[$name]} = $value; | |
| 283 } | |
| 284 else { | |
| 285 $this->others[$name] = $value; | |
| 286 } | |
| 287 } | |
| 288 | |
| 289 | |
| 290 /** | |
| 291 * Factory method to instantiate headers from a data array | |
| 292 * | |
| 293 * @param array Hash array with header values | |
| 294 * @return object rcube_message_header instance filled with headers values | |
| 295 */ | |
| 296 public static function from_array($arr) | |
| 297 { | |
| 298 $obj = new rcube_message_header; | |
| 299 foreach ($arr as $k => $v) | |
| 300 $obj->set($k, $v); | |
| 301 | |
| 302 return $obj; | |
| 303 } | |
| 304 } | |
| 305 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
306 if (in_array('thunderbird_labels', |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
307 (rcube::get_instance()->config->get('plugins')))) |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
308 { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
309 class rcube_message_header extends r_m_h_base { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
310 public $list_flags = array(); |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
311 } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
312 } else { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
313 class rcube_message_header extends r_m_h_base { } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
314 } |
| 0 | 315 |
| 316 /** | |
| 317 * Class for sorting an array of rcube_message_header objects in a predetermined order. | |
| 318 * | |
| 319 * @package Framework | |
| 320 * @subpackage Storage | |
| 321 * @author Aleksander Machniak <alec@alec.pl> | |
| 322 */ | |
| 323 class rcube_message_header_sorter | |
| 324 { | |
| 325 private $uids = array(); | |
| 326 | |
| 327 | |
| 328 /** | |
| 329 * Set the predetermined sort order. | |
| 330 * | |
| 331 * @param array $index Numerically indexed array of IMAP UIDs | |
| 332 */ | |
| 333 function set_index($index) | |
| 334 { | |
| 335 $index = array_flip($index); | |
| 336 | |
| 337 $this->uids = $index; | |
| 338 } | |
| 339 | |
| 340 /** | |
| 341 * Sort the array of header objects | |
| 342 * | |
| 343 * @param array $headers Array of rcube_message_header objects indexed by UID | |
| 344 */ | |
| 345 function sort_headers(&$headers) | |
| 346 { | |
| 347 uksort($headers, array($this, "compare_uids")); | |
| 348 } | |
| 349 | |
| 350 /** | |
| 351 * Sort method called by uksort() | |
| 352 * | |
| 353 * @param int $a Array key (UID) | |
| 354 * @param int $b Array key (UID) | |
| 355 */ | |
| 356 function compare_uids($a, $b) | |
| 357 { | |
| 358 // then find each sequence number in my ordered list | |
| 359 $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; | |
| 360 $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; | |
| 361 | |
| 362 // return the relative position as the comparison value | |
| 363 return $posa - $posb; | |
| 364 } | |
| 365 } |
