Mercurial > hg > rc2
annotate program/steps/mail/func.inc @ 21:73124dd49283
More cleaning up php8 Warnings/deprecations,
noticed that setting non-my-Dates mailboxes to sort on Date isn't sticky over ctrl-R
| author | Charlie Root |
|---|---|
| date | Thu, 09 Oct 2025 11:31:41 -0400 |
| parents | b6a96bdd6b29 |
| children | 303b85d5b561 |
| rev | line source |
|---|---|
| 0 | 1 <?php |
| 2 | |
| 3 /** | |
| 4 +-----------------------------------------------------------------------+ | |
| 5 | program/steps/mail/func.inc | | |
| 6 | | | |
| 7 | This file is part of the Roundcube Webmail client | | |
| 8 | Copyright (C) 2005-2014, The Roundcube Dev Team | | |
| 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 | Provide webmail functionality and GUI objects | | |
| 16 | | | |
| 17 +-----------------------------------------------------------------------+ | |
| 18 | Author: Thomas Bruederli <roundcube@gmail.com> | | |
| 19 | Author: Aleksander Machniak <alec@alec.pl> | | |
| 20 +-----------------------------------------------------------------------+ | |
| 21 */ | |
| 22 | |
| 23 // always instantiate storage object (but not connect to server yet) | |
| 24 $RCMAIL->storage_init(); | |
| 25 | |
| 26 // init environment - set current folder, page, list mode | |
| 27 rcmail_init_env(); | |
| 28 | |
| 29 // set message set for search result | |
| 30 if (!empty($_REQUEST['_search']) && isset($_SESSION['search']) | |
| 31 && $_SESSION['search_request'] == $_REQUEST['_search'] | |
| 32 ) { | |
| 33 $RCMAIL->storage->set_search_set($_SESSION['search']); | |
| 34 | |
| 35 $OUTPUT->set_env('search_request', $_REQUEST['_search']); | |
| 36 $OUTPUT->set_env('search_text', $_SESSION['last_text_search']); | |
| 37 } | |
| 38 | |
| 39 // remove mbox part from _uid | |
| 40 if (($_uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)) && !is_array($_uid) && preg_match('/^\d+-.+/', $_uid)) { | |
| 41 list($_uid, $mbox) = explode('-', $_uid, 2); | |
| 42 if (isset($_GET['_uid'])) $_GET['_uid'] = $_uid; | |
| 43 if (isset($_POST['_uid'])) $_POST['_uid'] = $_uid; | |
| 44 $_REQUEST['_uid'] = $_uid; | |
| 45 unset($_uid); | |
| 46 | |
| 47 // override mbox | |
| 48 if (!empty($mbox)) { | |
| 49 $_GET['_mbox'] = $mbox; | |
| 50 $_POST['_mbox'] = $mbox; | |
| 51 $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox)); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 if (!empty($_SESSION['browser_caps']) && !$OUTPUT->ajax_call) { | |
| 56 $OUTPUT->set_env('browser_capabilities', $_SESSION['browser_caps']); | |
| 57 } | |
| 58 | |
| 59 // set main env variables, labels and page title | |
| 60 if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { | |
| 61 // connect to storage server and trigger error on failure | |
| 62 $RCMAIL->storage_connect(); | |
| 63 | |
| 64 $mbox_name = $RCMAIL->storage->get_folder(); | |
| 65 | |
| 66 if (empty($RCMAIL->action)) { | |
| 67 $OUTPUT->set_env('search_mods', rcmail_search_mods()); | |
| 68 | |
| 69 if (!empty($_SESSION['search_scope'])) | |
| 70 $OUTPUT->set_env('search_scope', $_SESSION['search_scope']); | |
| 71 | |
| 72 rcmail_list_pagetitle(); | |
| 73 } | |
| 74 | |
| 75 $threading = (bool) $RCMAIL->storage->get_threading(); | |
| 76 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); | |
| 77 | |
| 78 // set current mailbox and some other vars in client environment | |
| 79 $OUTPUT->set_env('mailbox', $mbox_name); | |
| 80 $OUTPUT->set_env('pagesize', $RCMAIL->storage->get_pagesize()); | |
| 19 | 81 $OUTPUT->set_env('current_page', max(1, ($_SESSION['page']??0))); |
| 0 | 82 $OUTPUT->set_env('delimiter', $delimiter); |
| 83 $OUTPUT->set_env('threading', $threading); | |
| 84 $OUTPUT->set_env('threads', $threading || $RCMAIL->storage->get_capability('THREAD')); | |
| 85 $OUTPUT->set_env('reply_all_mode', (int) $RCMAIL->config->get('reply_all_mode')); | |
| 86 $OUTPUT->set_env('layout', $RCMAIL->config->get('layout') ?: 'widescreen'); | |
| 87 | |
| 88 if ($RCMAIL->storage->get_capability('QUOTA')) { | |
| 89 $OUTPUT->set_env('quota', true); | |
| 90 } | |
| 91 | |
| 92 // set special folders | |
| 93 foreach (array('drafts', 'trash', 'junk') as $mbox) { | |
| 94 if ($folder = $RCMAIL->config->get($mbox . '_mbox')) { | |
| 95 $OUTPUT->set_env($mbox . '_mailbox', $folder); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 if (!empty($_GET['_uid'])) { | |
| 100 $OUTPUT->set_env('list_uid', $_GET['_uid']); | |
| 101 } | |
| 102 | |
| 103 // set configuration | |
| 104 $RCMAIL->set_env_config(array('delete_junk', 'flag_for_deletion', 'read_when_deleted', | |
| 105 'skip_deleted', 'display_next', 'message_extwin', 'forward_attachment')); | |
| 106 | |
| 107 if (!$OUTPUT->ajax_call) { | |
| 108 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', | |
| 109 'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage', | |
| 110 'copy', 'move', 'quota', 'replyall', 'replylist', 'stillsearching', | |
| 111 'flagged', 'unflagged', 'unread', 'deleted', 'replied', 'forwarded', | |
| 112 'priority', 'withattachment', 'fileuploaderror', 'mark', 'markallread', | |
| 113 'folders-cur', 'folders-sub', 'folders-all', 'cancel'); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 // register UI objects | |
| 118 $OUTPUT->add_handlers(array( | |
| 119 'mailboxlist' => array($RCMAIL, 'folder_list'), | |
| 120 'quotadisplay' => array($RCMAIL, 'quota_display'), | |
| 121 'messages' => 'rcmail_message_list', | |
| 122 'messagecountdisplay' => 'rcmail_messagecount_display', | |
| 123 'listmenulink' => 'rcmail_options_menu_link', | |
| 124 'mailboxname' => 'rcmail_mailbox_name_display', | |
| 125 'messageheaders' => 'rcmail_message_headers', | |
| 126 'messagefullheaders' => 'rcmail_message_full_headers', | |
| 127 'messagebody' => 'rcmail_message_body', | |
| 128 'messagecontentframe' => 'rcmail_messagecontent_frame', | |
| 129 'messageimportform' => 'rcmail_message_import_form', | |
| 130 'searchfilter' => 'rcmail_search_filter', | |
| 131 'searchinterval' => 'rcmail_search_interval', | |
| 132 'searchform' => array($OUTPUT, 'search_form'), | |
| 133 )); | |
| 134 | |
| 135 // register action aliases | |
| 136 $RCMAIL->register_action_map(array( | |
| 137 'refresh' => 'check_recent.inc', | |
| 138 'preview' => 'show.inc', | |
| 139 'print' => 'show.inc', | |
| 140 'move' => 'move_del.inc', | |
| 141 'delete' => 'move_del.inc', | |
| 142 'send' => 'sendmail.inc', | |
| 143 'expunge' => 'folders.inc', | |
| 144 'purge' => 'folders.inc', | |
| 145 'remove-attachment' => 'attachments.inc', | |
| 146 'rename-attachment' => 'attachments.inc', | |
| 147 'display-attachment' => 'attachments.inc', | |
| 148 'upload' => 'attachments.inc', | |
| 149 'group-expand' => 'autocomplete.inc', | |
| 150 )); | |
| 151 | |
| 152 | |
| 153 /** | |
| 154 * Sets storage properties and session | |
| 155 */ | |
| 156 function rcmail_init_env() | |
| 157 { | |
| 158 global $RCMAIL; | |
| 159 | |
| 160 $default_threading = $RCMAIL->config->get('default_list_mode', 'list') == 'threads'; | |
| 161 $a_threading = $RCMAIL->config->get('message_threading', array()); | |
| 162 $message_sort_col = $RCMAIL->config->get('message_sort_col'); | |
| 163 $message_sort_order = $RCMAIL->config->get('message_sort_order'); | |
| 164 | |
| 165 // set imap properties and session vars | |
| 19 | 166 $mbox = (rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true)??null) ?: (!empty($_SESSION['mbox']) ? $_SESSION['mbox'] : 'INBOX'); |
| 0 | 167 |
| 168 // we handle 'page' argument on 'list' and 'getunread' to prevent from | |
| 169 // race condition and unintentional page overwrite in session | |
| 170 if ($RCMAIL->action == 'list' || $RCMAIL->action == 'getunread') { | |
| 19 | 171 if (!($page = intval($_GET['_page']??null))) { |
| 172 $page = ($_SESSION['page']??null) ?: 1; | |
| 0 | 173 } |
| 174 | |
| 175 $_SESSION['page'] = $page; | |
| 176 } | |
| 177 | |
| 178 $RCMAIL->storage->set_folder($_SESSION['mbox'] = $mbox); | |
| 19 | 179 $RCMAIL->storage->set_page($_SESSION['page']??null); |
| 0 | 180 |
| 181 // set default sort col/order to session | |
| 182 if (!isset($_SESSION['sort_col'])) { | |
| 183 $_SESSION['sort_col'] = $message_sort_col ?: ''; | |
| 184 } | |
| 185 if (!isset($_SESSION['sort_order'])) { | |
| 186 $_SESSION['sort_order'] = strtoupper($message_sort_order) == 'ASC' ? 'ASC' : 'DESC'; | |
| 187 } | |
| 188 | |
| 189 // set threads mode | |
| 190 if (isset($_GET['_threads'])) { | |
| 191 if ($_GET['_threads']) { | |
| 192 // re-set current page number when listing mode changes | |
| 193 if (!$a_threading[$_SESSION['mbox']]) { | |
| 194 $RCMAIL->storage->set_page($_SESSION['page'] = 1); | |
| 195 } | |
| 196 | |
| 197 $a_threading[$_SESSION['mbox']] = true; | |
| 198 } | |
| 199 else { | |
| 200 // re-set current page number when listing mode changes | |
| 201 if ($a_threading[$_SESSION['mbox']]) { | |
| 202 $RCMAIL->storage->set_page($_SESSION['page'] = 1); | |
| 203 } | |
| 204 | |
| 205 $a_threading[$_SESSION['mbox']] = false; | |
| 206 } | |
| 207 | |
| 208 $RCMAIL->user->save_prefs(array('message_threading' => $a_threading)); | |
| 209 } | |
| 210 | |
| 211 $threading = isset($a_threading[$_SESSION['mbox']]) ? $a_threading[$_SESSION['mbox']] : $default_threading; | |
| 212 | |
| 213 $RCMAIL->storage->set_threading($threading); | |
| 214 } | |
| 215 | |
| 216 /** | |
| 217 * Sets page title | |
| 218 */ | |
| 219 function rcmail_list_pagetitle() | |
| 220 { | |
| 221 global $RCMAIL; | |
| 222 | |
| 223 if ($RCMAIL->output->get_env('search_request')) { | |
| 224 $pagetitle = $RCMAIL->gettext('searchresult'); | |
| 225 } | |
| 226 else { | |
| 227 $mbox_name = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder(); | |
| 228 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); | |
| 229 $pagetitle = $RCMAIL->localize_foldername($mbox_name, true); | |
| 230 $pagetitle = str_replace($delimiter, " \xC2\xBB ", $pagetitle); | |
| 231 } | |
| 232 | |
| 233 $RCMAIL->output->set_pagetitle($pagetitle); | |
| 234 } | |
| 235 | |
| 236 /** | |
| 237 * Returns default search mods | |
| 238 */ | |
| 239 function rcmail_search_mods() | |
| 240 { | |
| 241 global $RCMAIL; | |
| 242 | |
| 243 $mods = $RCMAIL->config->get('search_mods'); | |
| 244 | |
| 245 if (empty($mods)) { | |
| 246 $mods = array('*' => array('subject' => 1, 'from' => 1)); | |
| 247 | |
| 248 foreach (array('sent', 'drafts') as $mbox) { | |
| 249 if ($mbox = $RCMAIL->config->get($mbox . '_mbox')) { | |
| 250 $mods[$mbox] = array('subject' => 1, 'to' => 1); | |
| 251 } | |
| 252 } | |
| 253 } | |
| 254 | |
| 255 return $mods; | |
| 256 } | |
| 257 | |
| 258 /** | |
| 259 * Returns 'to' if current folder is configured Sent or Drafts | |
| 260 * or their subfolders, otherwise returns 'from'. | |
| 261 * | |
| 262 * @return string Column name | |
| 263 */ | |
| 264 function rcmail_message_list_smart_column_name() | |
| 265 { | |
| 266 global $RCMAIL; | |
| 267 | |
| 268 $delim = $RCMAIL->storage->get_hierarchy_delimiter(); | |
| 269 $mbox = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder(); | |
| 270 $sent_mbox = $RCMAIL->config->get('sent_mbox'); | |
| 271 $drafts_mbox = $RCMAIL->config->get('drafts_mbox'); | |
| 272 | |
| 273 if ((strpos($mbox.$delim, $sent_mbox.$delim) === 0 || strpos($mbox.$delim, $drafts_mbox.$delim) === 0) | |
| 274 && strtoupper($mbox) != 'INBOX' | |
| 275 ) { | |
| 276 return 'to'; | |
| 277 } | |
| 278 | |
| 279 return 'from'; | |
| 280 } | |
| 281 | |
| 282 /** | |
| 283 * Returns configured messages list sorting column name | |
| 284 * The name is context-sensitive, which means if sorting is set to 'fromto' | |
| 285 * it will return 'from' or 'to' according to current folder type. | |
| 286 * | |
| 287 * @return string Column name | |
| 288 */ | |
| 289 function rcmail_sort_column() | |
| 290 { | |
| 291 global $RCMAIL; | |
| 292 | |
| 293 if (isset($_SESSION['sort_col'])) { | |
| 294 $column = $_SESSION['sort_col']; | |
| 295 } | |
| 296 else { | |
| 297 $column = $RCMAIL->config->get('message_sort_col'); | |
| 298 } | |
| 299 | |
| 300 // get name of smart From/To column in folder context | |
| 301 if ($column == 'fromto') { | |
| 302 $column = rcmail_message_list_smart_column_name(); | |
| 303 } | |
| 304 | |
| 305 return $column; | |
| 306 } | |
| 307 | |
| 308 /** | |
| 309 * Returns configured message list sorting order | |
| 310 * | |
| 311 * @return string Sorting order (ASC|DESC) | |
| 312 */ | |
| 313 function rcmail_sort_order() | |
| 314 { | |
| 315 global $RCMAIL; | |
| 316 | |
| 317 if (isset($_SESSION['sort_order'])) { | |
| 318 return $_SESSION['sort_order']; | |
| 319 } | |
| 320 | |
| 321 return $RCMAIL->config->get('message_sort_order'); | |
| 322 } | |
| 323 | |
| 324 /** | |
| 325 * return the message list as HTML table | |
| 326 */ | |
| 327 function rcmail_message_list($attrib) | |
| 328 { | |
| 329 global $RCMAIL, $OUTPUT; | |
| 330 | |
| 331 // add some labels to client | |
| 332 $OUTPUT->add_label('from', 'to'); | |
| 333 | |
| 334 // add id to message list table if not specified | |
| 335 if (!strlen($attrib['id'])) { | |
| 336 $attrib['id'] = 'rcubemessagelist'; | |
| 337 } | |
| 338 | |
| 339 // define list of cols to be displayed based on parameter or config | |
| 340 if (empty($attrib['columns'])) { | |
| 341 $list_cols = $RCMAIL->config->get('list_cols'); | |
| 342 $a_show_cols = !empty($list_cols) && is_array($list_cols) ? $list_cols : array('subject'); | |
| 343 | |
| 344 $OUTPUT->set_env('col_movable', !in_array('list_cols', (array)$RCMAIL->config->get('dont_override'))); | |
| 345 } | |
| 346 else { | |
| 347 $a_show_cols = preg_split('/[\s,;]+/', str_replace(array("'", '"'), '', $attrib['columns'])); | |
| 348 $attrib['columns'] = $a_show_cols; | |
| 349 } | |
| 350 | |
| 351 // save some variables for use in ajax list | |
| 352 $_SESSION['list_attrib'] = $attrib; | |
| 353 | |
| 354 // make sure 'threads' and 'subject' columns are present | |
| 355 if (!in_array('subject', $a_show_cols)) | |
| 356 array_unshift($a_show_cols, 'subject'); | |
| 357 if (!in_array('threads', $a_show_cols)) | |
| 358 array_unshift($a_show_cols, 'threads'); | |
| 359 | |
| 360 $listcols = $a_show_cols; | |
| 361 | |
| 362 // Widescreen layout uses hardcoded list of columns | |
| 363 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') { | |
| 364 $a_show_cols = array('threads', 'subject', 'fromto', 'date', 'flag', 'attachment'); | |
| 365 $listcols = $a_show_cols; | |
| 366 array_shift($listcols); | |
| 367 } | |
| 368 | |
| 369 // set client env | |
| 370 $OUTPUT->add_gui_object('messagelist', $attrib['id']); | |
| 371 $OUTPUT->set_env('autoexpand_threads', intval($RCMAIL->config->get('autoexpand_threads'))); | |
| 372 $OUTPUT->set_env('sort_col', $_SESSION['sort_col']); | |
| 373 $OUTPUT->set_env('sort_order', $_SESSION['sort_order']); | |
| 374 $OUTPUT->set_env('messages', array()); | |
| 375 $OUTPUT->set_env('listcols', $listcols); | |
| 376 | |
| 377 $OUTPUT->include_script('list.js'); | |
| 378 | |
| 379 $table = new html_table($attrib); | |
| 380 | |
| 19 | 381 if (empty($attrib['noheader'])) { |
| 0 | 382 foreach (rcmail_message_list_head($attrib, $a_show_cols) as $cell) |
| 383 $table->add_header(array('class' => $cell['className'], 'id' => $cell['id']), $cell['html']); | |
| 384 } | |
| 385 | |
| 386 return $table->show(); | |
| 387 } | |
| 388 | |
| 389 /** | |
| 390 * return javascript commands to add rows to the message list | |
| 391 */ | |
| 392 function rcmail_js_message_list($a_headers, $insert_top=false, $a_show_cols=null) | |
| 393 { | |
| 2 | 394 // Will _not_ have been sorted if sort_col is a flag param, e.g. dates |
| 0 | 395 global $RCMAIL, $OUTPUT; |
| 396 | |
| 397 if (empty($a_show_cols)) { | |
| 398 if (!empty($_SESSION['list_attrib']['columns'])) | |
| 399 $a_show_cols = $_SESSION['list_attrib']['columns']; | |
| 400 else { | |
| 401 $list_cols = $RCMAIL->config->get('list_cols'); | |
| 402 $a_show_cols = !empty($list_cols) && is_array($list_cols) ? $list_cols : array('subject'); | |
| 403 } | |
| 404 } | |
| 405 else { | |
| 406 if (!is_array($a_show_cols)) { | |
| 407 $a_show_cols = preg_split('/[\s,;]+/', str_replace(array("'", '"'), '', $a_show_cols)); | |
| 408 } | |
| 409 $head_replace = true; | |
| 410 } | |
| 411 | |
| 412 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter(); | |
| 413 $search_set = $RCMAIL->storage->get_search_set(); | |
| 414 $multifolder = $search_set && $search_set[1]->multi; | |
| 415 | |
| 416 // add/remove 'folder' column to the list on multi-folder searches | |
| 417 if ($multifolder && !in_array('folder', $a_show_cols)) { | |
| 418 $a_show_cols[] = 'folder'; | |
| 419 $head_replace = true; | |
| 420 } | |
| 421 else if (!$multifolder && ($found = array_search('folder', $a_show_cols)) !== false) { | |
| 422 unset($a_show_cols[$found]); | |
| 423 $head_replace = true; | |
| 424 } | |
| 425 | |
| 426 $mbox = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder(); | |
| 427 | |
| 428 // make sure 'threads' and 'subject' columns are present | |
| 429 if (!in_array('subject', $a_show_cols)) | |
| 430 array_unshift($a_show_cols, 'subject'); | |
| 431 if (!in_array('threads', $a_show_cols)) | |
| 432 array_unshift($a_show_cols, 'threads'); | |
| 433 | |
| 434 // Make sure there are no duplicated columns (#1486999) | |
| 435 $a_show_cols = array_unique($a_show_cols); | |
| 436 $_SESSION['list_attrib']['columns'] = $a_show_cols; | |
| 437 | |
| 438 // Widescreen layout uses hardcoded list of columns | |
| 439 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') { | |
| 440 $a_show_cols = array('threads', 'subject', 'fromto', 'date', 'flag', 'attachment'); | |
| 441 } | |
| 442 | |
| 443 // Plugins may set header's list_cols/list_flags and other rcube_message_header variables | |
| 444 // and list columns | |
| 5 | 445 #rcube::write_log('thunderbird_labels','t? |'.$RCMAIL->storage->get_threading().'|'); |
| 0 | 446 $plugin = $RCMAIL->plugins->exec_hook('messages_list', |
| 5 | 447 array('messages' => $a_headers, 'cols' => $a_show_cols)); |
| 0 | 448 |
| 449 $a_show_cols = $plugin['cols']; | |
| 450 $a_headers = $plugin['messages']; | |
| 2 | 451 #rcube::write_log('thunderbird_labels','plugh: '.print_r($a_headers,true)); |
| 0 | 452 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') { |
| 453 if (!$RCMAIL->storage->get_threading()) { | |
| 454 if (($idx = array_search('threads', $a_show_cols)) !== false) { | |
| 455 unset($a_show_cols[$idx]); | |
| 456 } | |
| 457 } | |
| 458 } | |
| 459 | |
| 19 | 460 $thead = !empty($head_replace) ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL; |
| 0 | 461 |
| 462 // get name of smart From/To column in folder context | |
| 463 if (array_search('fromto', $a_show_cols) !== false) { | |
| 464 $smart_col = rcmail_message_list_smart_column_name(); | |
| 465 } | |
| 466 | |
| 467 $OUTPUT->command('set_message_coltypes', array_values($a_show_cols), $thead, $smart_col); | |
| 468 | |
| 469 if ($multifolder && $_SESSION['search_scope'] == 'all') { | |
| 470 $OUTPUT->command('select_folder', ''); | |
| 471 } | |
| 472 | |
| 473 $OUTPUT->set_env('multifolder_listing', $multifolder); | |
| 474 | |
| 475 if (empty($a_headers)) { | |
| 476 return; | |
| 477 } | |
| 478 | |
| 479 // remove 'threads', 'attachment', 'flag', 'status' columns, we don't need them here | |
| 480 foreach (array('threads', 'attachment', 'flag', 'status', 'priority') as $col) { | |
| 481 if (($key = array_search($col, $a_show_cols)) !== FALSE) { | |
| 482 unset($a_show_cols[$key]); | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 $sort_col = $_SESSION['sort_col']; | |
| 487 | |
| 488 // loop through message headers | |
| 489 foreach ($a_headers as $header) { | |
| 490 if (empty($header) || !$header->size) { | |
| 491 continue; | |
| 492 } | |
| 493 | |
| 494 // make message UIDs unique by appending the folder name | |
| 495 if ($multifolder) { | |
| 496 $header->uid .= '-'.$header->folder; | |
| 497 $header->flags['skip_mbox_check'] = true; | |
| 498 if ($header->parent_uid) | |
| 499 $header->parent_uid .= '-'.$header->folder; | |
| 500 } | |
| 501 | |
| 502 $a_msg_cols = array(); | |
| 503 $a_msg_flags = array(); | |
| 504 | |
| 505 // format each col; similar as in rcmail_message_list() | |
| 506 foreach ($a_show_cols as $col) { | |
| 507 $col_name = $col == 'fromto' ? $smart_col : $col; | |
| 508 | |
| 509 if (in_array($col_name, array('from', 'to', 'cc', 'replyto'))) { | |
| 510 $cont = rcmail_address_string($header->$col_name, 3, false, null, $header->charset); | |
| 511 if (empty($cont)) $cont = ' '; // for widescreen mode | |
| 512 } | |
| 513 else if ($col == 'subject') { | |
| 514 $cont = trim(rcube_mime::decode_header($header->$col, $header->charset)); | |
| 515 if (!$cont) $cont = $RCMAIL->gettext('nosubject'); | |
| 516 $cont = rcube::Q($cont); | |
| 517 } | |
| 518 else if ($col == 'size') | |
| 519 $cont = $RCMAIL->show_bytes($header->$col); | |
| 520 else if ($col == 'date') | |
| 521 $cont = $RCMAIL->format_date($sort_col == 'arrival' ? $header->internaldate : $header->date); | |
| 522 else if ($col == 'folder') { | |
| 523 if ($last_folder !== $header->folder) { | |
| 524 $last_folder = $header->folder; | |
| 525 $last_folder_name = $RCMAIL->localize_foldername($last_folder, true); | |
| 526 $last_folder_name = str_replace($delimiter, " \xC2\xBB ", $last_folder_name); | |
| 527 } | |
| 528 | |
| 529 $cont = rcube::Q($last_folder_name); | |
| 530 } | |
| 531 else | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
532 $cont = rcube::Q($header->$col??null); |
| 0 | 533 |
| 534 $a_msg_cols[$col] = $cont; | |
| 535 } | |
| 536 | |
| 537 $a_msg_flags = array_change_key_case(array_map('intval', (array) $header->flags)); | |
| 538 if ($header->depth) | |
| 539 $a_msg_flags['depth'] = $header->depth; | |
| 540 else if ($header->has_children) | |
| 541 $roots[] = $header->uid; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
542 if ($header->parent_uid??null) |
| 0 | 543 $a_msg_flags['parent_uid'] = $header->parent_uid; |
| 544 if ($header->has_children) | |
| 545 $a_msg_flags['has_children'] = $header->has_children; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
546 if ($header->unread_children??null) |
| 0 | 547 $a_msg_flags['unread_children'] = $header->unread_children; |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
548 if ($header->flagged_children??null) |
| 0 | 549 $a_msg_flags['flagged_children'] = $header->flagged_children; |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
550 if ($header->others['list-post']??null) |
| 0 | 551 $a_msg_flags['ml'] = 1; |
| 552 if ($header->priority) | |
| 553 $a_msg_flags['prio'] = (int) $header->priority; | |
| 554 | |
| 555 $a_msg_flags['ctype'] = rcube::Q($header->ctype); | |
| 556 $a_msg_flags['mbox'] = $header->folder; | |
| 557 | |
| 558 // merge with plugin result (Deprecated, use $header->flags) | |
| 559 if (!empty($header->list_flags) && is_array($header->list_flags)) | |
| 560 $a_msg_flags = array_merge($a_msg_flags, $header->list_flags); | |
| 561 if (!empty($header->list_cols) && is_array($header->list_cols)) | |
| 562 $a_msg_cols = array_merge($a_msg_cols, $header->list_cols); | |
| 563 | |
| 564 $OUTPUT->command('add_message_row', $header->uid, $a_msg_cols, $a_msg_flags, $insert_top); | |
| 565 } | |
| 566 | |
| 567 if ($RCMAIL->storage->get_threading()) { | |
| 21 | 568 $OUTPUT->command('init_threads', isset($roots) ? (array)$roots: array(), |
| 569 $mbox); | |
| 0 | 570 } |
| 571 } | |
| 572 | |
| 573 /* | |
| 574 * Creates <THEAD> for message list table | |
| 575 */ | |
| 576 function rcmail_message_list_head($attrib, $a_show_cols) | |
| 577 { | |
| 578 global $RCMAIL; | |
| 579 | |
| 580 // check to see if we have some settings for sorting | |
| 581 $sort_col = $_SESSION['sort_col']; | |
| 582 $sort_order = $_SESSION['sort_order']; | |
| 583 | |
| 584 $dont_override = (array) $RCMAIL->config->get('dont_override'); | |
| 585 $disabled_sort = in_array('message_sort_col', $dont_override); | |
| 586 $disabled_order = in_array('message_sort_order', $dont_override); | |
| 587 | |
| 588 $RCMAIL->output->set_env('disabled_sort_col', $disabled_sort); | |
| 589 $RCMAIL->output->set_env('disabled_sort_order', $disabled_order); | |
| 590 | |
| 591 // define sortable columns | |
| 592 if ($disabled_sort) | |
| 593 $a_sort_cols = $sort_col && !$disabled_order ? array($sort_col) : array(); | |
| 594 else | |
| 2 | 595 $a_sort_cols = array('subject', 'date', 'from', 'to', 'fromto', 'size', 'cc','dates'); |
| 596 | |
| 597 #rcube::write_log('mail','asc: '.print_r($a_sort_cols,true)); | |
| 0 | 598 if (!empty($attrib['optionsmenuicon'])) { |
| 599 $list_menu = rcmail_options_menu_link($attrib); | |
| 600 } | |
| 601 | |
| 602 $cells = $coltypes = array(); | |
| 603 | |
| 604 // get name of smart From/To column in folder context | |
| 605 if (array_search('fromto', $a_show_cols) !== false) { | |
| 606 $smart_col = rcmail_message_list_smart_column_name(); | |
| 607 } | |
| 608 | |
| 609 foreach ($a_show_cols as $col) { | |
| 610 $label = ''; | |
| 611 $sortable = false; | |
| 612 $rel_col = $col == 'date' && $sort_col == 'arrival' ? 'arrival' : $col; | |
| 613 | |
| 614 // get column name | |
| 615 switch ($col) { | |
| 616 case 'flag': | |
| 617 $col_name = html::span('flagged', $RCMAIL->gettext('flagged')); | |
| 618 break; | |
| 619 case 'attachment': | |
| 620 case 'priority': | |
| 621 $col_name = html::span($col, $RCMAIL->gettext($col)); | |
| 622 break; | |
| 623 case 'status': | |
| 624 $col_name = html::span($col, $RCMAIL->gettext('readstatus')); | |
| 625 break; | |
| 626 case 'threads': | |
| 627 $col_name = (string) $list_menu; | |
| 628 break; | |
| 629 case 'fromto': | |
| 630 $label = $RCMAIL->gettext($smart_col); | |
| 631 $col_name = rcube::Q($label); | |
| 632 break; | |
| 633 default: | |
| 634 $label = $RCMAIL->gettext($col); | |
| 635 $col_name = rcube::Q($label); | |
| 636 } | |
| 637 | |
| 638 // make sort links | |
| 639 if (in_array($col, $a_sort_cols)) { | |
| 640 $sortable = true; | |
| 641 $col_name = html::a(array( | |
| 642 'href' => "./#sort", | |
| 643 'class' => 'sortcol', | |
| 644 'rel' => $rel_col, | |
| 645 'title' => $RCMAIL->gettext('sortby') | |
| 646 ), $col_name); | |
| 647 } | |
| 648 else if ($col_name[0] != '<') { | |
| 649 $col_name = '<span class="' . $col .'">' . $col_name . '</span>'; | |
| 650 } | |
| 651 | |
| 652 $sort_class = $rel_col == $sort_col && !$disabled_order ? " sorted$sort_order" : ''; | |
| 653 $class_name = $col.$sort_class; | |
| 654 | |
| 655 // put it all together | |
| 656 $cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name); | |
| 657 $coltypes[$col] = array('className' => $class_name, 'id' => "rcm$col", 'label' => $label, 'sortable' => $sortable); | |
| 658 } | |
| 659 | |
| 660 $RCMAIL->output->set_env('coltypes', $coltypes); | |
| 661 return $cells; | |
| 662 } | |
| 663 | |
| 664 function rcmail_options_menu_link($attrib) | |
| 665 { | |
| 666 global $RCMAIL; | |
| 667 | |
| 668 $onclick = 'return ' . rcmail_output::JS_OBJECT_NAME . ".command('menu-open', 'messagelistmenu', this, event)"; | |
| 669 $inner = $title = $RCMAIL->gettext('listoptions'); | |
| 670 | |
| 671 if (is_string($attrib['optionsmenuicon']) && $attrib['optionsmenuicon'] != 'true') { | |
| 672 $inner = html::img(array('src' => $RCMAIL->output->abs_url($attrib['optionsmenuicon'], true), 'alt' => $title)); | |
| 673 } | |
| 674 | |
| 675 return html::a(array( | |
| 676 'href' => '#list-options', | |
| 677 'onclick' => $onclick, | |
| 678 'class' => 'listmenu', | |
| 679 'id' => 'listmenulink', | |
| 680 'title' => $title, | |
| 681 'tabindex' => '0', | |
| 682 ), $inner); | |
| 683 } | |
| 684 | |
| 685 /** | |
| 686 * Return an HTML iframe for loading mail content | |
| 687 */ | |
| 688 function rcmail_messagecontent_frame($attrib) | |
| 689 { | |
| 690 global $OUTPUT; | |
| 691 | |
| 692 if (empty($attrib['id'])) { | |
| 693 $attrib['id'] = 'rcmailcontentwindow'; | |
| 694 } | |
| 695 | |
| 696 return $OUTPUT->frame($attrib, true); | |
| 697 } | |
| 698 | |
| 699 function rcmail_messagecount_display($attrib) | |
| 700 { | |
| 701 global $RCMAIL; | |
| 702 | |
| 19 | 703 if (empty($attrib['id'])) { |
| 0 | 704 $attrib['id'] = 'rcmcountdisplay'; |
| 705 } | |
| 706 | |
| 707 $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']); | |
| 708 | |
| 709 $content = $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : $RCMAIL->gettext('loading'); | |
| 710 | |
| 711 return html::span($attrib, $content); | |
| 712 } | |
| 713 | |
| 714 function rcmail_get_messagecount_text($count = null, $page = null) | |
| 715 { | |
| 716 global $RCMAIL; | |
| 717 | |
| 718 if ($page === null) { | |
| 719 $page = $RCMAIL->storage->get_page(); | |
| 720 } | |
| 721 | |
| 722 $page_size = $RCMAIL->storage->get_pagesize(); | |
| 723 $start_msg = ($page-1) * $page_size + 1; | |
| 724 $max = $count; | |
| 725 | |
| 726 if ($max === null && $RCMAIL->action) { | |
| 727 $max = $RCMAIL->storage->count(null, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); | |
| 728 } | |
| 729 | |
| 730 if (!$max) { | |
| 731 $out = $RCMAIL->storage->get_search_set() ? $RCMAIL->gettext('nomessages') : $RCMAIL->gettext('mailboxempty'); | |
| 732 } | |
| 733 else { | |
| 734 $out = $RCMAIL->gettext(array('name' => $RCMAIL->storage->get_threading() ? 'threadsfromto' : 'messagesfromto', | |
| 735 'vars' => array('from' => $start_msg, | |
| 736 'to' => min($max, $start_msg + $page_size - 1), | |
| 737 'count' => $max))); | |
| 738 } | |
| 739 | |
| 740 return rcube::Q($out); | |
| 741 } | |
| 742 | |
| 743 function rcmail_mailbox_name_display($attrib) | |
| 744 { | |
| 745 global $RCMAIL; | |
| 746 | |
| 747 if (!$attrib['id']) { | |
| 748 $attrib['id'] = 'rcmmailboxname'; | |
| 749 } | |
| 750 | |
| 751 $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']); | |
| 752 | |
| 753 return html::span($attrib, rcmail_get_mailbox_name_text()); | |
| 754 } | |
| 755 | |
| 756 function rcmail_get_mailbox_name_text() | |
| 757 { | |
| 758 global $RCMAIL; | |
| 759 return $RCMAIL->localize_foldername($RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder()); | |
| 760 } | |
| 761 | |
| 762 function rcmail_send_unread_count($mbox_name, $force=false, $count=null, $mark='') | |
| 763 { | |
| 764 global $RCMAIL; | |
| 765 | |
| 766 $old_unseen = rcmail_get_unseen_count($mbox_name); | |
| 767 $unseen = $count; | |
| 768 | |
| 769 if ($unseen === null) { | |
| 770 $unseen = $RCMAIL->storage->count($mbox_name, 'UNSEEN', $force); | |
| 771 } | |
| 772 | |
| 773 if ($unseen != $old_unseen || ($mbox_name == 'INBOX')) { | |
| 774 $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, | |
| 775 ($mbox_name == 'INBOX'), $unseen && $mark ? $mark : ''); | |
| 776 } | |
| 777 | |
| 778 rcmail_set_unseen_count($mbox_name, $unseen); | |
| 779 | |
| 780 return $unseen; | |
| 781 } | |
| 782 | |
| 783 function rcmail_set_unseen_count($mbox_name, $count) | |
| 784 { | |
| 785 // @TODO: this data is doubled (session and cache tables) if caching is enabled | |
| 786 | |
| 787 // Make sure we have an array here (#1487066) | |
| 19 | 788 if (!is_array($_SESSION['unseen_count']??null)) { |
| 0 | 789 $_SESSION['unseen_count'] = array(); |
| 790 } | |
| 791 | |
| 792 $_SESSION['unseen_count'][$mbox_name] = $count; | |
| 793 } | |
| 794 | |
| 795 function rcmail_get_unseen_count($mbox_name) | |
| 796 { | |
| 19 | 797 if (is_array($_SESSION['unseen_count']??null) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) { |
| 0 | 798 return $_SESSION['unseen_count'][$mbox_name]; |
| 799 } | |
| 800 } | |
| 801 | |
| 802 /** | |
| 803 * Sets message is_safe flag according to 'show_images' option value | |
| 804 * | |
| 805 * @param object rcube_message Message | |
| 806 */ | |
| 807 function rcmail_check_safe($message) | |
| 808 { | |
| 809 global $RCMAIL; | |
| 810 | |
| 811 if (!$message->is_safe | |
| 812 && ($show_images = $RCMAIL->config->get('show_images')) | |
| 813 && $message->has_html_part() | |
| 814 ) { | |
| 815 switch ($show_images) { | |
| 816 case 1: // known senders only | |
| 817 // get default addressbook, like in addcontact.inc | |
| 818 $CONTACTS = $RCMAIL->get_address_book(-1, true); | |
| 819 | |
| 820 if ($CONTACTS && $message->sender['mailto']) { | |
| 821 $result = $CONTACTS->search('email', $message->sender['mailto'], 1, false); | |
| 822 if ($result->count) { | |
| 823 $message->set_safe(true); | |
| 824 } | |
| 825 } | |
| 826 | |
| 827 $RCMAIL->plugins->exec_hook('message_check_safe', array('message' => $message)); | |
| 828 break; | |
| 829 | |
| 830 case 2: // always | |
| 831 $message->set_safe(true); | |
| 832 break; | |
| 833 } | |
| 834 } | |
| 835 | |
| 836 return !empty($message->is_safe); | |
| 837 } | |
| 838 | |
| 839 /** | |
| 840 * Cleans up the given message HTML Body (for displaying) | |
| 841 * | |
| 842 * @param string HTML | |
| 843 * @param array Display parameters | |
| 844 * @param array CID map replaces (inline images) | |
| 845 * @return string Clean HTML | |
| 846 */ | |
| 847 function rcmail_wash_html($html, $p, $cid_replaces = array()) | |
| 848 { | |
| 849 global $REMOTE_OBJECTS; | |
| 850 | |
| 851 $p += array('safe' => false, 'inline_html' => true); | |
| 852 | |
| 853 // charset was converted to UTF-8 in rcube_storage::get_message_part(), | |
| 854 // change/add charset specification in HTML accordingly, | |
| 855 // washtml cannot work without that | |
| 856 $meta = '<meta http-equiv="Content-Type" content="text/html; charset='.RCUBE_CHARSET.'" />'; | |
| 857 | |
| 858 // remove old meta tag and add the new one, making sure | |
| 859 // that it is placed in the head (#1488093) | |
| 860 $html = preg_replace('/<meta[^>]+charset=[a-z0-9-_]+[^>]*>/Ui', '', $html); | |
| 861 $html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); | |
| 862 if (!$rcount) { | |
| 863 $html = '<head>' . $meta . '</head>' . $html; | |
| 864 } | |
| 865 | |
| 866 // clean HTML with washhtml by Frederic Motte | |
| 867 $wash_opts = array( | |
| 868 'show_washed' => false, | |
| 869 'allow_remote' => $p['safe'], | |
| 870 'blocked_src' => 'program/resources/blocked.gif', | |
| 871 'charset' => RCUBE_CHARSET, | |
| 872 'cid_map' => $cid_replaces, | |
| 873 'html_elements' => array('body'), | |
| 874 ); | |
| 875 | |
| 876 if (!$p['inline_html']) { | |
| 877 $wash_opts['html_elements'] = array('html','head','title','body'); | |
| 878 } | |
| 879 if ($p['safe']) { | |
| 880 $wash_opts['html_elements'][] = 'link'; | |
| 881 $wash_opts['html_attribs'] = array('rel','type'); | |
| 882 } | |
| 883 | |
| 884 // overwrite washer options with options from plugins | |
| 885 if (isset($p['html_elements'])) | |
| 886 $wash_opts['html_elements'] = $p['html_elements']; | |
| 887 if (isset($p['html_attribs'])) | |
| 888 $wash_opts['html_attribs'] = $p['html_attribs']; | |
| 889 | |
| 890 // initialize HTML washer | |
| 891 $washer = new rcube_washtml($wash_opts); | |
| 892 | |
| 893 if (!$p['skip_washer_form_callback']) { | |
| 894 $washer->add_callback('form', 'rcmail_washtml_callback'); | |
| 895 } | |
| 896 | |
| 897 // allow CSS styles, will be sanitized by rcmail_washtml_callback() | |
| 898 if (!$p['skip_washer_style_callback']) { | |
| 899 $washer->add_callback('style', 'rcmail_washtml_callback'); | |
| 900 } | |
| 901 | |
| 902 // modify HTML links to open a new window if clicked | |
| 903 if (!$p['skip_washer_link_callback']) { | |
| 904 $washer->add_callback('a', 'rcmail_washtml_link_callback'); | |
| 905 $washer->add_callback('area', 'rcmail_washtml_link_callback'); | |
| 906 | |
| 907 if ($p['safe']) | |
| 908 $washer->add_callback('link', 'rcmail_washtml_link_callback'); | |
| 909 } | |
| 910 | |
| 911 // Remove non-UTF8 characters (#1487813) | |
| 912 $html = rcube_charset::clean($html); | |
| 913 | |
| 914 $html = $washer->wash($html); | |
| 915 $REMOTE_OBJECTS = $washer->extlinks; | |
| 916 | |
| 917 return $html; | |
| 918 } | |
| 919 | |
| 920 /** | |
| 921 * Convert the given message part to proper HTML | |
| 922 * which can be displayed the message view | |
| 923 * | |
| 924 * @param string Message part body | |
| 925 * @param rcube_message_part Message part | |
| 926 * @param array Display parameters array | |
| 927 * | |
| 928 * @return string Formatted HTML string | |
| 929 */ | |
| 930 function rcmail_print_body($body, $part, $p = array()) | |
| 931 { | |
| 932 global $RCMAIL; | |
| 933 | |
| 934 // trigger plugin hook | |
| 935 $data = $RCMAIL->plugins->exec_hook('message_part_before', | |
| 936 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) | |
| 937 + $p + array('safe' => false, 'plain' => false, 'inline_html' => true)); | |
| 938 | |
| 939 // convert html to text/plain | |
| 940 if ($data['plain'] && ($data['type'] == 'html' || $data['type'] == 'enriched')) { | |
| 941 if ($data['type'] == 'enriched') { | |
| 942 $data['body'] = rcube_enriched::to_html($data['body']); | |
| 943 } | |
| 944 | |
| 945 $body = $RCMAIL->html2text($data['body']); | |
| 946 $part->ctype_secondary = 'plain'; | |
| 947 } | |
| 948 // text/html | |
| 949 else if ($data['type'] == 'html') { | |
| 950 $body = rcmail_wash_html($data['body'], $data, $part->replaces); | |
| 951 $part->ctype_secondary = $data['type']; | |
| 952 } | |
| 953 // text/enriched | |
| 954 else if ($data['type'] == 'enriched') { | |
| 955 $body = rcube_enriched::to_html($data['body']); | |
| 956 $body = rcmail_wash_html($body, $data, $part->replaces); | |
| 957 $part->ctype_secondary = 'html'; | |
| 958 } | |
| 959 else { | |
| 960 // assert plaintext | |
| 961 $body = $data['body']; | |
| 962 $part->ctype_secondary = $data['type'] = 'plain'; | |
| 963 } | |
| 964 | |
| 965 // free some memory (hopefully) | |
| 966 unset($data['body']); | |
| 967 | |
| 968 // plaintext postprocessing | |
| 969 if ($part->ctype_secondary == 'plain') { | |
| 19 | 970 $flowed = ($part->ctype_parameters['format']??null) == 'flowed'; |
| 971 $delsp = ($part->ctype_parameters['delsp']??null) == 'yes'; | |
| 0 | 972 $body = rcmail_plain_body($body, $flowed, $delsp); |
| 973 } | |
| 974 | |
| 975 // allow post-processing of the message body | |
| 976 $data = $RCMAIL->plugins->exec_hook('message_part_after', | |
| 977 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) + $data); | |
| 978 | |
| 979 return $data['body']; | |
| 980 } | |
| 981 | |
| 982 /** | |
| 983 * Handle links and citation marks in plain text message | |
| 984 * | |
| 985 * @param string Plain text string | |
| 986 * @param boolean Set to True if the source text is in format=flowed | |
| 987 * | |
| 988 * @return string Formatted HTML string | |
| 989 */ | |
| 990 function rcmail_plain_body($body, $flowed = false, $delsp = false) | |
| 991 { | |
| 992 $options = array('flowed' => $flowed, 'wrap' => !$flowed, 'replacer' => 'rcmail_string_replacer', | |
| 993 'delsp' => $delsp); | |
| 994 $text2html = new rcube_text2html($body, false, $options); | |
| 995 $body = $text2html->get_html(); | |
| 996 | |
| 997 return $body; | |
| 998 } | |
| 999 | |
| 1000 /** | |
| 1001 * Callback function for washtml cleaning class | |
| 1002 */ | |
| 1003 function rcmail_washtml_callback($tagname, $attrib, $content, $washtml) | |
| 1004 { | |
| 1005 switch ($tagname) { | |
| 1006 case 'form': | |
| 1007 $out = html::div('form', $content); | |
| 1008 break; | |
| 1009 | |
| 1010 case 'style': | |
| 1011 // Crazy big styles may freeze the browser (#1490539) | |
| 1012 // remove content with more than 5k lines | |
| 1013 if (substr_count($content, "\n") > 5000) { | |
| 1014 $out = ''; | |
| 1015 break; | |
| 1016 } | |
| 1017 | |
| 1018 // decode all escaped entities and reduce to ascii strings | |
| 1019 $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', rcube_utils::xss_entity_decode($content)); | |
| 1020 | |
| 1021 // now check for evil strings like expression, behavior or url() | |
| 1022 if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) { | |
| 1023 if (!$washtml->get_config('allow_remote') && preg_match('/url\((?!data:image)/', $stripped)) { | |
| 1024 $washtml->extlinks = true; | |
| 1025 } | |
| 1026 else { | |
| 1027 $out = html::tag('style', array('type' => 'text/css'), $content); | |
| 1028 } | |
| 1029 break; | |
| 1030 } | |
| 1031 | |
| 1032 default: | |
| 1033 $out = ''; | |
| 1034 } | |
| 1035 | |
| 1036 return $out; | |
| 1037 } | |
| 1038 | |
| 1039 /** | |
| 1040 * return table with message headers | |
| 1041 */ | |
| 1042 function rcmail_message_headers($attrib, $headers=null) | |
| 1043 { | |
| 1044 global $MESSAGE, $PRINT_MODE, $RCMAIL; | |
| 1045 static $sa_attrib; | |
| 1046 | |
| 1047 // keep header table attrib | |
| 19 | 1048 if (is_array($attrib) && !$sa_attrib && empty($attrib['valueof'])) { |
| 0 | 1049 $sa_attrib = $attrib; |
| 1050 } | |
| 1051 else if (!is_array($attrib) && is_array($sa_attrib)) { | |
| 1052 $attrib = $sa_attrib; | |
| 1053 } | |
| 1054 | |
| 1055 if (!isset($MESSAGE)) { | |
| 1056 return false; | |
| 1057 } | |
| 1058 | |
| 1059 // get associative array of headers object | |
| 1060 if (!$headers) { | |
| 1061 $headers_obj = $MESSAGE->headers; | |
| 1062 $headers = get_object_vars($MESSAGE->headers); | |
| 1063 } | |
| 1064 else if (is_object($headers)) { | |
| 1065 $headers_obj = $headers; | |
| 1066 $headers = get_object_vars($headers_obj); | |
| 1067 } | |
| 1068 else { | |
| 1069 $headers_obj = rcube_message_header::from_array($headers); | |
| 1070 } | |
| 1071 | |
| 1072 // show these headers | |
| 1073 $standard_headers = array('subject', 'from', 'sender', 'to', 'cc', 'bcc', 'replyto', | |
| 1074 'mail-reply-to', 'mail-followup-to', 'date', 'priority'); | |
| 19 | 1075 $exclude_headers = !empty($attrib['exclude']) ? explode(',', $attrib['exclude']) : array(); |
| 0 | 1076 $output_headers = array(); |
| 1077 | |
| 1078 foreach ($standard_headers as $hkey) { | |
| 19 | 1079 if ($headers[$hkey]??null) |
| 0 | 1080 $value = $headers[$hkey]; |
| 19 | 1081 else if ($headers['others'][$hkey]??null) |
| 0 | 1082 $value = $headers['others'][$hkey]; |
| 19 | 1083 else if (empty($attrib['valueof'])) |
| 0 | 1084 continue; |
| 1085 | |
| 1086 if (in_array($hkey, $exclude_headers)) | |
| 1087 continue; | |
| 1088 | |
| 1089 $ishtml = false; | |
| 1090 $header_title = $RCMAIL->gettext(preg_replace('/(^mail-|-)/', '', $hkey)); | |
| 1091 | |
| 1092 if ($hkey == 'date') { | |
| 1093 if ($PRINT_MODE) | |
| 1094 $header_value = $RCMAIL->format_date($value, $RCMAIL->config->get('date_long', 'x')); | |
| 1095 else | |
| 1096 $header_value = $RCMAIL->format_date($value); | |
| 1097 } | |
| 1098 else if ($hkey == 'priority') { | |
| 1099 if ($value) { | |
| 1100 $header_value = html::span('prio' . $value, rcube::Q(rcmail_localized_priority($value))); | |
| 1101 $ishtml = true; | |
| 1102 } | |
| 1103 else { | |
| 1104 continue; | |
| 1105 } | |
| 1106 } | |
| 1107 else if ($hkey == 'replyto') { | |
| 1108 if ($headers['replyto'] != $headers['from']) { | |
| 19 | 1109 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1110 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1111 $ishtml = true; |
| 1112 } | |
| 1113 else { | |
| 1114 continue; | |
| 1115 } | |
| 1116 } | |
| 1117 else if ($hkey == 'mail-reply-to') { | |
| 19 | 1118 if (($headers['mail-replyto']??null) != $headers['replyto'] |
| 0 | 1119 && $headers['replyto'] != $headers['from'] |
| 1120 ) { | |
| 19 | 1121 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1122 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1123 $ishtml = true; |
| 1124 } | |
| 1125 else { | |
| 1126 continue; | |
| 1127 } | |
| 1128 } | |
| 1129 else if ($hkey == 'sender') { | |
| 19 | 1130 if (($headers['sender']??null) != $headers['from']) { |
| 1131 $header_value = rcmail_address_string($value, $attrib['max']??null, true, | |
| 1132 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1133 $ishtml = true; |
| 1134 } | |
| 1135 else { | |
| 1136 continue; | |
| 1137 } | |
| 1138 } | |
| 1139 else if ($hkey == 'mail-followup-to') { | |
| 19 | 1140 $header_value = rcmail_address_string($value, $attrib['max']??null, |
| 1141 true, | |
| 1142 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1143 $ishtml = true; |
| 1144 } | |
| 1145 else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) { | |
| 19 | 1146 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1147 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1148 $ishtml = true; |
| 1149 } | |
| 1150 else if ($hkey == 'subject' && empty($value)) { | |
| 1151 $header_value = $RCMAIL->gettext('nosubject'); | |
| 1152 } | |
| 1153 else { | |
| 1154 $value = is_array($value) ? implode(' ', $value) : $value; | |
| 1155 $header_value = trim(rcube_mime::decode_header($value, $headers['charset'])); | |
| 1156 } | |
| 1157 | |
| 1158 $output_headers[$hkey] = array( | |
| 1159 'title' => $header_title, | |
| 1160 'value' => $header_value, | |
| 1161 'raw' => $value, | |
| 1162 'html' => $ishtml, | |
| 1163 ); | |
| 1164 } | |
| 1165 | |
| 1166 $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array( | |
| 1167 'output' => $output_headers, | |
| 1168 'headers' => $headers_obj, | |
| 1169 'exclude' => $exclude_headers, // readonly | |
| 1170 'folder' => $MESSAGE->folder, // readonly | |
| 1171 'uid' => $MESSAGE->uid, // readonly | |
| 1172 )); | |
| 1173 | |
| 1174 // single header value is requested | |
| 1175 if (!empty($attrib['valueof'])) { | |
| 1176 $row = $plugin['output'][$attrib['valueof']]; | |
| 1177 return $row['html'] ? $row['value'] : rcube::Q($row['value']); | |
| 1178 } | |
| 1179 | |
| 1180 // compose html table | |
| 1181 $table = new html_table(array('cols' => 2)); | |
| 1182 | |
| 1183 foreach ($plugin['output'] as $hkey => $row) { | |
| 1184 $val = $row['html'] ? $row['value'] : rcube::Q($row['value']); | |
| 1185 | |
| 1186 $table->add(array('class' => 'header-title'), rcube::Q($row['title'])); | |
| 1187 $table->add(array('class' => 'header '.$hkey), $val); | |
| 1188 } | |
| 1189 | |
| 1190 return $table->show($attrib); | |
| 1191 } | |
| 1192 | |
| 1193 /** | |
| 1194 * Convert Priority header value into a localized string | |
| 1195 */ | |
| 1196 function rcmail_localized_priority($value) | |
| 1197 { | |
| 1198 global $RCMAIL; | |
| 1199 | |
| 1200 $labels_map = array( | |
| 1201 '1' => 'highest', | |
| 1202 '2' => 'high', | |
| 1203 '3' => 'normal', | |
| 1204 '4' => 'low', | |
| 1205 '5' => 'lowest', | |
| 1206 ); | |
| 1207 | |
| 19 | 1208 if ($value && !empty($labels_map[$value])) { |
| 0 | 1209 return $RCMAIL->gettext($labels_map[$value]); |
| 1210 } | |
| 1211 | |
| 1212 return ''; | |
| 1213 } | |
| 1214 | |
| 1215 /** | |
| 1216 * return block to show full message headers | |
| 1217 */ | |
| 1218 function rcmail_message_full_headers($attrib) | |
| 1219 { | |
| 1220 global $OUTPUT, $RCMAIL; | |
| 1221 | |
| 1222 $html = html::div(array('id' => "all-headers", 'class' => "all", 'style' => 'display:none'), html::div(array('id' => 'headers-source'), '')); | |
| 1223 $html .= html::div(array( | |
| 1224 'class' => "more-headers show-headers", | |
| 1225 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('show-headers','',this)", | |
| 1226 'title' => $RCMAIL->gettext('togglefullheaders') | |
| 1227 ), ''); | |
| 1228 | |
| 1229 $OUTPUT->add_gui_object('all_headers_row', 'all-headers'); | |
| 1230 $OUTPUT->add_gui_object('all_headers_box', 'headers-source'); | |
| 1231 | |
| 1232 return html::div($attrib, $html); | |
| 1233 } | |
| 1234 | |
| 1235 /** | |
| 1236 * Handler for the 'messagebody' GUI object | |
| 1237 * | |
| 1238 * @param array Named parameters | |
| 1239 * @return string HTML content showing the message body | |
| 1240 */ | |
| 1241 function rcmail_message_body($attrib) | |
| 1242 { | |
| 1243 global $OUTPUT, $MESSAGE, $RCMAIL, $REMOTE_OBJECTS; | |
| 1244 | |
| 1245 if (!is_array($MESSAGE->parts) && empty($MESSAGE->body)) { | |
| 1246 return ''; | |
| 1247 } | |
| 1248 | |
| 1249 if (!$attrib['id']) | |
| 1250 $attrib['id'] = 'rcmailMsgBody'; | |
| 1251 | |
| 19 | 1252 $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']??null); |
| 0 | 1253 $out = ''; |
| 1254 $part_no = 0; | |
| 1255 | |
| 1256 $header_attrib = array(); | |
| 1257 foreach ($attrib as $attr => $value) { | |
| 1258 if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs)) { | |
| 1259 $header_attrib[$regs[1]] = $value; | |
| 1260 } | |
| 1261 } | |
| 1262 | |
| 1263 if (!empty($MESSAGE->parts)) { | |
| 1264 foreach ($MESSAGE->parts as $part) { | |
| 1265 if ($part->type == 'headers') { | |
| 1266 $out .= html::div('message-partheaders', rcmail_message_headers(count($header_attrib) ? $header_attrib : null, $part->headers)); | |
| 1267 } | |
| 1268 else if ($part->type == 'content') { | |
| 1269 // unsupported (e.g. encrypted) | |
| 19 | 1270 if ($part->realtype??null) { |
| 0 | 1271 if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') { |
| 1272 if (!empty($_SESSION['browser_caps']['pgpmime']) && ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part())) { | |
| 1273 $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption')); | |
| 1274 $OUTPUT->set_env('pgp_mime_part', $pgp_mime_part->mime_id); | |
| 1275 $OUTPUT->set_env('pgp_mime_container', '#' . $attrib['id']); | |
| 1276 $OUTPUT->add_label('loadingdata'); | |
| 1277 } | |
| 1278 | |
| 1279 if (!$MESSAGE->encrypted_part) { | |
| 1280 $out .= html::span('part-notice', $RCMAIL->gettext('encryptedmessage')); | |
| 1281 } | |
| 1282 } | |
| 1283 continue; | |
| 1284 } | |
| 1285 else if (!$part->size) { | |
| 1286 continue; | |
| 1287 } | |
| 1288 | |
| 1289 // Check if we have enough memory to handle the message in it | |
| 1290 // #1487424: we need up to 10x more memory than the body | |
| 1291 else if (!rcube_utils::mem_check($part->size * 10)) { | |
| 1292 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' ' | |
| 1293 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id | |
| 1294 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download'))); | |
| 1295 continue; | |
| 1296 } | |
| 1297 | |
| 1298 // fetch part body | |
| 1299 $body = $MESSAGE->get_part_body($part->mime_id, true); | |
| 1300 | |
| 1301 // message is cached but not exists (#1485443), or other error | |
| 1302 if ($body === false) { | |
| 1303 rcmail_message_error($MESSAGE->uid); | |
| 1304 } | |
| 1305 | |
| 1306 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', | |
| 1307 array('part' => $part, 'prefix' => '')); | |
| 1308 | |
| 1309 // Set attributes of the part container | |
| 1310 $container_class = $part->ctype_secondary == 'html' ? 'message-htmlpart' : 'message-part'; | |
| 1311 $container_id = $container_class . (++$part_no); | |
| 1312 $container_attrib = array('class' => $container_class, 'id' => $container_id); | |
| 1313 | |
| 1314 // Assign container ID to a global variable for use in rcmail_washtml_link_callback() | |
| 1315 $GLOBALS['rcmail_html_container_id'] = $container_id; | |
| 1316 | |
| 1317 // Parse the part content for display | |
| 1318 $body = rcmail_print_body($body, $part, array('safe' => $safe_mode, 'plain' => !$RCMAIL->config->get('prefer_html'))); | |
| 1319 | |
| 1320 // check if the message body is PGP encrypted | |
| 1321 if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) { | |
| 1322 $OUTPUT->set_env('is_pgp_content', '#' . $container_id); | |
| 1323 } | |
| 1324 | |
| 1325 if ($part->ctype_secondary == 'html') { | |
| 1326 $body = rcmail_html4inline($body, $container_id, 'rcmBody', $container_attrib, $safe_mode); | |
| 1327 } | |
| 1328 | |
| 1329 $out .= html::div($container_attrib, $plugin['prefix'] . $body); | |
| 1330 } | |
| 1331 } | |
| 1332 } | |
| 1333 else { | |
| 1334 // Check if we have enough memory to handle the message in it | |
| 1335 // #1487424: we need up to 10x more memory than the body | |
| 1336 if (!rcube_utils::mem_check(strlen($MESSAGE->body) * 10)) { | |
| 1337 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' ' | |
| 1338 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part=0' | |
| 1339 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download'))); | |
| 1340 } | |
| 1341 else { | |
| 1342 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', | |
| 1343 array('part' => $MESSAGE, 'prefix' => '')); | |
| 1344 | |
| 1345 $out .= html::div('message-part', | |
| 1346 $plugin['prefix'] . rcmail_plain_body($MESSAGE->body)); | |
| 1347 } | |
| 1348 } | |
| 1349 | |
| 1350 // list images after mail body | |
| 1351 if ($RCMAIL->config->get('inline_images', true) && !empty($MESSAGE->attachments)) { | |
| 1352 $thumbnail_size = $RCMAIL->config->get('image_thumbnail_size', 240); | |
| 1353 $client_mimetypes = (array)$RCMAIL->config->get('client_mimetypes'); | |
| 1354 | |
| 1355 foreach ($MESSAGE->attachments as $attach_prop) { | |
| 1356 // skip inline images | |
| 1357 if ($attach_prop->content_id && $attach_prop->disposition == 'inline') { | |
| 1358 continue; | |
| 1359 } | |
| 1360 | |
| 1361 // Content-Type: image/*... | |
| 1362 if ($mimetype = rcmail_part_image_type($attach_prop)) { | |
| 1363 // display thumbnails | |
| 1364 if ($thumbnail_size) { | |
| 1365 $supported = in_array($mimetype, $client_mimetypes); | |
| 1366 $show_link = array( | |
| 1367 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), | |
| 1368 'onclick' => sprintf( | |
| 1369 'return %s.command(\'load-attachment\',\'%s\',this)', | |
| 1370 rcmail_output::JS_OBJECT_NAME, | |
| 1371 $attach_prop->mime_id) | |
| 1372 ); | |
| 1373 | |
| 1374 $out .= html::p(array('class' => 'image-attachment', 'style' => $supported ? '' : 'display:none'), | |
| 1375 html::a($show_link + array('class' => 'image-link', 'style' => sprintf('width:%dpx', $thumbnail_size)), | |
| 1376 html::img(array( | |
| 1377 'class' => 'image-thumbnail', | |
| 1378 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image') . '&_thumb=1', | |
| 1379 'title' => $attach_prop->filename, | |
| 1380 'alt' => $attach_prop->filename, | |
| 1381 'style' => sprintf('max-width:%dpx; max-height:%dpx', $thumbnail_size, $thumbnail_size), | |
| 1382 'onload' => $supported ? '' : '$(this).parents(\'p.image-attachment\').show()', | |
| 1383 )) | |
| 1384 ) . | |
| 1385 html::span('image-filename', rcube::Q($attach_prop->filename)) . | |
| 1386 html::span('image-filesize', rcube::Q($RCMAIL->message_part_size($attach_prop))) . | |
| 1387 html::span('attachment-links', | |
| 1388 ($supported ? html::a($show_link, $RCMAIL->gettext('showattachment')) . ' ' : '') . | |
| 1389 html::a($show_link['href'] . '&_download=1', $RCMAIL->gettext('download')) | |
| 1390 ) . | |
| 1391 html::br(array('style' => 'clear:both')) | |
| 1392 ); | |
| 1393 } | |
| 1394 else { | |
| 1395 $out .= html::tag('fieldset', 'image-attachment', | |
| 1396 html::tag('legend', 'image-filename', rcube::Q($attach_prop->filename)) . | |
| 1397 html::p(array('align' => 'center'), | |
| 1398 html::img(array( | |
| 1399 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image'), | |
| 1400 'title' => $attach_prop->filename, | |
| 1401 'alt' => $attach_prop->filename, | |
| 1402 ))) | |
| 1403 ); | |
| 1404 } | |
| 1405 } | |
| 1406 } | |
| 1407 } | |
| 1408 | |
| 1409 // tell client that there are blocked remote objects | |
| 1410 if ($REMOTE_OBJECTS && !$safe_mode) { | |
| 1411 $OUTPUT->set_env('blockedobjects', true); | |
| 1412 } | |
| 1413 | |
| 1414 return html::div($attrib, $out); | |
| 1415 } | |
| 1416 | |
| 1417 function rcmail_part_image_type($part) | |
| 1418 { | |
| 1419 $mimetype = strtolower($part->mimetype); | |
| 1420 | |
| 1421 // Skip TIFF/WEBP images if browser doesn't support this format | |
| 1422 // ...until we can convert them to JPEG | |
| 1423 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tiff']); | |
| 1424 $tiff_support = $tiff_support || rcube_image::is_convertable('image/tiff'); | |
| 1425 $webp_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['webp']); | |
| 1426 $webp_support = $webp_support || rcube_image::is_convertable('image/webp'); | |
| 1427 | |
| 1428 if ((!$tiff_support && $mimetype == 'image/tiff') || (!$webp_support && $mimetype == 'image/webp')) { | |
| 1429 return; | |
| 1430 } | |
| 1431 | |
| 1432 // Content-Type: image/*... | |
| 1433 if (strpos($mimetype, 'image/') === 0) { | |
| 1434 return rcmail_fix_mimetype($mimetype); | |
| 1435 } | |
| 1436 | |
| 1437 // Many clients use application/octet-stream, we'll detect mimetype | |
| 1438 // by checking filename extension | |
| 1439 | |
| 1440 // Supported image filename extensions to image type map | |
| 1441 $types = array( | |
| 1442 'jpg' => 'image/jpeg', | |
| 1443 'jpeg' => 'image/jpeg', | |
| 1444 'png' => 'image/png', | |
| 1445 'gif' => 'image/gif', | |
| 1446 'bmp' => 'image/bmp', | |
| 1447 ); | |
| 1448 if ($tiff_support) { | |
| 1449 $types['tif'] = 'image/tiff'; | |
| 1450 $types['tiff'] = 'image/tiff'; | |
| 1451 } | |
| 1452 if ($webp_support) { | |
| 1453 $types['webp'] = 'image/webp'; | |
| 1454 } | |
| 1455 | |
| 1456 if ($part->filename | |
| 1457 && $mimetype == 'application/octet-stream' | |
| 1458 && preg_match('/\.([^.]+)$/i', $part->filename, $m) | |
| 1459 && ($extension = strtolower($m[1])) | |
| 1460 && isset($types[$extension]) | |
| 1461 ) { | |
| 1462 return $types[$extension]; | |
| 1463 } | |
| 1464 } | |
| 1465 | |
| 1466 /** | |
| 1467 * Modify a HTML message that it can be displayed inside a HTML page | |
| 1468 */ | |
| 1469 function rcmail_html4inline($body, $container_id, $body_class='', &$attributes=array(), $allow_remote=false) | |
| 1470 { | |
| 1471 $last_style_pos = 0; | |
| 1472 $cont_id = $container_id . ($body_class ? ' div.'.$body_class : ''); | |
| 1473 | |
| 1474 // find STYLE tags | |
| 1475 while (($pos = stripos($body, '<style', $last_style_pos)) && ($pos2 = stripos($body, '</style>', $pos))) { | |
| 1476 $pos = strpos($body, '>', $pos) + 1; | |
| 1477 $len = $pos2 - $pos; | |
| 1478 | |
| 1479 // replace all css definitions with #container [def] | |
| 1480 $styles = substr($body, $pos, $len); | |
| 1481 $styles = rcube_utils::mod_css_styles($styles, $cont_id, $allow_remote); | |
| 1482 | |
| 1483 $body = substr_replace($body, $styles, $pos, $len); | |
| 1484 $last_style_pos = $pos2 + strlen($styles) - $len; | |
| 1485 } | |
| 1486 | |
| 1487 $body = preg_replace(array( | |
| 1488 // add comments around html and other tags | |
| 1489 '/(<!DOCTYPE[^>]*>)/i', | |
| 1490 '/(<\?xml[^>]*>)/i', | |
| 1491 '/(<\/?html[^>]*>)/i', | |
| 1492 '/(<\/?head[^>]*>)/i', | |
| 1493 '/(<title[^>]*>.*<\/title>)/Ui', | |
| 1494 '/(<\/?meta[^>]*>)/i', | |
| 1495 // quote <? of php and xml files that are specified as text/html | |
| 1496 '/<\?/', | |
| 1497 '/\?>/', | |
| 1498 // replace <body> with <div> | |
| 1499 '/<body([^>]*)>/i', | |
| 1500 '/<\/body>/i', | |
| 1501 ), | |
| 1502 array( | |
| 1503 '<!--\\1-->', | |
| 1504 '<!--\\1-->', | |
| 1505 '<!--\\1-->', | |
| 1506 '<!--\\1-->', | |
| 1507 '<!--\\1-->', | |
| 1508 '<!--\\1-->', | |
| 1509 '<?', | |
| 1510 '?>', | |
| 1511 '<div class="' . $body_class . '"\\1>', | |
| 1512 '</div>', | |
| 1513 ), | |
| 1514 $body); | |
| 1515 | |
| 1516 // Handle body attributes that doesn't play nicely with div elements | |
| 1517 $regexp = '/<div class="' . preg_quote($body_class, '/') . '"([^>]*)/'; | |
| 1518 if (preg_match($regexp, $body, $m)) { | |
| 1519 $style = array(); | |
| 1520 $attrs = $m[0]; | |
| 1521 | |
| 1522 // Get bgcolor, we'll set it as background-color of the message container | |
| 1523 if ($m[1] && preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/i', $attrs, $mb)) { | |
| 1524 $style['background-color'] = $mb[1]; | |
| 1525 $attrs = preg_replace('/bgcolor=["\']*[a-z0-9#]+["\']*/i', '', $attrs); | |
| 1526 } | |
| 1527 | |
| 1528 // Get background, we'll set it as background-image of the message container | |
| 1529 if ($m[1] && preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) { | |
| 1530 $style['background-image'] = 'url('.$mb[1].')'; | |
| 1531 $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs); | |
| 1532 } | |
| 1533 | |
| 1534 if (!empty($style)) { | |
| 1535 $body = preg_replace($regexp, rtrim($attrs), $body, 1); | |
| 1536 } | |
| 1537 | |
| 1538 // handle body styles related to background image | |
| 1539 if ($style['background-image']) { | |
| 1540 // get body style | |
| 1541 if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) { | |
| 1542 // get background related style | |
| 1543 $regexp = '/(background-position|background-repeat)\s*:\s*([^;]+);/i'; | |
| 1544 if (preg_match_all($regexp, $m[1], $matches, PREG_SET_ORDER)) { | |
| 1545 foreach ($matches as $m) { | |
| 1546 $style[$m[1]] = $m[2]; | |
| 1547 } | |
| 1548 } | |
| 1549 } | |
| 1550 } | |
| 1551 | |
| 1552 if (!empty($style)) { | |
| 1553 foreach ($style as $idx => $val) { | |
| 1554 $style[$idx] = $idx . ': ' . $val; | |
| 1555 } | |
| 1556 | |
| 1557 $attributes['style'] = implode('; ', $style); | |
| 1558 } | |
| 1559 } | |
| 1560 // make sure there's 'rcmBody' div, we need it for proper css modification | |
| 1561 // its name is hardcoded in rcmail_message_body() also | |
| 1562 else { | |
| 1563 $body = '<div class="' . $body_class . '">' . $body . '</div>'; | |
| 1564 } | |
| 1565 | |
| 1566 return $body; | |
| 1567 } | |
| 1568 | |
| 1569 /** | |
| 1570 * Parse link (a, link, area) attributes and set correct target | |
| 1571 */ | |
| 1572 function rcmail_washtml_link_callback($tag, $attribs, $content, $washtml) | |
| 1573 { | |
| 1574 global $RCMAIL; | |
| 1575 | |
| 1576 $attrib = html::parse_attrib_string($attribs); | |
| 1577 | |
| 1578 // Remove non-printable characters in URL (#1487805) | |
| 1579 if ($attrib['href']) { | |
| 1580 $attrib['href'] = preg_replace('/[\x00-\x1F]/', '', $attrib['href']); | |
| 1581 } | |
| 1582 | |
| 1583 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { | |
| 1584 $tempurl = 'tmp-' . md5($attrib['href']) . '.css'; | |
| 1585 $_SESSION['modcssurls'][$tempurl] = $attrib['href']; | |
| 1586 $attrib['href'] = $RCMAIL->url(array('task' => 'utils', 'action' => 'modcss', 'u' => $tempurl, 'c' => $GLOBALS['rcmail_html_container_id'])); | |
| 1587 $end = ' />'; | |
| 1588 } | |
| 1589 else if (preg_match('/^mailto:(.+)/i', $attrib['href'], $mailto)) { | |
| 1590 list($mailto, $url) = explode('?', html_entity_decode($mailto[1], ENT_QUOTES, 'UTF-8'), 2); | |
| 1591 | |
| 1592 // #6020: use raw encoding for correct "+" character handling as specified in RFC6068 | |
| 1593 $url = rawurldecode($url); | |
| 1594 $mailto = rawurldecode($mailto); | |
| 1595 $addresses = rcube_mime::decode_address_list($mailto, null, true); | |
| 1596 $mailto = array(); | |
| 1597 | |
| 1598 // do sanity checks on recipients | |
| 1599 foreach ($addresses as $idx => $addr) { | |
| 1600 if (rcube_utils::check_email($addr['mailto'], false)) { | |
| 1601 $addresses[$idx] = $addr['mailto']; | |
| 1602 $mailto[] = $addr['string']; | |
| 1603 } | |
| 1604 else { | |
| 1605 unset($addresses[$idx]); | |
| 1606 } | |
| 1607 } | |
| 1608 | |
| 1609 if (!empty($addresses)) { | |
| 1610 $attrib['href'] = 'mailto:' . implode(',', $addresses); | |
| 1611 $attrib['onclick'] = sprintf( | |
| 1612 "return %s.command('compose','%s',this)", | |
| 1613 rcmail_output::JS_OBJECT_NAME, | |
| 1614 rcube::JQ(implode(',', $mailto) . ($url ? "?$url" : ''))); | |
| 1615 } | |
| 1616 else { | |
| 1617 $attrib['href'] = '#NOP'; | |
| 1618 $attrib['onclick'] = ''; | |
| 1619 } | |
| 1620 } | |
| 1621 else if (empty($attrib['href']) && !isset($attrib['name'])) { | |
| 1622 $attrib['href'] = './#NOP'; | |
| 1623 $attrib['onclick'] = 'return false'; | |
| 1624 } | |
| 1625 else if (!empty($attrib['href']) && $attrib['href'][0] != '#') { | |
| 1626 $attrib['target'] = '_blank'; | |
| 1627 } | |
| 1628 | |
| 1629 // Better security by adding rel="noreferrer" (#1484686) | |
| 1630 if (($tag == 'a' || $tag == 'area') && $attrib['href'] && $attrib['href'][0] != '#') { | |
| 1631 $attrib['rel'] = 'noreferrer'; | |
| 1632 } | |
| 1633 | |
| 1634 // allowed attributes for a|link|area tags | |
| 1635 $allow = array('href','name','target','onclick','id','class','style','title', | |
| 1636 'rel','type','media','alt','coords','nohref','hreflang','shape'); | |
| 1637 | |
| 1638 return html::tag($tag, $attrib, $content, $allow); | |
| 1639 } | |
| 1640 | |
| 1641 /** | |
| 1642 * Decode address string and re-format it as HTML links | |
| 1643 */ | |
| 1644 function rcmail_address_string($input, $max=null, $linked=false, $addicon=null, $default_charset=null, $title=null) | |
| 1645 { | |
| 1646 global $RCMAIL, $PRINT_MODE; | |
| 1647 | |
| 1648 $a_parts = rcube_mime::decode_address_list($input, null, true, $default_charset); | |
| 1649 | |
| 1650 if (!count($a_parts)) { | |
| 1651 return $input; | |
| 1652 } | |
| 1653 | |
| 1654 $c = count($a_parts); | |
| 1655 $j = 0; | |
| 1656 $out = ''; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
1657 $moreadrs = null; |
| 0 | 1658 $allvalues = array(); |
| 1659 $show_email = $RCMAIL->config->get('message_show_email'); | |
| 1660 | |
| 1661 if ($addicon && !isset($_SESSION['writeable_abook'])) { | |
| 1662 $_SESSION['writeable_abook'] = $RCMAIL->get_address_sources(true) ? true : false; | |
| 1663 } | |
| 1664 | |
| 1665 foreach ($a_parts as $part) { | |
| 1666 $j++; | |
| 1667 | |
| 1668 $name = $part['name']; | |
| 1669 $mailto = $part['mailto']; | |
| 1670 $string = $part['string']; | |
| 1671 $valid = rcube_utils::check_email($mailto, false); | |
| 1672 | |
| 1673 // phishing email prevention (#1488981), e.g. "valid@email.addr <phishing@email.addr>" | |
| 1674 if (!$show_email && $valid && $name && $name != $mailto && strpos($name, '@')) { | |
| 1675 $name = ''; | |
| 1676 } | |
| 1677 | |
| 1678 // IDNA ASCII to Unicode | |
| 1679 if ($name == $mailto) | |
| 1680 $name = rcube_utils::idn_to_utf8($name); | |
| 1681 if ($string == $mailto) | |
| 1682 $string = rcube_utils::idn_to_utf8($string); | |
| 1683 $mailto = rcube_utils::idn_to_utf8($mailto); | |
| 1684 | |
| 1685 if ($PRINT_MODE) { | |
| 1686 $address = sprintf('%s <%s>', rcube::Q($name), rcube::Q($mailto)); | |
| 1687 } | |
| 1688 else if ($valid) { | |
| 1689 if ($linked) { | |
| 1690 $attrs = array( | |
| 1691 'href' => 'mailto:' . $mailto, | |
| 1692 'class' => 'rcmContactAddress', | |
| 1693 'onclick' => sprintf("return %s.command('compose','%s',this)", | |
| 1694 rcmail_output::JS_OBJECT_NAME, rcube::JQ(format_email_recipient($mailto, $name))), | |
| 1695 ); | |
| 1696 | |
| 1697 if ($show_email && $name && $mailto) { | |
| 1698 $content = rcube::Q($name ? sprintf('%s <%s>', $name, $mailto) : $mailto); | |
| 1699 } | |
| 1700 else { | |
| 1701 $content = rcube::Q($name ?: $mailto); | |
| 1702 $attrs['title'] = $mailto; | |
| 1703 } | |
| 1704 | |
| 1705 $address = html::a($attrs, $content); | |
| 1706 } | |
| 1707 else { | |
| 1708 $address = html::span(array('title' => $mailto, 'class' => "rcmContactAddress"), | |
| 1709 rcube::Q($name ?: $mailto)); | |
| 1710 } | |
| 1711 | |
| 1712 if ($addicon && $_SESSION['writeable_abook']) { | |
| 1713 $address .= html::a(array( | |
| 1714 'href' => "#add", | |
| 1715 'title' => $RCMAIL->gettext('addtoaddressbook'), | |
| 1716 'class' => 'rcmaddcontact', | |
| 1717 'onclick' => sprintf("return %s.command('add-contact','%s',this)", | |
| 1718 rcmail_output::JS_OBJECT_NAME, rcube::JQ($string)), | |
| 1719 ), | |
| 1720 html::img(array( | |
| 1721 'src' => $RCMAIL->output->abs_url($addicon, true), | |
| 1722 'alt' => "Add contact", | |
| 1723 'class' => 'noselect', | |
| 1724 ))); | |
| 1725 } | |
| 1726 } | |
| 1727 else { | |
| 1728 $address = $name ? rcube::Q($name) : ''; | |
| 1729 if ($mailto) { | |
| 1730 $address = trim($address . ' ' . rcube::Q($name ? sprintf('<%s>', $mailto) : $mailto)); | |
| 1731 } | |
| 1732 } | |
| 1733 | |
| 1734 $address = html::span('adr', $address); | |
| 1735 $allvalues[] = $address; | |
| 1736 | |
| 1737 if (!$moreadrs) { | |
| 1738 $out .= ($out ? ', ' : '') . $address; | |
| 1739 } | |
| 1740 | |
| 1741 if ($max && $j == $max && $c > $j) { | |
| 1742 if ($linked) { | |
| 1743 $moreadrs = $c - $j; | |
| 1744 } | |
| 1745 else { | |
| 1746 $out .= '...'; | |
| 1747 break; | |
| 1748 } | |
| 1749 } | |
| 1750 } | |
| 1751 | |
| 1752 if ($moreadrs) { | |
| 1753 $label = rcube::Q($RCMAIL->gettext(array('name' => 'andnmore', 'vars' => array('nr' => $moreadrs)))); | |
| 1754 | |
| 1755 if ($PRINT_MODE) { | |
| 1756 $out .= ' ' . html::a(array( | |
| 1757 'href' => '#more', | |
| 1758 'class' => 'morelink', | |
| 1759 'onclick' => '$(this).hide().next().show()', | |
| 1760 ), $label) | |
| 1761 . html::span(array('style' => 'display:none'), join(', ', $allvalues)); | |
| 1762 } | |
| 1763 else { | |
| 1764 $out .= ' ' . html::a(array( | |
| 1765 'href' => '#more', | |
| 1766 'class' => 'morelink', | |
| 1767 'onclick' => sprintf("return %s.show_popup_dialog('%s','%s')", | |
| 1768 rcmail_output::JS_OBJECT_NAME, | |
| 1769 rcube::JQ(join(', ', $allvalues)), | |
| 1770 rcube::JQ($title)) | |
| 1771 ), $label); | |
| 1772 } | |
| 1773 } | |
| 1774 | |
| 1775 return $out; | |
| 1776 } | |
| 1777 | |
| 1778 /** | |
| 1779 * Wrap text to a given number of characters per line | |
| 1780 * but respect the mail quotation of replies messages (>). | |
| 1781 * Finally add another quotation level by prepending the lines | |
| 1782 * with > | |
| 1783 * | |
| 1784 * @param string Text to wrap | |
| 1785 * @param int The line width | |
| 1786 * @return string The wrapped text | |
| 1787 */ | |
| 1788 function rcmail_wrap_and_quote($text, $length = 72) | |
| 1789 { | |
| 1790 // Rebuild the message body with a maximum of $max chars, while keeping quoted message. | |
| 1791 $max = max(75, $length + 8); | |
| 1792 $lines = preg_split('/\r?\n/', trim($text)); | |
| 1793 $out = ''; | |
| 1794 | |
| 1795 foreach ($lines as $line) { | |
| 1796 // don't wrap already quoted lines | |
| 1797 if ($line[0] == '>') { | |
| 1798 $line = '>' . rtrim($line); | |
| 1799 } | |
| 1800 else if (mb_strlen($line) > $max) { | |
| 1801 $newline = ''; | |
| 1802 | |
| 1803 foreach (explode("\n", rcube_mime::wordwrap($line, $length - 2)) as $l) { | |
| 1804 $newline .= strlen($l) ? "> $l\n" : ">\n"; | |
| 1805 } | |
| 1806 | |
| 1807 $line = rtrim($newline); | |
| 1808 } | |
| 1809 else { | |
| 1810 $line = '> ' . $line; | |
| 1811 } | |
| 1812 | |
| 1813 // Append the line | |
| 1814 $out .= $line . "\n"; | |
| 1815 } | |
| 1816 | |
| 1817 return rtrim($out, "\n"); | |
| 1818 } | |
| 1819 | |
| 1820 function rcmail_draftinfo_encode($p) | |
| 1821 { | |
| 1822 $parts = array(); | |
| 1823 foreach ($p as $key => $val) { | |
| 1824 $encode = $key == 'folder' || strpos($val, ';') !== false; | |
| 1825 $parts[] = $key . '=' . ($encode ? 'B::' . base64_encode($val) : $val); | |
| 1826 } | |
| 1827 | |
| 1828 return join('; ', $parts); | |
| 1829 } | |
| 1830 | |
| 1831 function rcmail_draftinfo_decode($str) | |
| 1832 { | |
| 1833 $info = array(); | |
| 1834 | |
| 1835 foreach (preg_split('/;\s+/', $str) as $part) { | |
| 1836 list($key, $val) = explode('=', $part, 2); | |
| 1837 if (strpos($val, 'B::') === 0) { | |
| 1838 $val = base64_decode(substr($val, 3)); | |
| 1839 } | |
| 1840 else if ($key == 'folder') { | |
| 1841 $val = base64_decode($val); | |
| 1842 } | |
| 1843 | |
| 1844 $info[$key] = $val; | |
| 1845 } | |
| 1846 | |
| 1847 return $info; | |
| 1848 } | |
| 1849 | |
| 1850 /** | |
| 1851 * Send the MDN response | |
| 1852 * | |
| 1853 * @param mixed $message Original message object (rcube_message) or UID | |
| 1854 * @param array $smtp_error SMTP error array (reference) | |
| 1855 * | |
| 1856 * @return boolean Send status | |
| 1857 */ | |
| 1858 function rcmail_send_mdn($message, &$smtp_error) | |
| 1859 { | |
| 1860 global $RCMAIL; | |
| 1861 | |
| 1862 if (!is_object($message) || !is_a($message, 'rcube_message')) { | |
| 1863 $message = new rcube_message($message); | |
| 1864 } | |
| 1865 | |
| 1866 if ($message->headers->mdn_to && empty($message->headers->flags['MDNSENT']) && | |
| 1867 ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*')) | |
| 1868 ) { | |
| 1869 $identity = rcmail_identity_select($message); | |
| 1870 $sender = format_email_recipient($identity['email'], $identity['name']); | |
| 1871 $recipient = array_shift(rcube_mime::decode_address_list( | |
| 1872 $message->headers->mdn_to, 1, true, $message->headers->charset)); | |
| 1873 $mailto = $recipient['mailto']; | |
| 1874 | |
| 1875 $compose = new Mail_mime("\r\n"); | |
| 1876 | |
| 1877 $compose->setParam('text_encoding', 'quoted-printable'); | |
| 1878 $compose->setParam('html_encoding', 'quoted-printable'); | |
| 1879 $compose->setParam('head_encoding', 'quoted-printable'); | |
| 1880 $compose->setParam('head_charset', RCUBE_CHARSET); | |
| 1881 $compose->setParam('html_charset', RCUBE_CHARSET); | |
| 1882 $compose->setParam('text_charset', RCUBE_CHARSET); | |
| 1883 | |
| 1884 // compose headers array | |
| 1885 $headers = array( | |
| 1886 'Date' => $RCMAIL->user_date(), | |
| 1887 'From' => $sender, | |
| 1888 'To' => $message->headers->mdn_to, | |
| 1889 'Subject' => $RCMAIL->gettext('receiptread') . ': ' . $message->subject, | |
| 1890 'Message-ID' => $RCMAIL->gen_message_id($identity['email']), | |
| 1891 'X-Sender' => $identity['email'], | |
| 1892 'References' => trim($message->headers->references . ' ' . $message->headers->messageID), | |
| 1893 'In-Reply-To' => $message->headers->messageID, | |
| 1894 ); | |
| 1895 | |
| 1896 $report = "Final-Recipient: rfc822; {$identity['email']}\r\n" | |
| 1897 . "Original-Message-ID: {$message->headers->messageID}\r\n" | |
| 1898 . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; | |
| 1899 | |
| 1900 if ($message->headers->to) { | |
| 1901 $report .= "Original-Recipient: {$message->headers->to}\r\n"; | |
| 1902 } | |
| 1903 | |
| 1904 if ($agent = $RCMAIL->config->get('useragent')) { | |
| 1905 $headers['User-Agent'] = $agent; | |
| 1906 $report .= "Reporting-UA: $agent\r\n"; | |
| 1907 } | |
| 1908 | |
| 1909 $to = rcube_mime::decode_mime_string($message->headers->to, $message->headers->charset); | |
| 1910 $date = $RCMAIL->format_date($message->headers->date, $RCMAIL->config->get('date_long')); | |
| 1911 $body = $RCMAIL->gettext("yourmessage") . "\r\n\r\n" . | |
| 1912 "\t" . $RCMAIL->gettext("to") . ": {$to}\r\n" . | |
| 1913 "\t" . $RCMAIL->gettext("subject") . ": {$message->subject}\r\n" . | |
| 1914 "\t" . $RCMAIL->gettext("date") . ": {$date}\r\n" . | |
| 1915 "\r\n" . $RCMAIL->gettext("receiptnote"); | |
| 1916 | |
| 1917 $compose->headers(array_filter($headers)); | |
| 1918 $compose->setContentType('multipart/report', array('report-type'=> 'disposition-notification')); | |
| 1919 $compose->setTXTBody(rcube_mime::wordwrap($body, 75, "\r\n")); | |
| 1920 $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline'); | |
| 1921 | |
| 1922 // SMTP options | |
| 1923 $options = array('mdn_use_from' => (bool) $RCMAIL->config->get('mdn_use_from')); | |
| 1924 | |
| 1925 $sent = $RCMAIL->deliver_message($compose, $identity['email'], $mailto, $smtp_error, $body_file, $options, true); | |
| 1926 | |
| 1927 if ($sent) { | |
| 1928 $RCMAIL->storage->set_flag($message->uid, 'MDNSENT'); | |
| 1929 return true; | |
| 1930 } | |
| 1931 } | |
| 1932 | |
| 1933 return false; | |
| 1934 } | |
| 1935 | |
| 1936 /** | |
| 1937 * Detect recipient identity from specified message | |
| 1938 */ | |
| 1939 function rcmail_identity_select($MESSAGE, $identities = null, $compose_mode = 'reply') | |
| 1940 { | |
| 1941 $a_recipients = array(); | |
| 1942 $a_names = array(); | |
| 1943 | |
| 1944 if ($identities === null) { | |
| 1945 $identities = rcmail::get_instance()->user->list_identities(null, true); | |
| 1946 } | |
| 1947 | |
| 1948 // extract all recipients of the reply-message | |
| 1949 if (is_object($MESSAGE->headers) && in_array($compose_mode, array('reply', 'forward'))) { | |
| 1950 $a_to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, true, $MESSAGE->headers->charset); | |
| 1951 foreach ($a_to as $addr) { | |
| 1952 if (!empty($addr['mailto'])) { | |
| 1953 $a_recipients[] = strtolower($addr['mailto']); | |
| 1954 $a_names[] = $addr['name']; | |
| 1955 } | |
| 1956 } | |
| 1957 | |
| 1958 if (!empty($MESSAGE->headers->cc)) { | |
| 1959 $a_cc = rcube_mime::decode_address_list($MESSAGE->headers->cc, null, true, $MESSAGE->headers->charset); | |
| 1960 foreach ($a_cc as $addr) { | |
| 1961 if (!empty($addr['mailto'])) { | |
| 1962 $a_recipients[] = strtolower($addr['mailto']); | |
| 1963 $a_names[] = $addr['name']; | |
| 1964 } | |
| 1965 } | |
| 1966 } | |
| 1967 } | |
| 1968 | |
| 1969 // decode From: address | |
| 1970 $from = rcube_mime::decode_address_list($MESSAGE->headers->from, null, true, $MESSAGE->headers->charset); | |
| 1971 $from = array_shift($from); | |
| 1972 $from['mailto'] = strtolower($from['mailto']); | |
| 1973 | |
| 1974 $from_idx = null; | |
| 1975 $found_idx = array('to' => null, 'from' => null); | |
| 1976 $check_from = in_array($compose_mode, array('draft', 'edit', 'reply')); | |
| 1977 | |
| 1978 // Select identity | |
| 1979 foreach ($identities as $idx => $ident) { | |
| 1980 // use From: header when in edit/draft or reply-to-self | |
| 1981 if ($check_from && $from['mailto'] == strtolower($ident['email_ascii'])) { | |
| 1982 // remember first matching identity address | |
| 1983 if ($found_idx['from'] === null) { | |
| 1984 $found_idx['from'] = $idx; | |
| 1985 } | |
| 1986 // match identity name | |
| 1987 if ($from['name'] && $ident['name'] && $from['name'] == $ident['name']) { | |
| 1988 $from_idx = $idx; | |
| 1989 break; | |
| 1990 } | |
| 1991 } | |
| 1992 // use replied/forwarded message recipients | |
| 1993 else if (($found = array_search(strtolower($ident['email_ascii']), $a_recipients)) !== false) { | |
| 1994 // remember first matching identity address | |
| 1995 if ($found_idx['to'] === null) { | |
| 1996 $found_idx['to'] = $idx; | |
| 1997 } | |
| 1998 // match identity name | |
| 1999 if ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name']) { | |
| 2000 $from_idx = $idx; | |
| 2001 break; | |
| 2002 } | |
| 2003 } | |
| 2004 } | |
| 2005 | |
| 2006 // If matching by name+address didn't find any matches, | |
| 2007 // get first found identity (address) if any | |
| 2008 if ($from_idx === null) { | |
| 2009 $from_idx = $found_idx['from'] !== null ? $found_idx['from'] : $found_idx['to']; | |
| 2010 } | |
| 2011 | |
| 2012 // Try Return-Path | |
| 2013 if ($from_idx === null && ($return_path = $MESSAGE->headers->others['return-path'])) { | |
| 2014 $return_path = array_map('strtolower', (array) $return_path); | |
| 2015 | |
| 2016 foreach ($identities as $idx => $ident) { | |
| 2017 // Return-Path header contains an email address, but on some mailing list | |
| 2018 // it can be e.g. <pear-dev-return-55250-local=domain.tld@lists.php.net> | |
| 2019 // where local@domain.tld is the address we're looking for (#1489241) | |
| 2020 $ident1 = strtolower($ident['email_ascii']); | |
| 2021 $ident2 = str_replace('@', '=', $ident1); | |
| 2022 $ident1 = '<' . $ident1 . '>'; | |
| 2023 $ident2 = '-' . $ident2 . '@'; | |
| 2024 | |
| 2025 foreach ($return_path as $path) { | |
| 2026 if ($path == $ident1 || stripos($path, $ident2)) { | |
| 2027 $from_idx = $idx; | |
| 2028 break 2; | |
| 2029 } | |
| 2030 } | |
| 2031 } | |
| 2032 } | |
| 2033 | |
| 2034 // See identity_select plugin for example usage of this hook | |
| 2035 $plugin = rcmail::get_instance()->plugins->exec_hook('identity_select', | |
| 2036 array('message' => $MESSAGE, 'identities' => $identities, 'selected' => $from_idx)); | |
| 2037 | |
| 2038 $selected = $plugin['selected']; | |
| 2039 | |
| 2040 // default identity is always first on the list | |
| 2041 return $identities[$selected !== null ? $selected : 0]; | |
| 2042 } | |
| 2043 | |
| 2044 // Fixes some content-type names | |
| 2045 function rcmail_fix_mimetype($name) | |
| 2046 { | |
| 2047 $map = array( | |
| 2048 'image/x-ms-bmp' => 'image/bmp', // #1490282 | |
| 2049 ); | |
| 2050 | |
| 2051 $name = strtolower($name); | |
| 2052 | |
| 2053 if ($alias = $map[$name]) { | |
| 2054 $name = $alias; | |
| 2055 } | |
| 2056 // Some versions of Outlook create garbage Content-Type: | |
| 2057 // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608 | |
| 2058 else if (preg_match('/^application\/pdf.+/', $name)) { | |
| 2059 $name = 'application/pdf'; | |
| 2060 } | |
| 2061 // treat image/pjpeg (image/pjpg, image/jpg) as image/jpeg (#1489097) | |
| 2062 else if (preg_match('/^image\/p?jpe?g$/', $name)) { | |
| 2063 $name = 'image/jpeg'; | |
| 2064 } | |
| 2065 | |
| 2066 return $name; | |
| 2067 } | |
| 2068 | |
| 2069 // return attachment filename, handle empty filename case | |
| 2070 function rcmail_attachment_name($attachment, $display = false) | |
| 2071 { | |
| 2072 global $RCMAIL; | |
| 2073 | |
| 2074 $filename = (string) $attachment->filename; | |
| 2075 $filename = preg_replace('/[\x00-\x1F\x7F]/', '', $filename); | |
| 2076 | |
| 2077 if ($filename === '') { | |
| 2078 if ($attachment->mimetype == 'text/html') { | |
| 2079 $filename = $RCMAIL->gettext('htmlmessage'); | |
| 2080 } | |
| 2081 else { | |
| 2082 $ext = (array) rcube_mime::get_mime_extensions($attachment->mimetype); | |
| 2083 $ext = array_shift($ext); | |
| 2084 $filename = $RCMAIL->gettext('messagepart') . ' ' . $attachment->mime_id; | |
| 2085 if ($ext) { | |
| 2086 $filename .= '.' . $ext; | |
| 2087 } | |
| 2088 } | |
| 2089 } | |
| 2090 | |
| 2091 // Display smart names for some known mimetypes | |
| 2092 if ($display) { | |
| 2093 if (preg_match('/application\/(pgp|pkcs7)-signature/i', $attachment->mimetype)) { | |
| 2094 $filename = $RCMAIL->gettext('digitalsig'); | |
| 2095 } | |
| 2096 } | |
| 2097 | |
| 2098 return $filename; | |
| 2099 } | |
| 2100 | |
| 2101 function rcmail_search_filter($attrib) | |
| 2102 { | |
| 2103 global $RCMAIL; | |
| 2104 | |
| 2105 if (!strlen($attrib['id'])) { | |
| 2106 $attrib['id'] = 'rcmlistfilter'; | |
| 2107 } | |
| 2108 | |
| 2109 $attrib['onchange'] = rcmail_output::JS_OBJECT_NAME.'.filter_mailbox(this.value)'; | |
| 2110 | |
| 2111 // Content-Type values of messages with attachments | |
| 2112 // the same as in app.js:add_message_row() | |
| 2113 $ctypes = array('application/', 'multipart/m', 'multipart/signed', 'multipart/report'); | |
| 2114 | |
| 2115 // Build search string of "with attachment" filter | |
| 2116 $attachment = trim(str_repeat(' OR', count($ctypes)-1)); | |
| 2117 foreach ($ctypes as $type) { | |
| 2118 $attachment .= ' HEADER Content-Type ' . rcube_imap_generic::escape($type); | |
| 2119 } | |
| 2120 | |
| 2121 $select = new html_select($attrib); | |
| 2122 $select->add($RCMAIL->gettext('all'), 'ALL'); | |
| 2123 $select->add($RCMAIL->gettext('unread'), 'UNSEEN'); | |
| 2124 $select->add($RCMAIL->gettext('flagged'), 'FLAGGED'); | |
| 2125 $select->add($RCMAIL->gettext('unanswered'), 'UNANSWERED'); | |
| 2126 if (!$RCMAIL->config->get('skip_deleted')) { | |
| 2127 $select->add($RCMAIL->gettext('deleted'), 'DELETED'); | |
| 2128 $select->add($RCMAIL->gettext('undeleted'), 'UNDELETED'); | |
| 2129 } | |
| 2130 $select->add($RCMAIL->gettext('withattachment'), $attachment); | |
| 2131 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('highest'), 'HEADER X-PRIORITY 1'); | |
| 2132 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('high'), 'HEADER X-PRIORITY 2'); | |
| 2133 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('normal'), 'NOT HEADER X-PRIORITY 1 NOT HEADER X-PRIORITY 2 NOT HEADER X-PRIORITY 4 NOT HEADER X-PRIORITY 5'); | |
| 2134 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('low'), 'HEADER X-PRIORITY 4'); | |
| 2135 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('lowest'), 'HEADER X-PRIORITY 5'); | |
| 2136 | |
| 2137 $RCMAIL->output->add_gui_object('search_filter', $attrib['id']); | |
| 2138 | |
| 19 | 2139 return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_filter'] : 'ALL'); |
| 0 | 2140 } |
| 2141 | |
| 2142 function rcmail_search_interval($attrib) | |
| 2143 { | |
| 2144 global $RCMAIL; | |
| 2145 | |
| 2146 if (!strlen($attrib['id'])) { | |
| 2147 $attrib['id'] = 'rcmsearchinterval'; | |
| 2148 } | |
| 2149 | |
| 2150 $select = new html_select($attrib); | |
| 2151 $select->add('', ''); | |
| 2152 | |
| 2153 foreach (array('1W', '1M', '1Y', '-1W', '-1M', '-1Y') as $value) { | |
| 2154 $select->add($RCMAIL->gettext('searchinterval' . $value), $value); | |
| 2155 } | |
| 2156 | |
| 2157 $RCMAIL->output->add_gui_object('search_interval', $attrib['id']); | |
| 2158 | |
| 19 | 2159 return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_interval'] : ''); |
| 0 | 2160 } |
| 2161 | |
| 2162 function rcmail_message_error() | |
| 2163 { | |
| 2164 global $RCMAIL; | |
| 2165 | |
| 2166 // Set env variables for messageerror.html template | |
| 2167 if ($RCMAIL->action == 'show') { | |
| 2168 $mbox_name = $RCMAIL->storage->get_folder(); | |
| 2169 | |
| 2170 $RCMAIL->output->set_env('mailbox', $mbox_name); | |
| 2171 $RCMAIL->output->set_env('uid', null); | |
| 2172 } | |
| 2173 | |
| 2174 // display error message | |
| 2175 $RCMAIL->output->show_message('messageopenerror', 'error'); | |
| 2176 // ... display message error page | |
| 2177 $RCMAIL->output->send('messageerror'); | |
| 2178 } | |
| 2179 | |
| 2180 function rcmail_message_import_form($attrib = array()) | |
| 2181 { | |
| 2182 global $RCMAIL; | |
| 2183 | |
| 2184 $RCMAIL->output->add_label('selectimportfile','importwait'); | |
| 2185 | |
| 2186 $input_attr = array( | |
| 2187 'multiple' => true, | |
| 2188 'name' => '_file[]', | |
| 2189 'accept' => ".eml, .mbox, message/rfc822, text/*", | |
| 2190 ); | |
| 2191 | |
| 2192 $attrib['prefix'] = html::tag('input', array('type' => 'hidden', 'name' => '_unlock', 'value' => '')) | |
| 2193 . html::tag('input', array('type' => 'hidden', 'name' => '_framed', 'value' => '1')); | |
| 2194 | |
| 2195 return $RCMAIL->upload_form($attrib, 'importform', 'import-messages', $input_attr); | |
| 2196 } | |
| 2197 | |
| 2198 /** | |
| 2199 * Add groups from the given address source to the address book widget | |
| 2200 */ | |
| 2201 function rcmail_compose_contact_groups($abook, $source_id, $search = null, $search_mode = 0) | |
| 2202 { | |
| 2203 global $RCMAIL, $OUTPUT; | |
| 2204 | |
| 2205 $jsresult = array(); | |
| 2206 foreach ($abook->list_groups($search, $search_mode) as $group) { | |
| 2207 $abook->reset(); | |
| 2208 $abook->set_group($group['ID']); | |
| 2209 | |
| 2210 // group (distribution list) with email address(es) | |
| 2211 if ($group['email']) { | |
| 2212 foreach ((array)$group['email'] as $email) { | |
| 2213 $row_id = 'G'.$group['ID']; | |
| 2214 $jsresult[$row_id] = format_email_recipient($email, $group['name']); | |
| 2215 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2216 'contactgroup' => html::span(array('title' => $email), rcube::Q($group['name']))), 'group'); | |
| 2217 } | |
| 2218 } | |
| 2219 // make virtual groups clickable to list their members | |
| 2220 else if ($group['virtual']) { | |
| 2221 $row_id = 'G'.$group['ID']; | |
| 2222 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2223 'contactgroup' => html::a(array( | |
| 2224 'href' => '#list', | |
| 2225 'rel' => $group['ID'], | |
| 2226 'title' => $RCMAIL->gettext('listgroup'), | |
| 2227 'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this,event)", | |
| 2228 rcmail_output::JS_OBJECT_NAME, $source_id, $group['ID']), | |
| 2229 ), rcube::Q($group['name']) . ' ' . html::span('action', '»'))), | |
| 2230 'group', | |
| 2231 array('ID' => $group['ID'], 'name' => $group['name'], 'virtual' => true)); | |
| 2232 } | |
| 2233 // show group with count | |
| 2234 else if (($result = $abook->count()) && $result->count) { | |
| 2235 $row_id = 'E'.$group['ID']; | |
| 2236 $jsresult[$row_id] = $group['name']; | |
| 2237 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2238 'contactgroup' => rcube::Q($group['name'] . ' (' . intval($result->count) . ')')), 'group'); | |
| 2239 } | |
| 2240 } | |
| 2241 | |
| 2242 $abook->reset(); | |
| 2243 $abook->set_group(0); | |
| 2244 | |
| 2245 return $jsresult; | |
| 2246 } | |
| 2247 | |
| 2248 function rcmail_save_attachment($message, $pid, $compose_id, $params = array()) | |
| 2249 { | |
| 2250 global $COMPOSE; | |
| 2251 | |
| 2252 $rcmail = rcmail::get_instance(); | |
| 2253 $storage = $rcmail->get_storage(); | |
| 2254 | |
| 2255 if ($pid) { | |
| 2256 // attachment requested | |
| 2257 $part = $message->mime_parts[$pid]; | |
| 2258 $size = $part->size; | |
| 2259 $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; | |
| 2260 $filename = $params['filename'] ?: rcmail_attachment_name($part); | |
| 2261 } | |
| 2262 else if (is_object($message)) { | |
| 2263 // the whole message requested | |
| 2264 $size = $message->size; | |
| 2265 $mimetype = 'message/rfc822'; | |
| 2266 $filename = $params['filename'] ?: 'message_rfc822.eml'; | |
| 2267 } | |
| 2268 else if (is_string($message)) { | |
| 2269 // the whole message requested | |
| 2270 $size = strlen($message); | |
| 2271 $data = $message; | |
| 2272 $mimetype = $params['mimetype']; | |
| 2273 $filename = $params['filename']; | |
| 2274 } | |
| 2275 | |
| 2276 if (!isset($data)) { | |
| 2277 // don't load too big attachments into memory | |
| 2278 if (!rcube_utils::mem_check($size)) { | |
| 2279 $temp_dir = unslashify($rcmail->config->get('temp_dir')); | |
| 2280 $path = tempnam($temp_dir, 'rcmAttmnt'); | |
| 2281 | |
| 2282 if ($fp = fopen($path, 'w')) { | |
| 2283 if ($pid) { | |
| 2284 // part body | |
| 2285 $message->get_part_body($pid, false, 0, $fp); | |
| 2286 } | |
| 2287 else { | |
| 2288 // complete message | |
| 2289 $storage->get_raw_body($message->uid, $fp); | |
| 2290 } | |
| 2291 | |
| 2292 fclose($fp); | |
| 2293 } | |
| 2294 else { | |
| 2295 return false; | |
| 2296 } | |
| 2297 } | |
| 2298 else if ($pid) { | |
| 2299 // part body | |
| 2300 $data = $message->get_part_body($pid); | |
| 2301 } | |
| 2302 else { | |
| 2303 // complete message | |
| 2304 $data = $storage->get_raw_body($message->uid); | |
| 2305 } | |
| 2306 } | |
| 2307 | |
| 2308 $attachment = array( | |
| 2309 'group' => $compose_id, | |
| 2310 'name' => $filename, | |
| 2311 'mimetype' => $mimetype, | |
| 2312 'content_id' => $part ? $part->content_id : null, | |
| 2313 'data' => $data, | |
| 2314 'path' => $path, | |
| 2315 'size' => $path ? filesize($path) : strlen($data), | |
| 2316 'charset' => $part ? $part->charset : $params['charset'], | |
| 2317 ); | |
| 2318 | |
| 2319 $attachment = $rcmail->plugins->exec_hook('attachment_save', $attachment); | |
| 2320 | |
| 2321 if ($attachment['status']) { | |
| 2322 unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); | |
| 2323 | |
| 2324 // rcube_session::append() replaces current session data with the old values | |
| 2325 // (in rcube_session::reload()). This is a problem in 'compose' action, because before | |
| 2326 // the first append() use we set some important data in the session. | |
| 2327 // It also overwrites attachments list. Fixing reload() is not so simple if possible | |
| 2328 // as we don't really know what has been added and what removed in meantime. | |
| 2329 // So, for now we'll do not use append() on 'compose' action (#1490608). | |
| 2330 | |
| 2331 if ($rcmail->action == 'compose') { | |
| 2332 $COMPOSE['attachments'][$attachment['id']] = $attachment; | |
| 2333 } | |
| 2334 else { | |
| 2335 $rcmail->session->append('compose_data_' . $compose_id . '.attachments', $attachment['id'], $attachment); | |
| 2336 } | |
| 2337 | |
| 2338 return $attachment; | |
| 2339 } | |
| 2340 else if ($path) { | |
| 2341 @unlink($path); | |
| 2342 } | |
| 2343 | |
| 2344 return false; | |
| 2345 } | |
| 2346 | |
| 2347 // Return mimetypes supported by the browser | |
| 2348 function rcmail_supported_mimetypes() | |
| 2349 { | |
| 2350 $rcmail = rcube::get_instance(); | |
| 2351 | |
| 2352 // mimetypes supported by the browser (default settings) | |
| 2353 $mimetypes = (array) $rcmail->config->get('client_mimetypes'); | |
| 2354 | |
| 2355 // Remove unsupported types, which makes that attachment which cannot be | |
| 2356 // displayed in a browser will be downloaded directly without displaying an overlay page | |
| 2357 if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) { | |
| 2358 unset($mimetypes[$key]); | |
| 2359 } | |
| 2360 | |
| 2361 if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) { | |
| 2362 unset($mimetypes[$key]); | |
| 2363 } | |
| 2364 | |
| 2365 foreach (array('tiff', 'webp') as $type) { | |
| 2366 if (empty($_SESSION['browser_caps'][$type]) && ($key = array_search('image/' . $type, $mimetypes)) !== false) { | |
| 2367 // can we convert it to jpeg? | |
| 2368 if (!rcube_image::is_convertable('image/' . $type)) { | |
| 2369 unset($mimetypes[$key]); | |
| 2370 } | |
| 2371 } | |
| 2372 } | |
| 2373 | |
| 2374 // @TODO: support mail preview for compose attachments | |
| 2375 if ($rcmail->action != 'compose' && !in_array('message/rfc822', $mimetypes)) { | |
| 2376 $mimetypes[] = 'message/rfc822'; | |
| 2377 } | |
| 2378 | |
| 2379 return array_values($mimetypes); | |
| 2380 } |
