Mercurial > hg > rc2
annotate program/lib/Roundcube/rcube_message_header.php @ 27:c32b53434b47
more compensation for deprecated empty cases
| author | Charlie Root |
|---|---|
| date | Sun, 18 Jan 2026 14:20:29 -0500 |
| parents | 303b85d5b561 |
| children |
| 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 /** | |
| 27 | 75 * Message hidden recipients (Bcc) |
| 76 * | |
| 77 * @var string | |
| 78 */ | |
| 79 public $bcc; | |
| 80 | |
| 81 /** | |
| 0 | 82 * Message Reply-To header |
| 83 * | |
| 84 * @var string | |
| 85 */ | |
| 86 public $replyto; | |
| 87 | |
| 88 /** | |
| 89 * Message In-Reply-To header | |
| 90 * | |
| 91 * @var string | |
| 92 */ | |
| 93 public $in_reply_to; | |
| 94 | |
| 95 /** | |
| 96 * Message date (Date) | |
| 97 * | |
| 98 * @var string | |
| 99 */ | |
| 100 public $date; | |
| 101 | |
| 102 /** | |
| 103 * Message identifier (Message-ID) | |
| 104 * | |
| 105 * @var string | |
| 106 */ | |
| 107 public $messageID; | |
| 108 | |
| 109 /** | |
| 110 * Message size | |
| 111 * | |
| 112 * @var int | |
| 113 */ | |
| 114 public $size; | |
| 115 | |
| 116 /** | |
| 117 * Message encoding | |
| 118 * | |
| 119 * @var string | |
| 120 */ | |
| 121 public $encoding; | |
| 122 | |
| 123 /** | |
| 124 * Message charset | |
| 125 * | |
| 126 * @var string | |
| 127 */ | |
| 128 public $charset; | |
| 129 | |
| 130 /** | |
| 131 * Message Content-type | |
| 132 * | |
| 133 * @var string | |
| 134 */ | |
| 135 public $ctype; | |
| 136 | |
| 137 /** | |
| 138 * Message timestamp (based on message date) | |
| 139 * | |
| 140 * @var int | |
| 141 */ | |
| 142 public $timestamp; | |
| 143 | |
| 144 /** | |
| 145 * IMAP bodystructure string | |
| 146 * | |
| 147 * @var string | |
| 148 */ | |
| 149 public $bodystructure; | |
| 150 | |
| 151 /** | |
| 19 | 152 * IMAP structure |
| 153 * | |
| 154 * @var rcube_message_part | |
| 155 */ | |
| 156 public $structure; | |
| 157 | |
| 158 /** | |
| 0 | 159 * IMAP internal date |
| 160 * | |
| 161 * @var string | |
| 162 */ | |
| 163 public $internaldate; | |
| 164 | |
| 165 /** | |
| 166 * Message References header | |
| 167 * | |
| 168 * @var string | |
| 169 */ | |
| 170 public $references; | |
| 171 | |
| 172 /** | |
| 173 * Message priority (X-Priority) | |
| 174 * | |
| 175 * @var int | |
| 176 */ | |
| 177 public $priority; | |
| 178 | |
| 179 /** | |
| 180 * Message receipt recipient | |
| 181 * | |
| 182 * @var string | |
| 183 */ | |
| 184 public $mdn_to; | |
| 185 | |
| 186 /** | |
| 187 * IMAP folder this message is stored in | |
| 188 * | |
| 189 * @var string | |
| 190 */ | |
| 191 public $folder; | |
| 192 | |
| 193 /** | |
| 194 * Other message headers | |
| 195 * | |
| 196 * @var array | |
| 197 */ | |
| 198 public $others = array(); | |
| 199 | |
| 200 /** | |
| 201 * Message flags | |
| 202 * | |
| 203 * @var array | |
| 204 */ | |
| 205 public $flags = array(); | |
| 206 | |
|
16
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 $parent_uid; |
|
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 int |
|
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 $depth; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
220 |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
221 /** |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
222 * Threaded message property, HST added |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
223 * |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
224 * @var array |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
225 */ |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
226 public $has_children; |
| 22 | 227 public $unread_children = 0; |
| 228 public $flagged_children = 0; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
229 |
| 0 | 230 // map header to rcube_message_header object property |
| 231 private $obj_headers = array( | |
| 232 'date' => 'date', | |
| 233 'from' => 'from', | |
| 234 'to' => 'to', | |
| 235 'subject' => 'subject', | |
| 236 'reply-to' => 'replyto', | |
| 237 'cc' => 'cc', | |
| 238 'bcc' => 'bcc', | |
| 239 'mbox' => 'folder', | |
| 240 'folder' => 'folder', | |
| 241 'content-transfer-encoding' => 'encoding', | |
| 242 'in-reply-to' => 'in_reply_to', | |
| 243 'content-type' => 'ctype', | |
| 244 'charset' => 'charset', | |
| 245 'references' => 'references', | |
| 246 'return-receipt-to' => 'mdn_to', | |
| 247 'disposition-notification-to' => 'mdn_to', | |
| 248 'x-confirm-reading-to' => 'mdn_to', | |
| 249 'message-id' => 'messageID', | |
| 250 'x-priority' => 'priority', | |
| 251 ); | |
| 252 | |
| 253 /** | |
| 254 * Returns header value | |
| 255 */ | |
| 256 public function get($name, $decode = true) | |
| 257 { | |
| 258 $name = strtolower($name); | |
| 259 | |
| 260 if (isset($this->obj_headers[$name])) { | |
| 261 $value = $this->{$this->obj_headers[$name]}; | |
| 262 } | |
| 263 else { | |
| 21 | 264 $value = $this->others[$name]??null; |
| 0 | 265 } |
| 266 | |
| 267 if ($decode) { | |
| 268 if (is_array($value)) { | |
| 269 foreach ($value as $key => $val) { | |
| 270 $val = rcube_mime::decode_header($val, $this->charset); | |
| 271 $value[$key] = rcube_charset::clean($val); | |
| 272 } | |
| 273 } | |
| 274 else { | |
| 275 $value = rcube_mime::decode_header($value, $this->charset); | |
| 276 $value = rcube_charset::clean($value); | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 return $value; | |
| 281 } | |
| 282 | |
| 283 /** | |
| 284 * Sets header value | |
| 285 */ | |
| 286 public function set($name, $value) | |
| 287 { | |
| 288 $name = strtolower($name); | |
| 289 | |
| 290 if (isset($this->obj_headers[$name])) { | |
| 291 $this->{$this->obj_headers[$name]} = $value; | |
| 292 } | |
| 293 else { | |
| 294 $this->others[$name] = $value; | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 | |
| 299 /** | |
| 300 * Factory method to instantiate headers from a data array | |
| 301 * | |
| 302 * @param array Hash array with header values | |
| 303 * @return object rcube_message_header instance filled with headers values | |
| 304 */ | |
| 305 public static function from_array($arr) | |
| 306 { | |
| 307 $obj = new rcube_message_header; | |
| 308 foreach ($arr as $k => $v) | |
| 309 $obj->set($k, $v); | |
| 310 | |
| 311 return $obj; | |
| 312 } | |
| 313 } | |
| 314 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
315 if (in_array('thunderbird_labels', |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
316 (rcube::get_instance()->config->get('plugins')))) |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
317 { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
318 class rcube_message_header extends r_m_h_base { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
319 public $list_flags = array(); |
| 27 | 320 public $sortKey = null; |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
321 } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
322 } else { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
323 class rcube_message_header extends r_m_h_base { } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
324 } |
| 0 | 325 |
| 326 /** | |
| 327 * Class for sorting an array of rcube_message_header objects in a predetermined order. | |
| 328 * | |
| 329 * @package Framework | |
| 330 * @subpackage Storage | |
| 331 * @author Aleksander Machniak <alec@alec.pl> | |
| 332 */ | |
| 333 class rcube_message_header_sorter | |
| 334 { | |
| 335 private $uids = array(); | |
| 336 | |
| 337 | |
| 338 /** | |
| 339 * Set the predetermined sort order. | |
| 340 * | |
| 341 * @param array $index Numerically indexed array of IMAP UIDs | |
| 342 */ | |
| 343 function set_index($index) | |
| 344 { | |
| 345 $index = array_flip($index); | |
| 346 | |
| 347 $this->uids = $index; | |
| 348 } | |
| 349 | |
| 350 /** | |
| 351 * Sort the array of header objects | |
| 352 * | |
| 353 * @param array $headers Array of rcube_message_header objects indexed by UID | |
| 354 */ | |
| 355 function sort_headers(&$headers) | |
| 356 { | |
| 357 uksort($headers, array($this, "compare_uids")); | |
| 358 } | |
| 359 | |
| 360 /** | |
| 361 * Sort method called by uksort() | |
| 362 * | |
| 363 * @param int $a Array key (UID) | |
| 364 * @param int $b Array key (UID) | |
| 365 */ | |
| 366 function compare_uids($a, $b) | |
| 367 { | |
| 368 // then find each sequence number in my ordered list | |
| 369 $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; | |
| 370 $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; | |
| 371 | |
| 372 // return the relative position as the comparison value | |
| 373 return $posa - $posb; | |
| 374 } | |
| 375 } |
