Mercurial > hg > rc2
annotate program/lib/Roundcube/rcube_message_header.php @ 22:303b85d5b561
More cleaning up php8 Warnings/deprecations
| author | Charlie Root |
|---|---|
| date | Wed, 15 Oct 2025 14:06:27 -0400 |
| parents | 73124dd49283 |
| children | c32b53434b47 |
| 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; |
| 22 | 220 public $unread_children = 0; |
| 221 public $flagged_children = 0; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
222 |
| 0 | 223 // map header to rcube_message_header object property |
| 224 private $obj_headers = array( | |
| 225 'date' => 'date', | |
| 226 'from' => 'from', | |
| 227 'to' => 'to', | |
| 228 'subject' => 'subject', | |
| 229 'reply-to' => 'replyto', | |
| 230 'cc' => 'cc', | |
| 231 'bcc' => 'bcc', | |
| 232 'mbox' => 'folder', | |
| 233 'folder' => 'folder', | |
| 234 'content-transfer-encoding' => 'encoding', | |
| 235 'in-reply-to' => 'in_reply_to', | |
| 236 'content-type' => 'ctype', | |
| 237 'charset' => 'charset', | |
| 238 'references' => 'references', | |
| 239 'return-receipt-to' => 'mdn_to', | |
| 240 'disposition-notification-to' => 'mdn_to', | |
| 241 'x-confirm-reading-to' => 'mdn_to', | |
| 242 'message-id' => 'messageID', | |
| 243 'x-priority' => 'priority', | |
| 244 ); | |
| 245 | |
| 246 /** | |
| 247 * Returns header value | |
| 248 */ | |
| 249 public function get($name, $decode = true) | |
| 250 { | |
| 251 $name = strtolower($name); | |
| 252 | |
| 253 if (isset($this->obj_headers[$name])) { | |
| 254 $value = $this->{$this->obj_headers[$name]}; | |
| 255 } | |
| 256 else { | |
| 21 | 257 $value = $this->others[$name]??null; |
| 0 | 258 } |
| 259 | |
| 260 if ($decode) { | |
| 261 if (is_array($value)) { | |
| 262 foreach ($value as $key => $val) { | |
| 263 $val = rcube_mime::decode_header($val, $this->charset); | |
| 264 $value[$key] = rcube_charset::clean($val); | |
| 265 } | |
| 266 } | |
| 267 else { | |
| 268 $value = rcube_mime::decode_header($value, $this->charset); | |
| 269 $value = rcube_charset::clean($value); | |
| 270 } | |
| 271 } | |
| 272 | |
| 273 return $value; | |
| 274 } | |
| 275 | |
| 276 /** | |
| 277 * Sets header value | |
| 278 */ | |
| 279 public function set($name, $value) | |
| 280 { | |
| 281 $name = strtolower($name); | |
| 282 | |
| 283 if (isset($this->obj_headers[$name])) { | |
| 284 $this->{$this->obj_headers[$name]} = $value; | |
| 285 } | |
| 286 else { | |
| 287 $this->others[$name] = $value; | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 | |
| 292 /** | |
| 293 * Factory method to instantiate headers from a data array | |
| 294 * | |
| 295 * @param array Hash array with header values | |
| 296 * @return object rcube_message_header instance filled with headers values | |
| 297 */ | |
| 298 public static function from_array($arr) | |
| 299 { | |
| 300 $obj = new rcube_message_header; | |
| 301 foreach ($arr as $k => $v) | |
| 302 $obj->set($k, $v); | |
| 303 | |
| 304 return $obj; | |
| 305 } | |
| 306 } | |
| 307 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
308 if (in_array('thunderbird_labels', |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
309 (rcube::get_instance()->config->get('plugins')))) |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
310 { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
311 class rcube_message_header extends r_m_h_base { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
312 public $list_flags = array(); |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
313 } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
314 } else { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
315 class rcube_message_header extends r_m_h_base { } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
316 } |
| 0 | 317 |
| 318 /** | |
| 319 * Class for sorting an array of rcube_message_header objects in a predetermined order. | |
| 320 * | |
| 321 * @package Framework | |
| 322 * @subpackage Storage | |
| 323 * @author Aleksander Machniak <alec@alec.pl> | |
| 324 */ | |
| 325 class rcube_message_header_sorter | |
| 326 { | |
| 327 private $uids = array(); | |
| 328 | |
| 329 | |
| 330 /** | |
| 331 * Set the predetermined sort order. | |
| 332 * | |
| 333 * @param array $index Numerically indexed array of IMAP UIDs | |
| 334 */ | |
| 335 function set_index($index) | |
| 336 { | |
| 337 $index = array_flip($index); | |
| 338 | |
| 339 $this->uids = $index; | |
| 340 } | |
| 341 | |
| 342 /** | |
| 343 * Sort the array of header objects | |
| 344 * | |
| 345 * @param array $headers Array of rcube_message_header objects indexed by UID | |
| 346 */ | |
| 347 function sort_headers(&$headers) | |
| 348 { | |
| 349 uksort($headers, array($this, "compare_uids")); | |
| 350 } | |
| 351 | |
| 352 /** | |
| 353 * Sort method called by uksort() | |
| 354 * | |
| 355 * @param int $a Array key (UID) | |
| 356 * @param int $b Array key (UID) | |
| 357 */ | |
| 358 function compare_uids($a, $b) | |
| 359 { | |
| 360 // then find each sequence number in my ordered list | |
| 361 $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; | |
| 362 $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; | |
| 363 | |
| 364 // return the relative position as the comparison value | |
| 365 return $posa - $posb; | |
| 366 } | |
| 367 } |
