Mercurial > hg > rc2
annotate program/steps/mail/func.inc @ 19:b6a96bdd6b29
More cleaning up php8 Warnings/deprecations
| author | Charlie Root |
|---|---|
| date | Wed, 08 Oct 2025 08:50:44 -0400 |
| parents | 1866b439e6d3 |
| children | 73124dd49283 |
| rev | line source |
|---|---|
| 0 | 1 <?php |
| 2 | |
| 3 /** | |
| 4 +-----------------------------------------------------------------------+ | |
| 5 | 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()) { | |
| 568 $OUTPUT->command('init_threads', (array) $roots, $mbox); | |
| 569 } | |
| 570 } | |
| 571 | |
| 572 /* | |
| 573 * Creates <THEAD> for message list table | |
| 574 */ | |
| 575 function rcmail_message_list_head($attrib, $a_show_cols) | |
| 576 { | |
| 577 global $RCMAIL; | |
| 578 | |
| 579 // check to see if we have some settings for sorting | |
| 580 $sort_col = $_SESSION['sort_col']; | |
| 581 $sort_order = $_SESSION['sort_order']; | |
| 582 | |
| 583 $dont_override = (array) $RCMAIL->config->get('dont_override'); | |
| 584 $disabled_sort = in_array('message_sort_col', $dont_override); | |
| 585 $disabled_order = in_array('message_sort_order', $dont_override); | |
| 586 | |
| 587 $RCMAIL->output->set_env('disabled_sort_col', $disabled_sort); | |
| 588 $RCMAIL->output->set_env('disabled_sort_order', $disabled_order); | |
| 589 | |
| 590 // define sortable columns | |
| 591 if ($disabled_sort) | |
| 592 $a_sort_cols = $sort_col && !$disabled_order ? array($sort_col) : array(); | |
| 593 else | |
| 2 | 594 $a_sort_cols = array('subject', 'date', 'from', 'to', 'fromto', 'size', 'cc','dates'); |
| 595 | |
| 596 #rcube::write_log('mail','asc: '.print_r($a_sort_cols,true)); | |
| 0 | 597 if (!empty($attrib['optionsmenuicon'])) { |
| 598 $list_menu = rcmail_options_menu_link($attrib); | |
| 599 } | |
| 600 | |
| 601 $cells = $coltypes = array(); | |
| 602 | |
| 603 // get name of smart From/To column in folder context | |
| 604 if (array_search('fromto', $a_show_cols) !== false) { | |
| 605 $smart_col = rcmail_message_list_smart_column_name(); | |
| 606 } | |
| 607 | |
| 608 foreach ($a_show_cols as $col) { | |
| 609 $label = ''; | |
| 610 $sortable = false; | |
| 611 $rel_col = $col == 'date' && $sort_col == 'arrival' ? 'arrival' : $col; | |
| 612 | |
| 613 // get column name | |
| 614 switch ($col) { | |
| 615 case 'flag': | |
| 616 $col_name = html::span('flagged', $RCMAIL->gettext('flagged')); | |
| 617 break; | |
| 618 case 'attachment': | |
| 619 case 'priority': | |
| 620 $col_name = html::span($col, $RCMAIL->gettext($col)); | |
| 621 break; | |
| 622 case 'status': | |
| 623 $col_name = html::span($col, $RCMAIL->gettext('readstatus')); | |
| 624 break; | |
| 625 case 'threads': | |
| 626 $col_name = (string) $list_menu; | |
| 627 break; | |
| 628 case 'fromto': | |
| 629 $label = $RCMAIL->gettext($smart_col); | |
| 630 $col_name = rcube::Q($label); | |
| 631 break; | |
| 632 default: | |
| 633 $label = $RCMAIL->gettext($col); | |
| 634 $col_name = rcube::Q($label); | |
| 635 } | |
| 636 | |
| 637 // make sort links | |
| 638 if (in_array($col, $a_sort_cols)) { | |
| 639 $sortable = true; | |
| 640 $col_name = html::a(array( | |
| 641 'href' => "./#sort", | |
| 642 'class' => 'sortcol', | |
| 643 'rel' => $rel_col, | |
| 644 'title' => $RCMAIL->gettext('sortby') | |
| 645 ), $col_name); | |
| 646 } | |
| 647 else if ($col_name[0] != '<') { | |
| 648 $col_name = '<span class="' . $col .'">' . $col_name . '</span>'; | |
| 649 } | |
| 650 | |
| 651 $sort_class = $rel_col == $sort_col && !$disabled_order ? " sorted$sort_order" : ''; | |
| 652 $class_name = $col.$sort_class; | |
| 653 | |
| 654 // put it all together | |
| 655 $cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name); | |
| 656 $coltypes[$col] = array('className' => $class_name, 'id' => "rcm$col", 'label' => $label, 'sortable' => $sortable); | |
| 657 } | |
| 658 | |
| 659 $RCMAIL->output->set_env('coltypes', $coltypes); | |
| 660 return $cells; | |
| 661 } | |
| 662 | |
| 663 function rcmail_options_menu_link($attrib) | |
| 664 { | |
| 665 global $RCMAIL; | |
| 666 | |
| 667 $onclick = 'return ' . rcmail_output::JS_OBJECT_NAME . ".command('menu-open', 'messagelistmenu', this, event)"; | |
| 668 $inner = $title = $RCMAIL->gettext('listoptions'); | |
| 669 | |
| 670 if (is_string($attrib['optionsmenuicon']) && $attrib['optionsmenuicon'] != 'true') { | |
| 671 $inner = html::img(array('src' => $RCMAIL->output->abs_url($attrib['optionsmenuicon'], true), 'alt' => $title)); | |
| 672 } | |
| 673 | |
| 674 return html::a(array( | |
| 675 'href' => '#list-options', | |
| 676 'onclick' => $onclick, | |
| 677 'class' => 'listmenu', | |
| 678 'id' => 'listmenulink', | |
| 679 'title' => $title, | |
| 680 'tabindex' => '0', | |
| 681 ), $inner); | |
| 682 } | |
| 683 | |
| 684 /** | |
| 685 * Return an HTML iframe for loading mail content | |
| 686 */ | |
| 687 function rcmail_messagecontent_frame($attrib) | |
| 688 { | |
| 689 global $OUTPUT; | |
| 690 | |
| 691 if (empty($attrib['id'])) { | |
| 692 $attrib['id'] = 'rcmailcontentwindow'; | |
| 693 } | |
| 694 | |
| 695 return $OUTPUT->frame($attrib, true); | |
| 696 } | |
| 697 | |
| 698 function rcmail_messagecount_display($attrib) | |
| 699 { | |
| 700 global $RCMAIL; | |
| 701 | |
| 19 | 702 if (empty($attrib['id'])) { |
| 0 | 703 $attrib['id'] = 'rcmcountdisplay'; |
| 704 } | |
| 705 | |
| 706 $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']); | |
| 707 | |
| 708 $content = $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : $RCMAIL->gettext('loading'); | |
| 709 | |
| 710 return html::span($attrib, $content); | |
| 711 } | |
| 712 | |
| 713 function rcmail_get_messagecount_text($count = null, $page = null) | |
| 714 { | |
| 715 global $RCMAIL; | |
| 716 | |
| 717 if ($page === null) { | |
| 718 $page = $RCMAIL->storage->get_page(); | |
| 719 } | |
| 720 | |
| 721 $page_size = $RCMAIL->storage->get_pagesize(); | |
| 722 $start_msg = ($page-1) * $page_size + 1; | |
| 723 $max = $count; | |
| 724 | |
| 725 if ($max === null && $RCMAIL->action) { | |
| 726 $max = $RCMAIL->storage->count(null, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); | |
| 727 } | |
| 728 | |
| 729 if (!$max) { | |
| 730 $out = $RCMAIL->storage->get_search_set() ? $RCMAIL->gettext('nomessages') : $RCMAIL->gettext('mailboxempty'); | |
| 731 } | |
| 732 else { | |
| 733 $out = $RCMAIL->gettext(array('name' => $RCMAIL->storage->get_threading() ? 'threadsfromto' : 'messagesfromto', | |
| 734 'vars' => array('from' => $start_msg, | |
| 735 'to' => min($max, $start_msg + $page_size - 1), | |
| 736 'count' => $max))); | |
| 737 } | |
| 738 | |
| 739 return rcube::Q($out); | |
| 740 } | |
| 741 | |
| 742 function rcmail_mailbox_name_display($attrib) | |
| 743 { | |
| 744 global $RCMAIL; | |
| 745 | |
| 746 if (!$attrib['id']) { | |
| 747 $attrib['id'] = 'rcmmailboxname'; | |
| 748 } | |
| 749 | |
| 750 $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']); | |
| 751 | |
| 752 return html::span($attrib, rcmail_get_mailbox_name_text()); | |
| 753 } | |
| 754 | |
| 755 function rcmail_get_mailbox_name_text() | |
| 756 { | |
| 757 global $RCMAIL; | |
| 758 return $RCMAIL->localize_foldername($RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder()); | |
| 759 } | |
| 760 | |
| 761 function rcmail_send_unread_count($mbox_name, $force=false, $count=null, $mark='') | |
| 762 { | |
| 763 global $RCMAIL; | |
| 764 | |
| 765 $old_unseen = rcmail_get_unseen_count($mbox_name); | |
| 766 $unseen = $count; | |
| 767 | |
| 768 if ($unseen === null) { | |
| 769 $unseen = $RCMAIL->storage->count($mbox_name, 'UNSEEN', $force); | |
| 770 } | |
| 771 | |
| 772 if ($unseen != $old_unseen || ($mbox_name == 'INBOX')) { | |
| 773 $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, | |
| 774 ($mbox_name == 'INBOX'), $unseen && $mark ? $mark : ''); | |
| 775 } | |
| 776 | |
| 777 rcmail_set_unseen_count($mbox_name, $unseen); | |
| 778 | |
| 779 return $unseen; | |
| 780 } | |
| 781 | |
| 782 function rcmail_set_unseen_count($mbox_name, $count) | |
| 783 { | |
| 784 // @TODO: this data is doubled (session and cache tables) if caching is enabled | |
| 785 | |
| 786 // Make sure we have an array here (#1487066) | |
| 19 | 787 if (!is_array($_SESSION['unseen_count']??null)) { |
| 0 | 788 $_SESSION['unseen_count'] = array(); |
| 789 } | |
| 790 | |
| 791 $_SESSION['unseen_count'][$mbox_name] = $count; | |
| 792 } | |
| 793 | |
| 794 function rcmail_get_unseen_count($mbox_name) | |
| 795 { | |
| 19 | 796 if (is_array($_SESSION['unseen_count']??null) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) { |
| 0 | 797 return $_SESSION['unseen_count'][$mbox_name]; |
| 798 } | |
| 799 } | |
| 800 | |
| 801 /** | |
| 802 * Sets message is_safe flag according to 'show_images' option value | |
| 803 * | |
| 804 * @param object rcube_message Message | |
| 805 */ | |
| 806 function rcmail_check_safe($message) | |
| 807 { | |
| 808 global $RCMAIL; | |
| 809 | |
| 810 if (!$message->is_safe | |
| 811 && ($show_images = $RCMAIL->config->get('show_images')) | |
| 812 && $message->has_html_part() | |
| 813 ) { | |
| 814 switch ($show_images) { | |
| 815 case 1: // known senders only | |
| 816 // get default addressbook, like in addcontact.inc | |
| 817 $CONTACTS = $RCMAIL->get_address_book(-1, true); | |
| 818 | |
| 819 if ($CONTACTS && $message->sender['mailto']) { | |
| 820 $result = $CONTACTS->search('email', $message->sender['mailto'], 1, false); | |
| 821 if ($result->count) { | |
| 822 $message->set_safe(true); | |
| 823 } | |
| 824 } | |
| 825 | |
| 826 $RCMAIL->plugins->exec_hook('message_check_safe', array('message' => $message)); | |
| 827 break; | |
| 828 | |
| 829 case 2: // always | |
| 830 $message->set_safe(true); | |
| 831 break; | |
| 832 } | |
| 833 } | |
| 834 | |
| 835 return !empty($message->is_safe); | |
| 836 } | |
| 837 | |
| 838 /** | |
| 839 * Cleans up the given message HTML Body (for displaying) | |
| 840 * | |
| 841 * @param string HTML | |
| 842 * @param array Display parameters | |
| 843 * @param array CID map replaces (inline images) | |
| 844 * @return string Clean HTML | |
| 845 */ | |
| 846 function rcmail_wash_html($html, $p, $cid_replaces = array()) | |
| 847 { | |
| 848 global $REMOTE_OBJECTS; | |
| 849 | |
| 850 $p += array('safe' => false, 'inline_html' => true); | |
| 851 | |
| 852 // charset was converted to UTF-8 in rcube_storage::get_message_part(), | |
| 853 // change/add charset specification in HTML accordingly, | |
| 854 // washtml cannot work without that | |
| 855 $meta = '<meta http-equiv="Content-Type" content="text/html; charset='.RCUBE_CHARSET.'" />'; | |
| 856 | |
| 857 // remove old meta tag and add the new one, making sure | |
| 858 // that it is placed in the head (#1488093) | |
| 859 $html = preg_replace('/<meta[^>]+charset=[a-z0-9-_]+[^>]*>/Ui', '', $html); | |
| 860 $html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); | |
| 861 if (!$rcount) { | |
| 862 $html = '<head>' . $meta . '</head>' . $html; | |
| 863 } | |
| 864 | |
| 865 // clean HTML with washhtml by Frederic Motte | |
| 866 $wash_opts = array( | |
| 867 'show_washed' => false, | |
| 868 'allow_remote' => $p['safe'], | |
| 869 'blocked_src' => 'program/resources/blocked.gif', | |
| 870 'charset' => RCUBE_CHARSET, | |
| 871 'cid_map' => $cid_replaces, | |
| 872 'html_elements' => array('body'), | |
| 873 ); | |
| 874 | |
| 875 if (!$p['inline_html']) { | |
| 876 $wash_opts['html_elements'] = array('html','head','title','body'); | |
| 877 } | |
| 878 if ($p['safe']) { | |
| 879 $wash_opts['html_elements'][] = 'link'; | |
| 880 $wash_opts['html_attribs'] = array('rel','type'); | |
| 881 } | |
| 882 | |
| 883 // overwrite washer options with options from plugins | |
| 884 if (isset($p['html_elements'])) | |
| 885 $wash_opts['html_elements'] = $p['html_elements']; | |
| 886 if (isset($p['html_attribs'])) | |
| 887 $wash_opts['html_attribs'] = $p['html_attribs']; | |
| 888 | |
| 889 // initialize HTML washer | |
| 890 $washer = new rcube_washtml($wash_opts); | |
| 891 | |
| 892 if (!$p['skip_washer_form_callback']) { | |
| 893 $washer->add_callback('form', 'rcmail_washtml_callback'); | |
| 894 } | |
| 895 | |
| 896 // allow CSS styles, will be sanitized by rcmail_washtml_callback() | |
| 897 if (!$p['skip_washer_style_callback']) { | |
| 898 $washer->add_callback('style', 'rcmail_washtml_callback'); | |
| 899 } | |
| 900 | |
| 901 // modify HTML links to open a new window if clicked | |
| 902 if (!$p['skip_washer_link_callback']) { | |
| 903 $washer->add_callback('a', 'rcmail_washtml_link_callback'); | |
| 904 $washer->add_callback('area', 'rcmail_washtml_link_callback'); | |
| 905 | |
| 906 if ($p['safe']) | |
| 907 $washer->add_callback('link', 'rcmail_washtml_link_callback'); | |
| 908 } | |
| 909 | |
| 910 // Remove non-UTF8 characters (#1487813) | |
| 911 $html = rcube_charset::clean($html); | |
| 912 | |
| 913 $html = $washer->wash($html); | |
| 914 $REMOTE_OBJECTS = $washer->extlinks; | |
| 915 | |
| 916 return $html; | |
| 917 } | |
| 918 | |
| 919 /** | |
| 920 * Convert the given message part to proper HTML | |
| 921 * which can be displayed the message view | |
| 922 * | |
| 923 * @param string Message part body | |
| 924 * @param rcube_message_part Message part | |
| 925 * @param array Display parameters array | |
| 926 * | |
| 927 * @return string Formatted HTML string | |
| 928 */ | |
| 929 function rcmail_print_body($body, $part, $p = array()) | |
| 930 { | |
| 931 global $RCMAIL; | |
| 932 | |
| 933 // trigger plugin hook | |
| 934 $data = $RCMAIL->plugins->exec_hook('message_part_before', | |
| 935 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) | |
| 936 + $p + array('safe' => false, 'plain' => false, 'inline_html' => true)); | |
| 937 | |
| 938 // convert html to text/plain | |
| 939 if ($data['plain'] && ($data['type'] == 'html' || $data['type'] == 'enriched')) { | |
| 940 if ($data['type'] == 'enriched') { | |
| 941 $data['body'] = rcube_enriched::to_html($data['body']); | |
| 942 } | |
| 943 | |
| 944 $body = $RCMAIL->html2text($data['body']); | |
| 945 $part->ctype_secondary = 'plain'; | |
| 946 } | |
| 947 // text/html | |
| 948 else if ($data['type'] == 'html') { | |
| 949 $body = rcmail_wash_html($data['body'], $data, $part->replaces); | |
| 950 $part->ctype_secondary = $data['type']; | |
| 951 } | |
| 952 // text/enriched | |
| 953 else if ($data['type'] == 'enriched') { | |
| 954 $body = rcube_enriched::to_html($data['body']); | |
| 955 $body = rcmail_wash_html($body, $data, $part->replaces); | |
| 956 $part->ctype_secondary = 'html'; | |
| 957 } | |
| 958 else { | |
| 959 // assert plaintext | |
| 960 $body = $data['body']; | |
| 961 $part->ctype_secondary = $data['type'] = 'plain'; | |
| 962 } | |
| 963 | |
| 964 // free some memory (hopefully) | |
| 965 unset($data['body']); | |
| 966 | |
| 967 // plaintext postprocessing | |
| 968 if ($part->ctype_secondary == 'plain') { | |
| 19 | 969 $flowed = ($part->ctype_parameters['format']??null) == 'flowed'; |
| 970 $delsp = ($part->ctype_parameters['delsp']??null) == 'yes'; | |
| 0 | 971 $body = rcmail_plain_body($body, $flowed, $delsp); |
| 972 } | |
| 973 | |
| 974 // allow post-processing of the message body | |
| 975 $data = $RCMAIL->plugins->exec_hook('message_part_after', | |
| 976 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) + $data); | |
| 977 | |
| 978 return $data['body']; | |
| 979 } | |
| 980 | |
| 981 /** | |
| 982 * Handle links and citation marks in plain text message | |
| 983 * | |
| 984 * @param string Plain text string | |
| 985 * @param boolean Set to True if the source text is in format=flowed | |
| 986 * | |
| 987 * @return string Formatted HTML string | |
| 988 */ | |
| 989 function rcmail_plain_body($body, $flowed = false, $delsp = false) | |
| 990 { | |
| 991 $options = array('flowed' => $flowed, 'wrap' => !$flowed, 'replacer' => 'rcmail_string_replacer', | |
| 992 'delsp' => $delsp); | |
| 993 $text2html = new rcube_text2html($body, false, $options); | |
| 994 $body = $text2html->get_html(); | |
| 995 | |
| 996 return $body; | |
| 997 } | |
| 998 | |
| 999 /** | |
| 1000 * Callback function for washtml cleaning class | |
| 1001 */ | |
| 1002 function rcmail_washtml_callback($tagname, $attrib, $content, $washtml) | |
| 1003 { | |
| 1004 switch ($tagname) { | |
| 1005 case 'form': | |
| 1006 $out = html::div('form', $content); | |
| 1007 break; | |
| 1008 | |
| 1009 case 'style': | |
| 1010 // Crazy big styles may freeze the browser (#1490539) | |
| 1011 // remove content with more than 5k lines | |
| 1012 if (substr_count($content, "\n") > 5000) { | |
| 1013 $out = ''; | |
| 1014 break; | |
| 1015 } | |
| 1016 | |
| 1017 // decode all escaped entities and reduce to ascii strings | |
| 1018 $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', rcube_utils::xss_entity_decode($content)); | |
| 1019 | |
| 1020 // now check for evil strings like expression, behavior or url() | |
| 1021 if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) { | |
| 1022 if (!$washtml->get_config('allow_remote') && preg_match('/url\((?!data:image)/', $stripped)) { | |
| 1023 $washtml->extlinks = true; | |
| 1024 } | |
| 1025 else { | |
| 1026 $out = html::tag('style', array('type' => 'text/css'), $content); | |
| 1027 } | |
| 1028 break; | |
| 1029 } | |
| 1030 | |
| 1031 default: | |
| 1032 $out = ''; | |
| 1033 } | |
| 1034 | |
| 1035 return $out; | |
| 1036 } | |
| 1037 | |
| 1038 /** | |
| 1039 * return table with message headers | |
| 1040 */ | |
| 1041 function rcmail_message_headers($attrib, $headers=null) | |
| 1042 { | |
| 1043 global $MESSAGE, $PRINT_MODE, $RCMAIL; | |
| 1044 static $sa_attrib; | |
| 1045 | |
| 1046 // keep header table attrib | |
| 19 | 1047 if (is_array($attrib) && !$sa_attrib && empty($attrib['valueof'])) { |
| 0 | 1048 $sa_attrib = $attrib; |
| 1049 } | |
| 1050 else if (!is_array($attrib) && is_array($sa_attrib)) { | |
| 1051 $attrib = $sa_attrib; | |
| 1052 } | |
| 1053 | |
| 1054 if (!isset($MESSAGE)) { | |
| 1055 return false; | |
| 1056 } | |
| 1057 | |
| 1058 // get associative array of headers object | |
| 1059 if (!$headers) { | |
| 1060 $headers_obj = $MESSAGE->headers; | |
| 1061 $headers = get_object_vars($MESSAGE->headers); | |
| 1062 } | |
| 1063 else if (is_object($headers)) { | |
| 1064 $headers_obj = $headers; | |
| 1065 $headers = get_object_vars($headers_obj); | |
| 1066 } | |
| 1067 else { | |
| 1068 $headers_obj = rcube_message_header::from_array($headers); | |
| 1069 } | |
| 1070 | |
| 1071 // show these headers | |
| 1072 $standard_headers = array('subject', 'from', 'sender', 'to', 'cc', 'bcc', 'replyto', | |
| 1073 'mail-reply-to', 'mail-followup-to', 'date', 'priority'); | |
| 19 | 1074 $exclude_headers = !empty($attrib['exclude']) ? explode(',', $attrib['exclude']) : array(); |
| 0 | 1075 $output_headers = array(); |
| 1076 | |
| 1077 foreach ($standard_headers as $hkey) { | |
| 19 | 1078 if ($headers[$hkey]??null) |
| 0 | 1079 $value = $headers[$hkey]; |
| 19 | 1080 else if ($headers['others'][$hkey]??null) |
| 0 | 1081 $value = $headers['others'][$hkey]; |
| 19 | 1082 else if (empty($attrib['valueof'])) |
| 0 | 1083 continue; |
| 1084 | |
| 1085 if (in_array($hkey, $exclude_headers)) | |
| 1086 continue; | |
| 1087 | |
| 1088 $ishtml = false; | |
| 1089 $header_title = $RCMAIL->gettext(preg_replace('/(^mail-|-)/', '', $hkey)); | |
| 1090 | |
| 1091 if ($hkey == 'date') { | |
| 1092 if ($PRINT_MODE) | |
| 1093 $header_value = $RCMAIL->format_date($value, $RCMAIL->config->get('date_long', 'x')); | |
| 1094 else | |
| 1095 $header_value = $RCMAIL->format_date($value); | |
| 1096 } | |
| 1097 else if ($hkey == 'priority') { | |
| 1098 if ($value) { | |
| 1099 $header_value = html::span('prio' . $value, rcube::Q(rcmail_localized_priority($value))); | |
| 1100 $ishtml = true; | |
| 1101 } | |
| 1102 else { | |
| 1103 continue; | |
| 1104 } | |
| 1105 } | |
| 1106 else if ($hkey == 'replyto') { | |
| 1107 if ($headers['replyto'] != $headers['from']) { | |
| 19 | 1108 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1109 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1110 $ishtml = true; |
| 1111 } | |
| 1112 else { | |
| 1113 continue; | |
| 1114 } | |
| 1115 } | |
| 1116 else if ($hkey == 'mail-reply-to') { | |
| 19 | 1117 if (($headers['mail-replyto']??null) != $headers['replyto'] |
| 0 | 1118 && $headers['replyto'] != $headers['from'] |
| 1119 ) { | |
| 19 | 1120 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1121 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1122 $ishtml = true; |
| 1123 } | |
| 1124 else { | |
| 1125 continue; | |
| 1126 } | |
| 1127 } | |
| 1128 else if ($hkey == 'sender') { | |
| 19 | 1129 if (($headers['sender']??null) != $headers['from']) { |
| 1130 $header_value = rcmail_address_string($value, $attrib['max']??null, true, | |
| 1131 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1132 $ishtml = true; |
| 1133 } | |
| 1134 else { | |
| 1135 continue; | |
| 1136 } | |
| 1137 } | |
| 1138 else if ($hkey == 'mail-followup-to') { | |
| 19 | 1139 $header_value = rcmail_address_string($value, $attrib['max']??null, |
| 1140 true, | |
| 1141 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1142 $ishtml = true; |
| 1143 } | |
| 1144 else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) { | |
| 19 | 1145 $header_value = rcmail_address_string($value, $attrib['max']??null, true, |
| 1146 $attrib['addicon']??null, $headers['charset'], $header_title); | |
| 0 | 1147 $ishtml = true; |
| 1148 } | |
| 1149 else if ($hkey == 'subject' && empty($value)) { | |
| 1150 $header_value = $RCMAIL->gettext('nosubject'); | |
| 1151 } | |
| 1152 else { | |
| 1153 $value = is_array($value) ? implode(' ', $value) : $value; | |
| 1154 $header_value = trim(rcube_mime::decode_header($value, $headers['charset'])); | |
| 1155 } | |
| 1156 | |
| 1157 $output_headers[$hkey] = array( | |
| 1158 'title' => $header_title, | |
| 1159 'value' => $header_value, | |
| 1160 'raw' => $value, | |
| 1161 'html' => $ishtml, | |
| 1162 ); | |
| 1163 } | |
| 1164 | |
| 1165 $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array( | |
| 1166 'output' => $output_headers, | |
| 1167 'headers' => $headers_obj, | |
| 1168 'exclude' => $exclude_headers, // readonly | |
| 1169 'folder' => $MESSAGE->folder, // readonly | |
| 1170 'uid' => $MESSAGE->uid, // readonly | |
| 1171 )); | |
| 1172 | |
| 1173 // single header value is requested | |
| 1174 if (!empty($attrib['valueof'])) { | |
| 1175 $row = $plugin['output'][$attrib['valueof']]; | |
| 1176 return $row['html'] ? $row['value'] : rcube::Q($row['value']); | |
| 1177 } | |
| 1178 | |
| 1179 // compose html table | |
| 1180 $table = new html_table(array('cols' => 2)); | |
| 1181 | |
| 1182 foreach ($plugin['output'] as $hkey => $row) { | |
| 1183 $val = $row['html'] ? $row['value'] : rcube::Q($row['value']); | |
| 1184 | |
| 1185 $table->add(array('class' => 'header-title'), rcube::Q($row['title'])); | |
| 1186 $table->add(array('class' => 'header '.$hkey), $val); | |
| 1187 } | |
| 1188 | |
| 1189 return $table->show($attrib); | |
| 1190 } | |
| 1191 | |
| 1192 /** | |
| 1193 * Convert Priority header value into a localized string | |
| 1194 */ | |
| 1195 function rcmail_localized_priority($value) | |
| 1196 { | |
| 1197 global $RCMAIL; | |
| 1198 | |
| 1199 $labels_map = array( | |
| 1200 '1' => 'highest', | |
| 1201 '2' => 'high', | |
| 1202 '3' => 'normal', | |
| 1203 '4' => 'low', | |
| 1204 '5' => 'lowest', | |
| 1205 ); | |
| 1206 | |
| 19 | 1207 if ($value && !empty($labels_map[$value])) { |
| 0 | 1208 return $RCMAIL->gettext($labels_map[$value]); |
| 1209 } | |
| 1210 | |
| 1211 return ''; | |
| 1212 } | |
| 1213 | |
| 1214 /** | |
| 1215 * return block to show full message headers | |
| 1216 */ | |
| 1217 function rcmail_message_full_headers($attrib) | |
| 1218 { | |
| 1219 global $OUTPUT, $RCMAIL; | |
| 1220 | |
| 1221 $html = html::div(array('id' => "all-headers", 'class' => "all", 'style' => 'display:none'), html::div(array('id' => 'headers-source'), '')); | |
| 1222 $html .= html::div(array( | |
| 1223 'class' => "more-headers show-headers", | |
| 1224 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('show-headers','',this)", | |
| 1225 'title' => $RCMAIL->gettext('togglefullheaders') | |
| 1226 ), ''); | |
| 1227 | |
| 1228 $OUTPUT->add_gui_object('all_headers_row', 'all-headers'); | |
| 1229 $OUTPUT->add_gui_object('all_headers_box', 'headers-source'); | |
| 1230 | |
| 1231 return html::div($attrib, $html); | |
| 1232 } | |
| 1233 | |
| 1234 /** | |
| 1235 * Handler for the 'messagebody' GUI object | |
| 1236 * | |
| 1237 * @param array Named parameters | |
| 1238 * @return string HTML content showing the message body | |
| 1239 */ | |
| 1240 function rcmail_message_body($attrib) | |
| 1241 { | |
| 1242 global $OUTPUT, $MESSAGE, $RCMAIL, $REMOTE_OBJECTS; | |
| 1243 | |
| 1244 if (!is_array($MESSAGE->parts) && empty($MESSAGE->body)) { | |
| 1245 return ''; | |
| 1246 } | |
| 1247 | |
| 1248 if (!$attrib['id']) | |
| 1249 $attrib['id'] = 'rcmailMsgBody'; | |
| 1250 | |
| 19 | 1251 $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']??null); |
| 0 | 1252 $out = ''; |
| 1253 $part_no = 0; | |
| 1254 | |
| 1255 $header_attrib = array(); | |
| 1256 foreach ($attrib as $attr => $value) { | |
| 1257 if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs)) { | |
| 1258 $header_attrib[$regs[1]] = $value; | |
| 1259 } | |
| 1260 } | |
| 1261 | |
| 1262 if (!empty($MESSAGE->parts)) { | |
| 1263 foreach ($MESSAGE->parts as $part) { | |
| 1264 if ($part->type == 'headers') { | |
| 1265 $out .= html::div('message-partheaders', rcmail_message_headers(count($header_attrib) ? $header_attrib : null, $part->headers)); | |
| 1266 } | |
| 1267 else if ($part->type == 'content') { | |
| 1268 // unsupported (e.g. encrypted) | |
| 19 | 1269 if ($part->realtype??null) { |
| 0 | 1270 if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') { |
| 1271 if (!empty($_SESSION['browser_caps']['pgpmime']) && ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part())) { | |
| 1272 $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption')); | |
| 1273 $OUTPUT->set_env('pgp_mime_part', $pgp_mime_part->mime_id); | |
| 1274 $OUTPUT->set_env('pgp_mime_container', '#' . $attrib['id']); | |
| 1275 $OUTPUT->add_label('loadingdata'); | |
| 1276 } | |
| 1277 | |
| 1278 if (!$MESSAGE->encrypted_part) { | |
| 1279 $out .= html::span('part-notice', $RCMAIL->gettext('encryptedmessage')); | |
| 1280 } | |
| 1281 } | |
| 1282 continue; | |
| 1283 } | |
| 1284 else if (!$part->size) { | |
| 1285 continue; | |
| 1286 } | |
| 1287 | |
| 1288 // Check if we have enough memory to handle the message in it | |
| 1289 // #1487424: we need up to 10x more memory than the body | |
| 1290 else if (!rcube_utils::mem_check($part->size * 10)) { | |
| 1291 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' ' | |
| 1292 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id | |
| 1293 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download'))); | |
| 1294 continue; | |
| 1295 } | |
| 1296 | |
| 1297 // fetch part body | |
| 1298 $body = $MESSAGE->get_part_body($part->mime_id, true); | |
| 1299 | |
| 1300 // message is cached but not exists (#1485443), or other error | |
| 1301 if ($body === false) { | |
| 1302 rcmail_message_error($MESSAGE->uid); | |
| 1303 } | |
| 1304 | |
| 1305 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', | |
| 1306 array('part' => $part, 'prefix' => '')); | |
| 1307 | |
| 1308 // Set attributes of the part container | |
| 1309 $container_class = $part->ctype_secondary == 'html' ? 'message-htmlpart' : 'message-part'; | |
| 1310 $container_id = $container_class . (++$part_no); | |
| 1311 $container_attrib = array('class' => $container_class, 'id' => $container_id); | |
| 1312 | |
| 1313 // Assign container ID to a global variable for use in rcmail_washtml_link_callback() | |
| 1314 $GLOBALS['rcmail_html_container_id'] = $container_id; | |
| 1315 | |
| 1316 // Parse the part content for display | |
| 1317 $body = rcmail_print_body($body, $part, array('safe' => $safe_mode, 'plain' => !$RCMAIL->config->get('prefer_html'))); | |
| 1318 | |
| 1319 // check if the message body is PGP encrypted | |
| 1320 if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) { | |
| 1321 $OUTPUT->set_env('is_pgp_content', '#' . $container_id); | |
| 1322 } | |
| 1323 | |
| 1324 if ($part->ctype_secondary == 'html') { | |
| 1325 $body = rcmail_html4inline($body, $container_id, 'rcmBody', $container_attrib, $safe_mode); | |
| 1326 } | |
| 1327 | |
| 1328 $out .= html::div($container_attrib, $plugin['prefix'] . $body); | |
| 1329 } | |
| 1330 } | |
| 1331 } | |
| 1332 else { | |
| 1333 // Check if we have enough memory to handle the message in it | |
| 1334 // #1487424: we need up to 10x more memory than the body | |
| 1335 if (!rcube_utils::mem_check(strlen($MESSAGE->body) * 10)) { | |
| 1336 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' ' | |
| 1337 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part=0' | |
| 1338 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download'))); | |
| 1339 } | |
| 1340 else { | |
| 1341 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', | |
| 1342 array('part' => $MESSAGE, 'prefix' => '')); | |
| 1343 | |
| 1344 $out .= html::div('message-part', | |
| 1345 $plugin['prefix'] . rcmail_plain_body($MESSAGE->body)); | |
| 1346 } | |
| 1347 } | |
| 1348 | |
| 1349 // list images after mail body | |
| 1350 if ($RCMAIL->config->get('inline_images', true) && !empty($MESSAGE->attachments)) { | |
| 1351 $thumbnail_size = $RCMAIL->config->get('image_thumbnail_size', 240); | |
| 1352 $client_mimetypes = (array)$RCMAIL->config->get('client_mimetypes'); | |
| 1353 | |
| 1354 foreach ($MESSAGE->attachments as $attach_prop) { | |
| 1355 // skip inline images | |
| 1356 if ($attach_prop->content_id && $attach_prop->disposition == 'inline') { | |
| 1357 continue; | |
| 1358 } | |
| 1359 | |
| 1360 // Content-Type: image/*... | |
| 1361 if ($mimetype = rcmail_part_image_type($attach_prop)) { | |
| 1362 // display thumbnails | |
| 1363 if ($thumbnail_size) { | |
| 1364 $supported = in_array($mimetype, $client_mimetypes); | |
| 1365 $show_link = array( | |
| 1366 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), | |
| 1367 'onclick' => sprintf( | |
| 1368 'return %s.command(\'load-attachment\',\'%s\',this)', | |
| 1369 rcmail_output::JS_OBJECT_NAME, | |
| 1370 $attach_prop->mime_id) | |
| 1371 ); | |
| 1372 | |
| 1373 $out .= html::p(array('class' => 'image-attachment', 'style' => $supported ? '' : 'display:none'), | |
| 1374 html::a($show_link + array('class' => 'image-link', 'style' => sprintf('width:%dpx', $thumbnail_size)), | |
| 1375 html::img(array( | |
| 1376 'class' => 'image-thumbnail', | |
| 1377 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image') . '&_thumb=1', | |
| 1378 'title' => $attach_prop->filename, | |
| 1379 'alt' => $attach_prop->filename, | |
| 1380 'style' => sprintf('max-width:%dpx; max-height:%dpx', $thumbnail_size, $thumbnail_size), | |
| 1381 'onload' => $supported ? '' : '$(this).parents(\'p.image-attachment\').show()', | |
| 1382 )) | |
| 1383 ) . | |
| 1384 html::span('image-filename', rcube::Q($attach_prop->filename)) . | |
| 1385 html::span('image-filesize', rcube::Q($RCMAIL->message_part_size($attach_prop))) . | |
| 1386 html::span('attachment-links', | |
| 1387 ($supported ? html::a($show_link, $RCMAIL->gettext('showattachment')) . ' ' : '') . | |
| 1388 html::a($show_link['href'] . '&_download=1', $RCMAIL->gettext('download')) | |
| 1389 ) . | |
| 1390 html::br(array('style' => 'clear:both')) | |
| 1391 ); | |
| 1392 } | |
| 1393 else { | |
| 1394 $out .= html::tag('fieldset', 'image-attachment', | |
| 1395 html::tag('legend', 'image-filename', rcube::Q($attach_prop->filename)) . | |
| 1396 html::p(array('align' => 'center'), | |
| 1397 html::img(array( | |
| 1398 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image'), | |
| 1399 'title' => $attach_prop->filename, | |
| 1400 'alt' => $attach_prop->filename, | |
| 1401 ))) | |
| 1402 ); | |
| 1403 } | |
| 1404 } | |
| 1405 } | |
| 1406 } | |
| 1407 | |
| 1408 // tell client that there are blocked remote objects | |
| 1409 if ($REMOTE_OBJECTS && !$safe_mode) { | |
| 1410 $OUTPUT->set_env('blockedobjects', true); | |
| 1411 } | |
| 1412 | |
| 1413 return html::div($attrib, $out); | |
| 1414 } | |
| 1415 | |
| 1416 function rcmail_part_image_type($part) | |
| 1417 { | |
| 1418 $mimetype = strtolower($part->mimetype); | |
| 1419 | |
| 1420 // Skip TIFF/WEBP images if browser doesn't support this format | |
| 1421 // ...until we can convert them to JPEG | |
| 1422 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tiff']); | |
| 1423 $tiff_support = $tiff_support || rcube_image::is_convertable('image/tiff'); | |
| 1424 $webp_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['webp']); | |
| 1425 $webp_support = $webp_support || rcube_image::is_convertable('image/webp'); | |
| 1426 | |
| 1427 if ((!$tiff_support && $mimetype == 'image/tiff') || (!$webp_support && $mimetype == 'image/webp')) { | |
| 1428 return; | |
| 1429 } | |
| 1430 | |
| 1431 // Content-Type: image/*... | |
| 1432 if (strpos($mimetype, 'image/') === 0) { | |
| 1433 return rcmail_fix_mimetype($mimetype); | |
| 1434 } | |
| 1435 | |
| 1436 // Many clients use application/octet-stream, we'll detect mimetype | |
| 1437 // by checking filename extension | |
| 1438 | |
| 1439 // Supported image filename extensions to image type map | |
| 1440 $types = array( | |
| 1441 'jpg' => 'image/jpeg', | |
| 1442 'jpeg' => 'image/jpeg', | |
| 1443 'png' => 'image/png', | |
| 1444 'gif' => 'image/gif', | |
| 1445 'bmp' => 'image/bmp', | |
| 1446 ); | |
| 1447 if ($tiff_support) { | |
| 1448 $types['tif'] = 'image/tiff'; | |
| 1449 $types['tiff'] = 'image/tiff'; | |
| 1450 } | |
| 1451 if ($webp_support) { | |
| 1452 $types['webp'] = 'image/webp'; | |
| 1453 } | |
| 1454 | |
| 1455 if ($part->filename | |
| 1456 && $mimetype == 'application/octet-stream' | |
| 1457 && preg_match('/\.([^.]+)$/i', $part->filename, $m) | |
| 1458 && ($extension = strtolower($m[1])) | |
| 1459 && isset($types[$extension]) | |
| 1460 ) { | |
| 1461 return $types[$extension]; | |
| 1462 } | |
| 1463 } | |
| 1464 | |
| 1465 /** | |
| 1466 * Modify a HTML message that it can be displayed inside a HTML page | |
| 1467 */ | |
| 1468 function rcmail_html4inline($body, $container_id, $body_class='', &$attributes=array(), $allow_remote=false) | |
| 1469 { | |
| 1470 $last_style_pos = 0; | |
| 1471 $cont_id = $container_id . ($body_class ? ' div.'.$body_class : ''); | |
| 1472 | |
| 1473 // find STYLE tags | |
| 1474 while (($pos = stripos($body, '<style', $last_style_pos)) && ($pos2 = stripos($body, '</style>', $pos))) { | |
| 1475 $pos = strpos($body, '>', $pos) + 1; | |
| 1476 $len = $pos2 - $pos; | |
| 1477 | |
| 1478 // replace all css definitions with #container [def] | |
| 1479 $styles = substr($body, $pos, $len); | |
| 1480 $styles = rcube_utils::mod_css_styles($styles, $cont_id, $allow_remote); | |
| 1481 | |
| 1482 $body = substr_replace($body, $styles, $pos, $len); | |
| 1483 $last_style_pos = $pos2 + strlen($styles) - $len; | |
| 1484 } | |
| 1485 | |
| 1486 $body = preg_replace(array( | |
| 1487 // add comments around html and other tags | |
| 1488 '/(<!DOCTYPE[^>]*>)/i', | |
| 1489 '/(<\?xml[^>]*>)/i', | |
| 1490 '/(<\/?html[^>]*>)/i', | |
| 1491 '/(<\/?head[^>]*>)/i', | |
| 1492 '/(<title[^>]*>.*<\/title>)/Ui', | |
| 1493 '/(<\/?meta[^>]*>)/i', | |
| 1494 // quote <? of php and xml files that are specified as text/html | |
| 1495 '/<\?/', | |
| 1496 '/\?>/', | |
| 1497 // replace <body> with <div> | |
| 1498 '/<body([^>]*)>/i', | |
| 1499 '/<\/body>/i', | |
| 1500 ), | |
| 1501 array( | |
| 1502 '<!--\\1-->', | |
| 1503 '<!--\\1-->', | |
| 1504 '<!--\\1-->', | |
| 1505 '<!--\\1-->', | |
| 1506 '<!--\\1-->', | |
| 1507 '<!--\\1-->', | |
| 1508 '<?', | |
| 1509 '?>', | |
| 1510 '<div class="' . $body_class . '"\\1>', | |
| 1511 '</div>', | |
| 1512 ), | |
| 1513 $body); | |
| 1514 | |
| 1515 // Handle body attributes that doesn't play nicely with div elements | |
| 1516 $regexp = '/<div class="' . preg_quote($body_class, '/') . '"([^>]*)/'; | |
| 1517 if (preg_match($regexp, $body, $m)) { | |
| 1518 $style = array(); | |
| 1519 $attrs = $m[0]; | |
| 1520 | |
| 1521 // Get bgcolor, we'll set it as background-color of the message container | |
| 1522 if ($m[1] && preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/i', $attrs, $mb)) { | |
| 1523 $style['background-color'] = $mb[1]; | |
| 1524 $attrs = preg_replace('/bgcolor=["\']*[a-z0-9#]+["\']*/i', '', $attrs); | |
| 1525 } | |
| 1526 | |
| 1527 // Get background, we'll set it as background-image of the message container | |
| 1528 if ($m[1] && preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) { | |
| 1529 $style['background-image'] = 'url('.$mb[1].')'; | |
| 1530 $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs); | |
| 1531 } | |
| 1532 | |
| 1533 if (!empty($style)) { | |
| 1534 $body = preg_replace($regexp, rtrim($attrs), $body, 1); | |
| 1535 } | |
| 1536 | |
| 1537 // handle body styles related to background image | |
| 1538 if ($style['background-image']) { | |
| 1539 // get body style | |
| 1540 if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) { | |
| 1541 // get background related style | |
| 1542 $regexp = '/(background-position|background-repeat)\s*:\s*([^;]+);/i'; | |
| 1543 if (preg_match_all($regexp, $m[1], $matches, PREG_SET_ORDER)) { | |
| 1544 foreach ($matches as $m) { | |
| 1545 $style[$m[1]] = $m[2]; | |
| 1546 } | |
| 1547 } | |
| 1548 } | |
| 1549 } | |
| 1550 | |
| 1551 if (!empty($style)) { | |
| 1552 foreach ($style as $idx => $val) { | |
| 1553 $style[$idx] = $idx . ': ' . $val; | |
| 1554 } | |
| 1555 | |
| 1556 $attributes['style'] = implode('; ', $style); | |
| 1557 } | |
| 1558 } | |
| 1559 // make sure there's 'rcmBody' div, we need it for proper css modification | |
| 1560 // its name is hardcoded in rcmail_message_body() also | |
| 1561 else { | |
| 1562 $body = '<div class="' . $body_class . '">' . $body . '</div>'; | |
| 1563 } | |
| 1564 | |
| 1565 return $body; | |
| 1566 } | |
| 1567 | |
| 1568 /** | |
| 1569 * Parse link (a, link, area) attributes and set correct target | |
| 1570 */ | |
| 1571 function rcmail_washtml_link_callback($tag, $attribs, $content, $washtml) | |
| 1572 { | |
| 1573 global $RCMAIL; | |
| 1574 | |
| 1575 $attrib = html::parse_attrib_string($attribs); | |
| 1576 | |
| 1577 // Remove non-printable characters in URL (#1487805) | |
| 1578 if ($attrib['href']) { | |
| 1579 $attrib['href'] = preg_replace('/[\x00-\x1F]/', '', $attrib['href']); | |
| 1580 } | |
| 1581 | |
| 1582 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { | |
| 1583 $tempurl = 'tmp-' . md5($attrib['href']) . '.css'; | |
| 1584 $_SESSION['modcssurls'][$tempurl] = $attrib['href']; | |
| 1585 $attrib['href'] = $RCMAIL->url(array('task' => 'utils', 'action' => 'modcss', 'u' => $tempurl, 'c' => $GLOBALS['rcmail_html_container_id'])); | |
| 1586 $end = ' />'; | |
| 1587 } | |
| 1588 else if (preg_match('/^mailto:(.+)/i', $attrib['href'], $mailto)) { | |
| 1589 list($mailto, $url) = explode('?', html_entity_decode($mailto[1], ENT_QUOTES, 'UTF-8'), 2); | |
| 1590 | |
| 1591 // #6020: use raw encoding for correct "+" character handling as specified in RFC6068 | |
| 1592 $url = rawurldecode($url); | |
| 1593 $mailto = rawurldecode($mailto); | |
| 1594 $addresses = rcube_mime::decode_address_list($mailto, null, true); | |
| 1595 $mailto = array(); | |
| 1596 | |
| 1597 // do sanity checks on recipients | |
| 1598 foreach ($addresses as $idx => $addr) { | |
| 1599 if (rcube_utils::check_email($addr['mailto'], false)) { | |
| 1600 $addresses[$idx] = $addr['mailto']; | |
| 1601 $mailto[] = $addr['string']; | |
| 1602 } | |
| 1603 else { | |
| 1604 unset($addresses[$idx]); | |
| 1605 } | |
| 1606 } | |
| 1607 | |
| 1608 if (!empty($addresses)) { | |
| 1609 $attrib['href'] = 'mailto:' . implode(',', $addresses); | |
| 1610 $attrib['onclick'] = sprintf( | |
| 1611 "return %s.command('compose','%s',this)", | |
| 1612 rcmail_output::JS_OBJECT_NAME, | |
| 1613 rcube::JQ(implode(',', $mailto) . ($url ? "?$url" : ''))); | |
| 1614 } | |
| 1615 else { | |
| 1616 $attrib['href'] = '#NOP'; | |
| 1617 $attrib['onclick'] = ''; | |
| 1618 } | |
| 1619 } | |
| 1620 else if (empty($attrib['href']) && !isset($attrib['name'])) { | |
| 1621 $attrib['href'] = './#NOP'; | |
| 1622 $attrib['onclick'] = 'return false'; | |
| 1623 } | |
| 1624 else if (!empty($attrib['href']) && $attrib['href'][0] != '#') { | |
| 1625 $attrib['target'] = '_blank'; | |
| 1626 } | |
| 1627 | |
| 1628 // Better security by adding rel="noreferrer" (#1484686) | |
| 1629 if (($tag == 'a' || $tag == 'area') && $attrib['href'] && $attrib['href'][0] != '#') { | |
| 1630 $attrib['rel'] = 'noreferrer'; | |
| 1631 } | |
| 1632 | |
| 1633 // allowed attributes for a|link|area tags | |
| 1634 $allow = array('href','name','target','onclick','id','class','style','title', | |
| 1635 'rel','type','media','alt','coords','nohref','hreflang','shape'); | |
| 1636 | |
| 1637 return html::tag($tag, $attrib, $content, $allow); | |
| 1638 } | |
| 1639 | |
| 1640 /** | |
| 1641 * Decode address string and re-format it as HTML links | |
| 1642 */ | |
| 1643 function rcmail_address_string($input, $max=null, $linked=false, $addicon=null, $default_charset=null, $title=null) | |
| 1644 { | |
| 1645 global $RCMAIL, $PRINT_MODE; | |
| 1646 | |
| 1647 $a_parts = rcube_mime::decode_address_list($input, null, true, $default_charset); | |
| 1648 | |
| 1649 if (!count($a_parts)) { | |
| 1650 return $input; | |
| 1651 } | |
| 1652 | |
| 1653 $c = count($a_parts); | |
| 1654 $j = 0; | |
| 1655 $out = ''; | |
|
16
1866b439e6d3
Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents:
5
diff
changeset
|
1656 $moreadrs = null; |
| 0 | 1657 $allvalues = array(); |
| 1658 $show_email = $RCMAIL->config->get('message_show_email'); | |
| 1659 | |
| 1660 if ($addicon && !isset($_SESSION['writeable_abook'])) { | |
| 1661 $_SESSION['writeable_abook'] = $RCMAIL->get_address_sources(true) ? true : false; | |
| 1662 } | |
| 1663 | |
| 1664 foreach ($a_parts as $part) { | |
| 1665 $j++; | |
| 1666 | |
| 1667 $name = $part['name']; | |
| 1668 $mailto = $part['mailto']; | |
| 1669 $string = $part['string']; | |
| 1670 $valid = rcube_utils::check_email($mailto, false); | |
| 1671 | |
| 1672 // phishing email prevention (#1488981), e.g. "valid@email.addr <phishing@email.addr>" | |
| 1673 if (!$show_email && $valid && $name && $name != $mailto && strpos($name, '@')) { | |
| 1674 $name = ''; | |
| 1675 } | |
| 1676 | |
| 1677 // IDNA ASCII to Unicode | |
| 1678 if ($name == $mailto) | |
| 1679 $name = rcube_utils::idn_to_utf8($name); | |
| 1680 if ($string == $mailto) | |
| 1681 $string = rcube_utils::idn_to_utf8($string); | |
| 1682 $mailto = rcube_utils::idn_to_utf8($mailto); | |
| 1683 | |
| 1684 if ($PRINT_MODE) { | |
| 1685 $address = sprintf('%s <%s>', rcube::Q($name), rcube::Q($mailto)); | |
| 1686 } | |
| 1687 else if ($valid) { | |
| 1688 if ($linked) { | |
| 1689 $attrs = array( | |
| 1690 'href' => 'mailto:' . $mailto, | |
| 1691 'class' => 'rcmContactAddress', | |
| 1692 'onclick' => sprintf("return %s.command('compose','%s',this)", | |
| 1693 rcmail_output::JS_OBJECT_NAME, rcube::JQ(format_email_recipient($mailto, $name))), | |
| 1694 ); | |
| 1695 | |
| 1696 if ($show_email && $name && $mailto) { | |
| 1697 $content = rcube::Q($name ? sprintf('%s <%s>', $name, $mailto) : $mailto); | |
| 1698 } | |
| 1699 else { | |
| 1700 $content = rcube::Q($name ?: $mailto); | |
| 1701 $attrs['title'] = $mailto; | |
| 1702 } | |
| 1703 | |
| 1704 $address = html::a($attrs, $content); | |
| 1705 } | |
| 1706 else { | |
| 1707 $address = html::span(array('title' => $mailto, 'class' => "rcmContactAddress"), | |
| 1708 rcube::Q($name ?: $mailto)); | |
| 1709 } | |
| 1710 | |
| 1711 if ($addicon && $_SESSION['writeable_abook']) { | |
| 1712 $address .= html::a(array( | |
| 1713 'href' => "#add", | |
| 1714 'title' => $RCMAIL->gettext('addtoaddressbook'), | |
| 1715 'class' => 'rcmaddcontact', | |
| 1716 'onclick' => sprintf("return %s.command('add-contact','%s',this)", | |
| 1717 rcmail_output::JS_OBJECT_NAME, rcube::JQ($string)), | |
| 1718 ), | |
| 1719 html::img(array( | |
| 1720 'src' => $RCMAIL->output->abs_url($addicon, true), | |
| 1721 'alt' => "Add contact", | |
| 1722 'class' => 'noselect', | |
| 1723 ))); | |
| 1724 } | |
| 1725 } | |
| 1726 else { | |
| 1727 $address = $name ? rcube::Q($name) : ''; | |
| 1728 if ($mailto) { | |
| 1729 $address = trim($address . ' ' . rcube::Q($name ? sprintf('<%s>', $mailto) : $mailto)); | |
| 1730 } | |
| 1731 } | |
| 1732 | |
| 1733 $address = html::span('adr', $address); | |
| 1734 $allvalues[] = $address; | |
| 1735 | |
| 1736 if (!$moreadrs) { | |
| 1737 $out .= ($out ? ', ' : '') . $address; | |
| 1738 } | |
| 1739 | |
| 1740 if ($max && $j == $max && $c > $j) { | |
| 1741 if ($linked) { | |
| 1742 $moreadrs = $c - $j; | |
| 1743 } | |
| 1744 else { | |
| 1745 $out .= '...'; | |
| 1746 break; | |
| 1747 } | |
| 1748 } | |
| 1749 } | |
| 1750 | |
| 1751 if ($moreadrs) { | |
| 1752 $label = rcube::Q($RCMAIL->gettext(array('name' => 'andnmore', 'vars' => array('nr' => $moreadrs)))); | |
| 1753 | |
| 1754 if ($PRINT_MODE) { | |
| 1755 $out .= ' ' . html::a(array( | |
| 1756 'href' => '#more', | |
| 1757 'class' => 'morelink', | |
| 1758 'onclick' => '$(this).hide().next().show()', | |
| 1759 ), $label) | |
| 1760 . html::span(array('style' => 'display:none'), join(', ', $allvalues)); | |
| 1761 } | |
| 1762 else { | |
| 1763 $out .= ' ' . html::a(array( | |
| 1764 'href' => '#more', | |
| 1765 'class' => 'morelink', | |
| 1766 'onclick' => sprintf("return %s.show_popup_dialog('%s','%s')", | |
| 1767 rcmail_output::JS_OBJECT_NAME, | |
| 1768 rcube::JQ(join(', ', $allvalues)), | |
| 1769 rcube::JQ($title)) | |
| 1770 ), $label); | |
| 1771 } | |
| 1772 } | |
| 1773 | |
| 1774 return $out; | |
| 1775 } | |
| 1776 | |
| 1777 /** | |
| 1778 * Wrap text to a given number of characters per line | |
| 1779 * but respect the mail quotation of replies messages (>). | |
| 1780 * Finally add another quotation level by prepending the lines | |
| 1781 * with > | |
| 1782 * | |
| 1783 * @param string Text to wrap | |
| 1784 * @param int The line width | |
| 1785 * @return string The wrapped text | |
| 1786 */ | |
| 1787 function rcmail_wrap_and_quote($text, $length = 72) | |
| 1788 { | |
| 1789 // Rebuild the message body with a maximum of $max chars, while keeping quoted message. | |
| 1790 $max = max(75, $length + 8); | |
| 1791 $lines = preg_split('/\r?\n/', trim($text)); | |
| 1792 $out = ''; | |
| 1793 | |
| 1794 foreach ($lines as $line) { | |
| 1795 // don't wrap already quoted lines | |
| 1796 if ($line[0] == '>') { | |
| 1797 $line = '>' . rtrim($line); | |
| 1798 } | |
| 1799 else if (mb_strlen($line) > $max) { | |
| 1800 $newline = ''; | |
| 1801 | |
| 1802 foreach (explode("\n", rcube_mime::wordwrap($line, $length - 2)) as $l) { | |
| 1803 $newline .= strlen($l) ? "> $l\n" : ">\n"; | |
| 1804 } | |
| 1805 | |
| 1806 $line = rtrim($newline); | |
| 1807 } | |
| 1808 else { | |
| 1809 $line = '> ' . $line; | |
| 1810 } | |
| 1811 | |
| 1812 // Append the line | |
| 1813 $out .= $line . "\n"; | |
| 1814 } | |
| 1815 | |
| 1816 return rtrim($out, "\n"); | |
| 1817 } | |
| 1818 | |
| 1819 function rcmail_draftinfo_encode($p) | |
| 1820 { | |
| 1821 $parts = array(); | |
| 1822 foreach ($p as $key => $val) { | |
| 1823 $encode = $key == 'folder' || strpos($val, ';') !== false; | |
| 1824 $parts[] = $key . '=' . ($encode ? 'B::' . base64_encode($val) : $val); | |
| 1825 } | |
| 1826 | |
| 1827 return join('; ', $parts); | |
| 1828 } | |
| 1829 | |
| 1830 function rcmail_draftinfo_decode($str) | |
| 1831 { | |
| 1832 $info = array(); | |
| 1833 | |
| 1834 foreach (preg_split('/;\s+/', $str) as $part) { | |
| 1835 list($key, $val) = explode('=', $part, 2); | |
| 1836 if (strpos($val, 'B::') === 0) { | |
| 1837 $val = base64_decode(substr($val, 3)); | |
| 1838 } | |
| 1839 else if ($key == 'folder') { | |
| 1840 $val = base64_decode($val); | |
| 1841 } | |
| 1842 | |
| 1843 $info[$key] = $val; | |
| 1844 } | |
| 1845 | |
| 1846 return $info; | |
| 1847 } | |
| 1848 | |
| 1849 /** | |
| 1850 * Send the MDN response | |
| 1851 * | |
| 1852 * @param mixed $message Original message object (rcube_message) or UID | |
| 1853 * @param array $smtp_error SMTP error array (reference) | |
| 1854 * | |
| 1855 * @return boolean Send status | |
| 1856 */ | |
| 1857 function rcmail_send_mdn($message, &$smtp_error) | |
| 1858 { | |
| 1859 global $RCMAIL; | |
| 1860 | |
| 1861 if (!is_object($message) || !is_a($message, 'rcube_message')) { | |
| 1862 $message = new rcube_message($message); | |
| 1863 } | |
| 1864 | |
| 1865 if ($message->headers->mdn_to && empty($message->headers->flags['MDNSENT']) && | |
| 1866 ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*')) | |
| 1867 ) { | |
| 1868 $identity = rcmail_identity_select($message); | |
| 1869 $sender = format_email_recipient($identity['email'], $identity['name']); | |
| 1870 $recipient = array_shift(rcube_mime::decode_address_list( | |
| 1871 $message->headers->mdn_to, 1, true, $message->headers->charset)); | |
| 1872 $mailto = $recipient['mailto']; | |
| 1873 | |
| 1874 $compose = new Mail_mime("\r\n"); | |
| 1875 | |
| 1876 $compose->setParam('text_encoding', 'quoted-printable'); | |
| 1877 $compose->setParam('html_encoding', 'quoted-printable'); | |
| 1878 $compose->setParam('head_encoding', 'quoted-printable'); | |
| 1879 $compose->setParam('head_charset', RCUBE_CHARSET); | |
| 1880 $compose->setParam('html_charset', RCUBE_CHARSET); | |
| 1881 $compose->setParam('text_charset', RCUBE_CHARSET); | |
| 1882 | |
| 1883 // compose headers array | |
| 1884 $headers = array( | |
| 1885 'Date' => $RCMAIL->user_date(), | |
| 1886 'From' => $sender, | |
| 1887 'To' => $message->headers->mdn_to, | |
| 1888 'Subject' => $RCMAIL->gettext('receiptread') . ': ' . $message->subject, | |
| 1889 'Message-ID' => $RCMAIL->gen_message_id($identity['email']), | |
| 1890 'X-Sender' => $identity['email'], | |
| 1891 'References' => trim($message->headers->references . ' ' . $message->headers->messageID), | |
| 1892 'In-Reply-To' => $message->headers->messageID, | |
| 1893 ); | |
| 1894 | |
| 1895 $report = "Final-Recipient: rfc822; {$identity['email']}\r\n" | |
| 1896 . "Original-Message-ID: {$message->headers->messageID}\r\n" | |
| 1897 . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; | |
| 1898 | |
| 1899 if ($message->headers->to) { | |
| 1900 $report .= "Original-Recipient: {$message->headers->to}\r\n"; | |
| 1901 } | |
| 1902 | |
| 1903 if ($agent = $RCMAIL->config->get('useragent')) { | |
| 1904 $headers['User-Agent'] = $agent; | |
| 1905 $report .= "Reporting-UA: $agent\r\n"; | |
| 1906 } | |
| 1907 | |
| 1908 $to = rcube_mime::decode_mime_string($message->headers->to, $message->headers->charset); | |
| 1909 $date = $RCMAIL->format_date($message->headers->date, $RCMAIL->config->get('date_long')); | |
| 1910 $body = $RCMAIL->gettext("yourmessage") . "\r\n\r\n" . | |
| 1911 "\t" . $RCMAIL->gettext("to") . ": {$to}\r\n" . | |
| 1912 "\t" . $RCMAIL->gettext("subject") . ": {$message->subject}\r\n" . | |
| 1913 "\t" . $RCMAIL->gettext("date") . ": {$date}\r\n" . | |
| 1914 "\r\n" . $RCMAIL->gettext("receiptnote"); | |
| 1915 | |
| 1916 $compose->headers(array_filter($headers)); | |
| 1917 $compose->setContentType('multipart/report', array('report-type'=> 'disposition-notification')); | |
| 1918 $compose->setTXTBody(rcube_mime::wordwrap($body, 75, "\r\n")); | |
| 1919 $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline'); | |
| 1920 | |
| 1921 // SMTP options | |
| 1922 $options = array('mdn_use_from' => (bool) $RCMAIL->config->get('mdn_use_from')); | |
| 1923 | |
| 1924 $sent = $RCMAIL->deliver_message($compose, $identity['email'], $mailto, $smtp_error, $body_file, $options, true); | |
| 1925 | |
| 1926 if ($sent) { | |
| 1927 $RCMAIL->storage->set_flag($message->uid, 'MDNSENT'); | |
| 1928 return true; | |
| 1929 } | |
| 1930 } | |
| 1931 | |
| 1932 return false; | |
| 1933 } | |
| 1934 | |
| 1935 /** | |
| 1936 * Detect recipient identity from specified message | |
| 1937 */ | |
| 1938 function rcmail_identity_select($MESSAGE, $identities = null, $compose_mode = 'reply') | |
| 1939 { | |
| 1940 $a_recipients = array(); | |
| 1941 $a_names = array(); | |
| 1942 | |
| 1943 if ($identities === null) { | |
| 1944 $identities = rcmail::get_instance()->user->list_identities(null, true); | |
| 1945 } | |
| 1946 | |
| 1947 // extract all recipients of the reply-message | |
| 1948 if (is_object($MESSAGE->headers) && in_array($compose_mode, array('reply', 'forward'))) { | |
| 1949 $a_to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, true, $MESSAGE->headers->charset); | |
| 1950 foreach ($a_to as $addr) { | |
| 1951 if (!empty($addr['mailto'])) { | |
| 1952 $a_recipients[] = strtolower($addr['mailto']); | |
| 1953 $a_names[] = $addr['name']; | |
| 1954 } | |
| 1955 } | |
| 1956 | |
| 1957 if (!empty($MESSAGE->headers->cc)) { | |
| 1958 $a_cc = rcube_mime::decode_address_list($MESSAGE->headers->cc, null, true, $MESSAGE->headers->charset); | |
| 1959 foreach ($a_cc as $addr) { | |
| 1960 if (!empty($addr['mailto'])) { | |
| 1961 $a_recipients[] = strtolower($addr['mailto']); | |
| 1962 $a_names[] = $addr['name']; | |
| 1963 } | |
| 1964 } | |
| 1965 } | |
| 1966 } | |
| 1967 | |
| 1968 // decode From: address | |
| 1969 $from = rcube_mime::decode_address_list($MESSAGE->headers->from, null, true, $MESSAGE->headers->charset); | |
| 1970 $from = array_shift($from); | |
| 1971 $from['mailto'] = strtolower($from['mailto']); | |
| 1972 | |
| 1973 $from_idx = null; | |
| 1974 $found_idx = array('to' => null, 'from' => null); | |
| 1975 $check_from = in_array($compose_mode, array('draft', 'edit', 'reply')); | |
| 1976 | |
| 1977 // Select identity | |
| 1978 foreach ($identities as $idx => $ident) { | |
| 1979 // use From: header when in edit/draft or reply-to-self | |
| 1980 if ($check_from && $from['mailto'] == strtolower($ident['email_ascii'])) { | |
| 1981 // remember first matching identity address | |
| 1982 if ($found_idx['from'] === null) { | |
| 1983 $found_idx['from'] = $idx; | |
| 1984 } | |
| 1985 // match identity name | |
| 1986 if ($from['name'] && $ident['name'] && $from['name'] == $ident['name']) { | |
| 1987 $from_idx = $idx; | |
| 1988 break; | |
| 1989 } | |
| 1990 } | |
| 1991 // use replied/forwarded message recipients | |
| 1992 else if (($found = array_search(strtolower($ident['email_ascii']), $a_recipients)) !== false) { | |
| 1993 // remember first matching identity address | |
| 1994 if ($found_idx['to'] === null) { | |
| 1995 $found_idx['to'] = $idx; | |
| 1996 } | |
| 1997 // match identity name | |
| 1998 if ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name']) { | |
| 1999 $from_idx = $idx; | |
| 2000 break; | |
| 2001 } | |
| 2002 } | |
| 2003 } | |
| 2004 | |
| 2005 // If matching by name+address didn't find any matches, | |
| 2006 // get first found identity (address) if any | |
| 2007 if ($from_idx === null) { | |
| 2008 $from_idx = $found_idx['from'] !== null ? $found_idx['from'] : $found_idx['to']; | |
| 2009 } | |
| 2010 | |
| 2011 // Try Return-Path | |
| 2012 if ($from_idx === null && ($return_path = $MESSAGE->headers->others['return-path'])) { | |
| 2013 $return_path = array_map('strtolower', (array) $return_path); | |
| 2014 | |
| 2015 foreach ($identities as $idx => $ident) { | |
| 2016 // Return-Path header contains an email address, but on some mailing list | |
| 2017 // it can be e.g. <pear-dev-return-55250-local=domain.tld@lists.php.net> | |
| 2018 // where local@domain.tld is the address we're looking for (#1489241) | |
| 2019 $ident1 = strtolower($ident['email_ascii']); | |
| 2020 $ident2 = str_replace('@', '=', $ident1); | |
| 2021 $ident1 = '<' . $ident1 . '>'; | |
| 2022 $ident2 = '-' . $ident2 . '@'; | |
| 2023 | |
| 2024 foreach ($return_path as $path) { | |
| 2025 if ($path == $ident1 || stripos($path, $ident2)) { | |
| 2026 $from_idx = $idx; | |
| 2027 break 2; | |
| 2028 } | |
| 2029 } | |
| 2030 } | |
| 2031 } | |
| 2032 | |
| 2033 // See identity_select plugin for example usage of this hook | |
| 2034 $plugin = rcmail::get_instance()->plugins->exec_hook('identity_select', | |
| 2035 array('message' => $MESSAGE, 'identities' => $identities, 'selected' => $from_idx)); | |
| 2036 | |
| 2037 $selected = $plugin['selected']; | |
| 2038 | |
| 2039 // default identity is always first on the list | |
| 2040 return $identities[$selected !== null ? $selected : 0]; | |
| 2041 } | |
| 2042 | |
| 2043 // Fixes some content-type names | |
| 2044 function rcmail_fix_mimetype($name) | |
| 2045 { | |
| 2046 $map = array( | |
| 2047 'image/x-ms-bmp' => 'image/bmp', // #1490282 | |
| 2048 ); | |
| 2049 | |
| 2050 $name = strtolower($name); | |
| 2051 | |
| 2052 if ($alias = $map[$name]) { | |
| 2053 $name = $alias; | |
| 2054 } | |
| 2055 // Some versions of Outlook create garbage Content-Type: | |
| 2056 // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608 | |
| 2057 else if (preg_match('/^application\/pdf.+/', $name)) { | |
| 2058 $name = 'application/pdf'; | |
| 2059 } | |
| 2060 // treat image/pjpeg (image/pjpg, image/jpg) as image/jpeg (#1489097) | |
| 2061 else if (preg_match('/^image\/p?jpe?g$/', $name)) { | |
| 2062 $name = 'image/jpeg'; | |
| 2063 } | |
| 2064 | |
| 2065 return $name; | |
| 2066 } | |
| 2067 | |
| 2068 // return attachment filename, handle empty filename case | |
| 2069 function rcmail_attachment_name($attachment, $display = false) | |
| 2070 { | |
| 2071 global $RCMAIL; | |
| 2072 | |
| 2073 $filename = (string) $attachment->filename; | |
| 2074 $filename = preg_replace('/[\x00-\x1F\x7F]/', '', $filename); | |
| 2075 | |
| 2076 if ($filename === '') { | |
| 2077 if ($attachment->mimetype == 'text/html') { | |
| 2078 $filename = $RCMAIL->gettext('htmlmessage'); | |
| 2079 } | |
| 2080 else { | |
| 2081 $ext = (array) rcube_mime::get_mime_extensions($attachment->mimetype); | |
| 2082 $ext = array_shift($ext); | |
| 2083 $filename = $RCMAIL->gettext('messagepart') . ' ' . $attachment->mime_id; | |
| 2084 if ($ext) { | |
| 2085 $filename .= '.' . $ext; | |
| 2086 } | |
| 2087 } | |
| 2088 } | |
| 2089 | |
| 2090 // Display smart names for some known mimetypes | |
| 2091 if ($display) { | |
| 2092 if (preg_match('/application\/(pgp|pkcs7)-signature/i', $attachment->mimetype)) { | |
| 2093 $filename = $RCMAIL->gettext('digitalsig'); | |
| 2094 } | |
| 2095 } | |
| 2096 | |
| 2097 return $filename; | |
| 2098 } | |
| 2099 | |
| 2100 function rcmail_search_filter($attrib) | |
| 2101 { | |
| 2102 global $RCMAIL; | |
| 2103 | |
| 2104 if (!strlen($attrib['id'])) { | |
| 2105 $attrib['id'] = 'rcmlistfilter'; | |
| 2106 } | |
| 2107 | |
| 2108 $attrib['onchange'] = rcmail_output::JS_OBJECT_NAME.'.filter_mailbox(this.value)'; | |
| 2109 | |
| 2110 // Content-Type values of messages with attachments | |
| 2111 // the same as in app.js:add_message_row() | |
| 2112 $ctypes = array('application/', 'multipart/m', 'multipart/signed', 'multipart/report'); | |
| 2113 | |
| 2114 // Build search string of "with attachment" filter | |
| 2115 $attachment = trim(str_repeat(' OR', count($ctypes)-1)); | |
| 2116 foreach ($ctypes as $type) { | |
| 2117 $attachment .= ' HEADER Content-Type ' . rcube_imap_generic::escape($type); | |
| 2118 } | |
| 2119 | |
| 2120 $select = new html_select($attrib); | |
| 2121 $select->add($RCMAIL->gettext('all'), 'ALL'); | |
| 2122 $select->add($RCMAIL->gettext('unread'), 'UNSEEN'); | |
| 2123 $select->add($RCMAIL->gettext('flagged'), 'FLAGGED'); | |
| 2124 $select->add($RCMAIL->gettext('unanswered'), 'UNANSWERED'); | |
| 2125 if (!$RCMAIL->config->get('skip_deleted')) { | |
| 2126 $select->add($RCMAIL->gettext('deleted'), 'DELETED'); | |
| 2127 $select->add($RCMAIL->gettext('undeleted'), 'UNDELETED'); | |
| 2128 } | |
| 2129 $select->add($RCMAIL->gettext('withattachment'), $attachment); | |
| 2130 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('highest'), 'HEADER X-PRIORITY 1'); | |
| 2131 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('high'), 'HEADER X-PRIORITY 2'); | |
| 2132 $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'); | |
| 2133 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('low'), 'HEADER X-PRIORITY 4'); | |
| 2134 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('lowest'), 'HEADER X-PRIORITY 5'); | |
| 2135 | |
| 2136 $RCMAIL->output->add_gui_object('search_filter', $attrib['id']); | |
| 2137 | |
| 19 | 2138 return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_filter'] : 'ALL'); |
| 0 | 2139 } |
| 2140 | |
| 2141 function rcmail_search_interval($attrib) | |
| 2142 { | |
| 2143 global $RCMAIL; | |
| 2144 | |
| 2145 if (!strlen($attrib['id'])) { | |
| 2146 $attrib['id'] = 'rcmsearchinterval'; | |
| 2147 } | |
| 2148 | |
| 2149 $select = new html_select($attrib); | |
| 2150 $select->add('', ''); | |
| 2151 | |
| 2152 foreach (array('1W', '1M', '1Y', '-1W', '-1M', '-1Y') as $value) { | |
| 2153 $select->add($RCMAIL->gettext('searchinterval' . $value), $value); | |
| 2154 } | |
| 2155 | |
| 2156 $RCMAIL->output->add_gui_object('search_interval', $attrib['id']); | |
| 2157 | |
| 19 | 2158 return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_interval'] : ''); |
| 0 | 2159 } |
| 2160 | |
| 2161 function rcmail_message_error() | |
| 2162 { | |
| 2163 global $RCMAIL; | |
| 2164 | |
| 2165 // Set env variables for messageerror.html template | |
| 2166 if ($RCMAIL->action == 'show') { | |
| 2167 $mbox_name = $RCMAIL->storage->get_folder(); | |
| 2168 | |
| 2169 $RCMAIL->output->set_env('mailbox', $mbox_name); | |
| 2170 $RCMAIL->output->set_env('uid', null); | |
| 2171 } | |
| 2172 | |
| 2173 // display error message | |
| 2174 $RCMAIL->output->show_message('messageopenerror', 'error'); | |
| 2175 // ... display message error page | |
| 2176 $RCMAIL->output->send('messageerror'); | |
| 2177 } | |
| 2178 | |
| 2179 function rcmail_message_import_form($attrib = array()) | |
| 2180 { | |
| 2181 global $RCMAIL; | |
| 2182 | |
| 2183 $RCMAIL->output->add_label('selectimportfile','importwait'); | |
| 2184 | |
| 2185 $input_attr = array( | |
| 2186 'multiple' => true, | |
| 2187 'name' => '_file[]', | |
| 2188 'accept' => ".eml, .mbox, message/rfc822, text/*", | |
| 2189 ); | |
| 2190 | |
| 2191 $attrib['prefix'] = html::tag('input', array('type' => 'hidden', 'name' => '_unlock', 'value' => '')) | |
| 2192 . html::tag('input', array('type' => 'hidden', 'name' => '_framed', 'value' => '1')); | |
| 2193 | |
| 2194 return $RCMAIL->upload_form($attrib, 'importform', 'import-messages', $input_attr); | |
| 2195 } | |
| 2196 | |
| 2197 /** | |
| 2198 * Add groups from the given address source to the address book widget | |
| 2199 */ | |
| 2200 function rcmail_compose_contact_groups($abook, $source_id, $search = null, $search_mode = 0) | |
| 2201 { | |
| 2202 global $RCMAIL, $OUTPUT; | |
| 2203 | |
| 2204 $jsresult = array(); | |
| 2205 foreach ($abook->list_groups($search, $search_mode) as $group) { | |
| 2206 $abook->reset(); | |
| 2207 $abook->set_group($group['ID']); | |
| 2208 | |
| 2209 // group (distribution list) with email address(es) | |
| 2210 if ($group['email']) { | |
| 2211 foreach ((array)$group['email'] as $email) { | |
| 2212 $row_id = 'G'.$group['ID']; | |
| 2213 $jsresult[$row_id] = format_email_recipient($email, $group['name']); | |
| 2214 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2215 'contactgroup' => html::span(array('title' => $email), rcube::Q($group['name']))), 'group'); | |
| 2216 } | |
| 2217 } | |
| 2218 // make virtual groups clickable to list their members | |
| 2219 else if ($group['virtual']) { | |
| 2220 $row_id = 'G'.$group['ID']; | |
| 2221 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2222 'contactgroup' => html::a(array( | |
| 2223 'href' => '#list', | |
| 2224 'rel' => $group['ID'], | |
| 2225 'title' => $RCMAIL->gettext('listgroup'), | |
| 2226 'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this,event)", | |
| 2227 rcmail_output::JS_OBJECT_NAME, $source_id, $group['ID']), | |
| 2228 ), rcube::Q($group['name']) . ' ' . html::span('action', '»'))), | |
| 2229 'group', | |
| 2230 array('ID' => $group['ID'], 'name' => $group['name'], 'virtual' => true)); | |
| 2231 } | |
| 2232 // show group with count | |
| 2233 else if (($result = $abook->count()) && $result->count) { | |
| 2234 $row_id = 'E'.$group['ID']; | |
| 2235 $jsresult[$row_id] = $group['name']; | |
| 2236 $OUTPUT->command('add_contact_row', $row_id, array( | |
| 2237 'contactgroup' => rcube::Q($group['name'] . ' (' . intval($result->count) . ')')), 'group'); | |
| 2238 } | |
| 2239 } | |
| 2240 | |
| 2241 $abook->reset(); | |
| 2242 $abook->set_group(0); | |
| 2243 | |
| 2244 return $jsresult; | |
| 2245 } | |
| 2246 | |
| 2247 function rcmail_save_attachment($message, $pid, $compose_id, $params = array()) | |
| 2248 { | |
| 2249 global $COMPOSE; | |
| 2250 | |
| 2251 $rcmail = rcmail::get_instance(); | |
| 2252 $storage = $rcmail->get_storage(); | |
| 2253 | |
| 2254 if ($pid) { | |
| 2255 // attachment requested | |
| 2256 $part = $message->mime_parts[$pid]; | |
| 2257 $size = $part->size; | |
| 2258 $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; | |
| 2259 $filename = $params['filename'] ?: rcmail_attachment_name($part); | |
| 2260 } | |
| 2261 else if (is_object($message)) { | |
| 2262 // the whole message requested | |
| 2263 $size = $message->size; | |
| 2264 $mimetype = 'message/rfc822'; | |
| 2265 $filename = $params['filename'] ?: 'message_rfc822.eml'; | |
| 2266 } | |
| 2267 else if (is_string($message)) { | |
| 2268 // the whole message requested | |
| 2269 $size = strlen($message); | |
| 2270 $data = $message; | |
| 2271 $mimetype = $params['mimetype']; | |
| 2272 $filename = $params['filename']; | |
| 2273 } | |
| 2274 | |
| 2275 if (!isset($data)) { | |
| 2276 // don't load too big attachments into memory | |
| 2277 if (!rcube_utils::mem_check($size)) { | |
| 2278 $temp_dir = unslashify($rcmail->config->get('temp_dir')); | |
| 2279 $path = tempnam($temp_dir, 'rcmAttmnt'); | |
| 2280 | |
| 2281 if ($fp = fopen($path, 'w')) { | |
| 2282 if ($pid) { | |
| 2283 // part body | |
| 2284 $message->get_part_body($pid, false, 0, $fp); | |
| 2285 } | |
| 2286 else { | |
| 2287 // complete message | |
| 2288 $storage->get_raw_body($message->uid, $fp); | |
| 2289 } | |
| 2290 | |
| 2291 fclose($fp); | |
| 2292 } | |
| 2293 else { | |
| 2294 return false; | |
| 2295 } | |
| 2296 } | |
| 2297 else if ($pid) { | |
| 2298 // part body | |
| 2299 $data = $message->get_part_body($pid); | |
| 2300 } | |
| 2301 else { | |
| 2302 // complete message | |
| 2303 $data = $storage->get_raw_body($message->uid); | |
| 2304 } | |
| 2305 } | |
| 2306 | |
| 2307 $attachment = array( | |
| 2308 'group' => $compose_id, | |
| 2309 'name' => $filename, | |
| 2310 'mimetype' => $mimetype, | |
| 2311 'content_id' => $part ? $part->content_id : null, | |
| 2312 'data' => $data, | |
| 2313 'path' => $path, | |
| 2314 'size' => $path ? filesize($path) : strlen($data), | |
| 2315 'charset' => $part ? $part->charset : $params['charset'], | |
| 2316 ); | |
| 2317 | |
| 2318 $attachment = $rcmail->plugins->exec_hook('attachment_save', $attachment); | |
| 2319 | |
| 2320 if ($attachment['status']) { | |
| 2321 unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); | |
| 2322 | |
| 2323 // rcube_session::append() replaces current session data with the old values | |
| 2324 // (in rcube_session::reload()). This is a problem in 'compose' action, because before | |
| 2325 // the first append() use we set some important data in the session. | |
| 2326 // It also overwrites attachments list. Fixing reload() is not so simple if possible | |
| 2327 // as we don't really know what has been added and what removed in meantime. | |
| 2328 // So, for now we'll do not use append() on 'compose' action (#1490608). | |
| 2329 | |
| 2330 if ($rcmail->action == 'compose') { | |
| 2331 $COMPOSE['attachments'][$attachment['id']] = $attachment; | |
| 2332 } | |
| 2333 else { | |
| 2334 $rcmail->session->append('compose_data_' . $compose_id . '.attachments', $attachment['id'], $attachment); | |
| 2335 } | |
| 2336 | |
| 2337 return $attachment; | |
| 2338 } | |
| 2339 else if ($path) { | |
| 2340 @unlink($path); | |
| 2341 } | |
| 2342 | |
| 2343 return false; | |
| 2344 } | |
| 2345 | |
| 2346 // Return mimetypes supported by the browser | |
| 2347 function rcmail_supported_mimetypes() | |
| 2348 { | |
| 2349 $rcmail = rcube::get_instance(); | |
| 2350 | |
| 2351 // mimetypes supported by the browser (default settings) | |
| 2352 $mimetypes = (array) $rcmail->config->get('client_mimetypes'); | |
| 2353 | |
| 2354 // Remove unsupported types, which makes that attachment which cannot be | |
| 2355 // displayed in a browser will be downloaded directly without displaying an overlay page | |
| 2356 if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) { | |
| 2357 unset($mimetypes[$key]); | |
| 2358 } | |
| 2359 | |
| 2360 if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) { | |
| 2361 unset($mimetypes[$key]); | |
| 2362 } | |
| 2363 | |
| 2364 foreach (array('tiff', 'webp') as $type) { | |
| 2365 if (empty($_SESSION['browser_caps'][$type]) && ($key = array_search('image/' . $type, $mimetypes)) !== false) { | |
| 2366 // can we convert it to jpeg? | |
| 2367 if (!rcube_image::is_convertable('image/' . $type)) { | |
| 2368 unset($mimetypes[$key]); | |
| 2369 } | |
| 2370 } | |
| 2371 } | |
| 2372 | |
| 2373 // @TODO: support mail preview for compose attachments | |
| 2374 if ($rcmail->action != 'compose' && !in_array('message/rfc822', $mimetypes)) { | |
| 2375 $mimetypes[] = 'message/rfc822'; | |
| 2376 } | |
| 2377 | |
| 2378 return array_values($mimetypes); | |
| 2379 } |
