Mercurial > hg > rc2
annotate program/lib/Roundcube/rcube_message_header.php @ 16:1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
| author | Charlie Root |
|---|---|
| date | Mon, 06 Oct 2025 10:34:51 -0400 |
| parents | 4681f974d28b |
| children | b6a96bdd6b29 |
| 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 /** | |
| 145 * IMAP internal date | |
| 146 * | |
| 147 * @var string | |
| 148 */ | |
| 149 public $internaldate; | |
| 150 | |
| 151 /** | |
| 152 * Message References header | |
| 153 * | |
| 154 * @var string | |
| 155 */ | |
| 156 public $references; | |
| 157 | |
| 158 /** | |
| 159 * Message priority (X-Priority) | |
| 160 * | |
| 161 * @var int | |
| 162 */ | |
| 163 public $priority; | |
| 164 | |
| 165 /** | |
| 166 * Message receipt recipient | |
| 167 * | |
| 168 * @var string | |
| 169 */ | |
| 170 public $mdn_to; | |
| 171 | |
| 172 /** | |
| 173 * IMAP folder this message is stored in | |
| 174 * | |
| 175 * @var string | |
| 176 */ | |
| 177 public $folder; | |
| 178 | |
| 179 /** | |
| 180 * Other message headers | |
| 181 * | |
| 182 * @var array | |
| 183 */ | |
| 184 public $others = array(); | |
| 185 | |
| 186 /** | |
| 187 * Message flags | |
| 188 * | |
| 189 * @var array | |
| 190 */ | |
| 191 public $flags = array(); | |
| 192 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
193 /** |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
194 * Threaded message property, HST added |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
195 * |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
196 * @var int |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
197 */ |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
198 public $parent_uid; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
199 |
|
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 $depth; |
|
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 array |
|
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 $has_children; |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
213 |
| 0 | 214 // map header to rcube_message_header object property |
| 215 private $obj_headers = array( | |
| 216 'date' => 'date', | |
| 217 'from' => 'from', | |
| 218 'to' => 'to', | |
| 219 'subject' => 'subject', | |
| 220 'reply-to' => 'replyto', | |
| 221 'cc' => 'cc', | |
| 222 'bcc' => 'bcc', | |
| 223 'mbox' => 'folder', | |
| 224 'folder' => 'folder', | |
| 225 'content-transfer-encoding' => 'encoding', | |
| 226 'in-reply-to' => 'in_reply_to', | |
| 227 'content-type' => 'ctype', | |
| 228 'charset' => 'charset', | |
| 229 'references' => 'references', | |
| 230 'return-receipt-to' => 'mdn_to', | |
| 231 'disposition-notification-to' => 'mdn_to', | |
| 232 'x-confirm-reading-to' => 'mdn_to', | |
| 233 'message-id' => 'messageID', | |
| 234 'x-priority' => 'priority', | |
| 235 ); | |
| 236 | |
| 237 /** | |
| 238 * Returns header value | |
| 239 */ | |
| 240 public function get($name, $decode = true) | |
| 241 { | |
| 242 $name = strtolower($name); | |
| 243 | |
| 244 if (isset($this->obj_headers[$name])) { | |
| 245 $value = $this->{$this->obj_headers[$name]}; | |
| 246 } | |
| 247 else { | |
| 248 $value = $this->others[$name]; | |
| 249 } | |
| 250 | |
| 251 if ($decode) { | |
| 252 if (is_array($value)) { | |
| 253 foreach ($value as $key => $val) { | |
| 254 $val = rcube_mime::decode_header($val, $this->charset); | |
| 255 $value[$key] = rcube_charset::clean($val); | |
| 256 } | |
| 257 } | |
| 258 else { | |
| 259 $value = rcube_mime::decode_header($value, $this->charset); | |
| 260 $value = rcube_charset::clean($value); | |
| 261 } | |
| 262 } | |
| 263 | |
| 264 return $value; | |
| 265 } | |
| 266 | |
| 267 /** | |
| 268 * Sets header value | |
| 269 */ | |
| 270 public function set($name, $value) | |
| 271 { | |
| 272 $name = strtolower($name); | |
| 273 | |
| 274 if (isset($this->obj_headers[$name])) { | |
| 275 $this->{$this->obj_headers[$name]} = $value; | |
| 276 } | |
| 277 else { | |
| 278 $this->others[$name] = $value; | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 | |
| 283 /** | |
| 284 * Factory method to instantiate headers from a data array | |
| 285 * | |
| 286 * @param array Hash array with header values | |
| 287 * @return object rcube_message_header instance filled with headers values | |
| 288 */ | |
| 289 public static function from_array($arr) | |
| 290 { | |
| 291 $obj = new rcube_message_header; | |
| 292 foreach ($arr as $k => $v) | |
| 293 $obj->set($k, $v); | |
| 294 | |
| 295 return $obj; | |
| 296 } | |
| 297 } | |
| 298 | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
299 if (in_array('thunderbird_labels', |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
300 (rcube::get_instance()->config->get('plugins')))) |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
301 { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
302 class rcube_message_header extends r_m_h_base { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
303 public $list_flags = array(); |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
304 } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
305 } else { |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
306 class rcube_message_header extends r_m_h_base { } |
|
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
0
diff
changeset
|
307 } |
| 0 | 308 |
| 309 /** | |
| 310 * Class for sorting an array of rcube_message_header objects in a predetermined order. | |
| 311 * | |
| 312 * @package Framework | |
| 313 * @subpackage Storage | |
| 314 * @author Aleksander Machniak <alec@alec.pl> | |
| 315 */ | |
| 316 class rcube_message_header_sorter | |
| 317 { | |
| 318 private $uids = array(); | |
| 319 | |
| 320 | |
| 321 /** | |
| 322 * Set the predetermined sort order. | |
| 323 * | |
| 324 * @param array $index Numerically indexed array of IMAP UIDs | |
| 325 */ | |
| 326 function set_index($index) | |
| 327 { | |
| 328 $index = array_flip($index); | |
| 329 | |
| 330 $this->uids = $index; | |
| 331 } | |
| 332 | |
| 333 /** | |
| 334 * Sort the array of header objects | |
| 335 * | |
| 336 * @param array $headers Array of rcube_message_header objects indexed by UID | |
| 337 */ | |
| 338 function sort_headers(&$headers) | |
| 339 { | |
| 340 uksort($headers, array($this, "compare_uids")); | |
| 341 } | |
| 342 | |
| 343 /** | |
| 344 * Sort method called by uksort() | |
| 345 * | |
| 346 * @param int $a Array key (UID) | |
| 347 * @param int $b Array key (UID) | |
| 348 */ | |
| 349 function compare_uids($a, $b) | |
| 350 { | |
| 351 // then find each sequence number in my ordered list | |
| 352 $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; | |
| 353 $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; | |
| 354 | |
| 355 // return the relative position as the comparison value | |
| 356 return $posa - $posb; | |
| 357 } | |
| 358 } |
