thomascube
2011-08-18 fbe54043cf598b19a753dc2b21a7ed558d23fd15
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/func.inc                                           |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2005-2010, The Roundcube Dev Team                       |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Provide webmail functionality and GUI objects                       |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
7910c0 22 // setup some global vars used by mail steps
T 23 $SENT_MBOX = $RCMAIL->config->get('sent_mbox');
24 $DRAFTS_MBOX = $RCMAIL->config->get('drafts_mbox');
5c1dfb 25 $SEARCH_MODS_DEFAULT = array(
A 26     '*'         => array('subject'=>1, 'from'=>1),
27     $SENT_MBOX  => array('subject'=>1, 'to'=>1),
28     $DRAFTS_MBOX => array('subject'=>1, 'to'=>1)
29 );
39cd51 30
431234 31 // actions that do not require imap connection here
A 32 $NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get');
39cd51 33
47d8d3 34 // always instantiate imap object (but not yet connect to server)
T 35 $RCMAIL->imap_init();
36
39cd51 37 // log in to imap server
A 38 if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) {
39   $RCMAIL->kill_session();
40
41   if ($OUTPUT->ajax_call)
42     $OUTPUT->redirect(array(), 2000);
43
44   $OUTPUT->set_env('task', 'login');
45   $OUTPUT->send('login');
46 }
47
4e17e6 48 // set imap properties and session vars
b72e2f 49 if (strlen(trim($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC, true))))
c57996 50   $IMAP->set_mailbox(($_SESSION['mbox'] = $mbox));
48bc52 51 else if ($IMAP)
4e5b11 52   $_SESSION['mbox'] = $IMAP->get_mailbox_name();
4e17e6 53
b3ce79 54 if (!empty($_GET['_page']))
c57996 55   $IMAP->set_page(($_SESSION['page'] = intval($_GET['_page'])));
4e17e6 56
6a35c8 57 // set default sort col/order to session
T 58 if (!isset($_SESSION['sort_col']))
2c052c 59   $_SESSION['sort_col'] = !empty($CONFIG['message_sort_col']) ? $CONFIG['message_sort_col'] : '';
6a35c8 60 if (!isset($_SESSION['sort_order']))
ae3d60 61   $_SESSION['sort_order'] = strtoupper($CONFIG['message_sort_order']) == 'ASC' ? 'ASC' : 'DESC';
2bca6e 62
f52c93 63 // set threads mode
T 64 $a_threading = $RCMAIL->config->get('message_threading', array());
65 if (isset($_GET['_threads'])) {
66   if ($_GET['_threads'])
67     $a_threading[$_SESSION['mbox']] = true;
68   else
69     unset($a_threading[$_SESSION['mbox']]);
70   $RCMAIL->user->save_prefs(array('message_threading' => $a_threading));
71 }
72 $IMAP->set_threading($a_threading[$_SESSION['mbox']]);
73
2bca6e 74 // set message set for search result
f6aac3 75 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
A 76     && $_SESSION['search_request'] == $_REQUEST['_search']
77 ) {
78   $IMAP->set_search_set($_SESSION['search']);
1f020b 79   $OUTPUT->set_env('search_request', $_REQUEST['_search']);
S 80   $OUTPUT->set_env('search_text', $_SESSION['last_text_search']);
f6aac3 81 }
4e17e6 82
528514 83 // set main env variables, labels and page title
f6aac3 84 if (empty($RCMAIL->action) || $RCMAIL->action == 'list') {
8abda5 85   $mbox_name = $IMAP->get_mailbox_name();
A 86
f6aac3 87   if (empty($RCMAIL->action)) {
8abda5 88     // initialize searching result if search_filter is used
f6aac3 89     if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL') {
8abda5 90       $search_request = md5($mbox_name.$_SESSION['search_filter']);
9800a8 91
8abda5 92       $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']);
f6aac3 93       $_SESSION['search'] = $IMAP->get_search_set();
A 94       $_SESSION['search_request'] = $search_request;
8abda5 95       $OUTPUT->set_env('search_request', $search_request);
A 96       }
9800a8 97
7910c0 98       $search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT);
T 99       $OUTPUT->set_env('search_mods', $search_mods);
f6aac3 100   }
9800a8 101
f52c93 102   // set current mailbox and some other vars in client environment
8abda5 103   $OUTPUT->set_env('mailbox', $mbox_name);
f52c93 104   $OUTPUT->set_env('pagesize', $IMAP->page_size);
600bb1 105   $OUTPUT->set_env('quota', $IMAP->get_capability('QUOTA'));
528514 106   $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
f52c93 107   $OUTPUT->set_env('threading', (bool) $IMAP->threading);
600bb1 108   $OUTPUT->set_env('threads', $IMAP->threading || $IMAP->get_capability('THREAD'));
a509bb 109   $OUTPUT->set_env('preview_pane_mark_read', $RCMAIL->config->get('preview_pane_mark_read', 0));
528514 110
0b2ce9 111   if ($CONFIG['flag_for_deletion'])
A 112     $OUTPUT->set_env('flag_for_deletion', true);
113   if ($CONFIG['read_when_deleted'])
114     $OUTPUT->set_env('read_when_deleted', true);
115   if ($CONFIG['skip_deleted'])
116     $OUTPUT->set_env('skip_deleted', true);
e54bb7 117   if ($CONFIG['display_next'])
A 118     $OUTPUT->set_env('display_next', true);
a509bb 119   if ($CONFIG['forward_attachment'])
A 120     $OUTPUT->set_env('forward_attachment', true);
528514 121   if ($CONFIG['trash_mbox'])
A 122     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
123   if ($CONFIG['drafts_mbox'])
124     $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
125   if ($CONFIG['junk_mbox'])
126     $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']);
127
128   if (!$OUTPUT->ajax_call)
9b3fdc 129     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
c50d88 130       'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage',
A 131       'copy', 'move', 'quota');
528514 132
d08333 133   $OUTPUT->set_pagetitle(rcmail_localize_foldername($IMAP->mod_mailbox($mbox_name)));
f6aac3 134 }
5eee00 135
4e17e6 136
45f56c 137 /**
T 138  * return the message list as HTML table
139  */
4e17e6 140 function rcmail_message_list($attrib)
f52c93 141 {
T 142   global $IMAP, $CONFIG, $OUTPUT;
b076a4 143
24053e 144   // add some labels to client
112c91 145   $OUTPUT->add_label('from', 'to');
4e17e6 146
T 147   // add id to message list table if not specified
148   if (!strlen($attrib['id']))
149     $attrib['id'] = 'rcubemessagelist';
e0ddd4 150
d59aaa 151   // define list of cols to be displayed based on parameter or config
b62c48 152   if (empty($attrib['columns'])) {
A 153     $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
154     $OUTPUT->set_env('col_movable', !in_array('list_cols', (array)$CONFIG['dont_override']));
155   }
156   else {
157     $a_show_cols = preg_split('/[\s,;]+/', strip_quotes($attrib['columns']));
158     $attrib['columns'] = $a_show_cols;
159   }
d59aaa 160
f52c93 161   // save some variables for use in ajax list
T 162   $_SESSION['list_attrib'] = $attrib;
9800a8 163
41bece 164   $mbox = $IMAP->get_mailbox_name();
4906eb 165   $delim = $IMAP->get_hierarchy_delimiter();
A 166
167   // show 'to' instead of 'from' in sent/draft messages
168   if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0)
ffaea6 169       && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
4e17e6 170     $a_show_cols[$f] = 'to';
e0ddd4 171
614c64 172   // make sure 'threads' and 'subject' columns are present
A 173   if (!in_array('subject', $a_show_cols))
174     array_unshift($a_show_cols, 'subject');
6c9d49 175   if (!in_array('threads', $a_show_cols))
A 176     array_unshift($a_show_cols, 'threads');
177
f52c93 178   $skin_path = $_SESSION['skin_path'] = $CONFIG['skin_path'];
9800a8 179
4e17e6 180   // set client env
f11541 181   $OUTPUT->add_gui_object('messagelist', $attrib['id']);
f52c93 182   $OUTPUT->set_env('autoexpand_threads', intval($CONFIG['autoexpand_threads']));
T 183   $OUTPUT->set_env('sort_col', $_SESSION['sort_col']);
184   $OUTPUT->set_env('sort_order', $_SESSION['sort_order']);
185   $OUTPUT->set_env('messages', array());
d24d20 186   $OUTPUT->set_env('coltypes', $a_show_cols);
9800a8 187
6b47de 188   $OUTPUT->include_script('list.js');
9800a8 189
f52c93 190   $thead = '';
T 191   foreach (rcmail_message_list_head($attrib, $a_show_cols) as $cell)
192     $thead .= html::tag('td', array('class' => $cell['className'], 'id' => $cell['id']), $cell['html']);
9800a8 193
f52c93 194   return html::tag('table',
T 195     $attrib,
196     html::tag('thead', null, html::tag('tr', null, $thead)) .
197       html::tag('tbody', null, ''),
b62c48 198         array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
f52c93 199 }
4e17e6 200
T 201
45f56c 202 /**
T 203  * return javascript commands to add rows to the message list
204  */
614c64 205 function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null)
f52c93 206 {
5bde17 207   global $CONFIG, $IMAP, $RCMAIL, $OUTPUT;
4e17e6 208
614c64 209   if (empty($a_show_cols)) {
A 210     if (!empty($_SESSION['list_attrib']['columns']))
211       $a_show_cols = $_SESSION['list_attrib']['columns'];
212     else
213       $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
214   }
215   else {
216     if (!is_array($a_show_cols))
217       $a_show_cols = preg_split('/[\s,;]+/', strip_quotes($a_show_cols));
218     $head_replace = true;
219   }
d59aaa 220
41bece 221   $mbox = $IMAP->get_mailbox_name();
4906eb 222   $delim = $IMAP->get_hierarchy_delimiter();
614c64 223
A 224   // make sure 'threads' and 'subject' columns are present
225   if (!in_array('subject', $a_show_cols))
226     array_unshift($a_show_cols, 'subject');
227   if (!in_array('threads', $a_show_cols))
228     array_unshift($a_show_cols, 'threads');
229
230   $_SESSION['list_attrib']['columns'] = $a_show_cols;
9800a8 231
4906eb 232   // show 'to' instead of 'from' in sent/draft messages
A 233   if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0)
f11541 234       && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
4e17e6 235     $a_show_cols[$f] = 'to';
T 236
614c64 237   // Make sure there are no duplicated columns (#1486999)
A 238   $a_show_cols = array_unique($a_show_cols);
6c9d49 239
5bde17 240   // Plugins may set header's list_cols/list_flags and other rcube_mail_header variables
A 241   // and list columns
242   $plugin = $RCMAIL->plugins->exec_hook('messages_list',
243     array('messages' => $a_headers, 'cols' => $a_show_cols));
244
245   $a_show_cols = $plugin['cols'];
246   $a_headers   = $plugin['messages'];
247
f52c93 248   $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
9800a8 249
f52c93 250   $OUTPUT->command('set_message_coltypes', $a_show_cols, $thead);
c4b819 251
f52c93 252   if (empty($a_headers))
T 253     return;
91354e 254
4438d6 255   // remove 'threads', 'attachment', 'flag', 'status' columns, we don't need them here
A 256   foreach (array('threads', 'attachment', 'flag', 'status') as $col) {
257     if (($key = array_search($col, $a_show_cols)) !== FALSE)
258       unset($a_show_cols[$key]);
259   }
5bde17 260
4438d6 261   // loop through message headers
A 262   foreach ($a_headers as $n => $header) {
ecd2e7 263     if (empty($header))
T 264       continue;
5bde17 265
A 266     $a_msg_cols = array();
267     $a_msg_flags = array();
f11541 268
5faac0 269     $IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']);
d59aaa 270
4e17e6 271     // format each col; similar as in rcmail_message_list()
4438d6 272     foreach ($a_show_cols as $col) {
5cef5b 273       if (in_array($col, array('from', 'to', 'cc', 'replyto')))
583850 274         $cont = Q(rcmail_address_string($header->$col, 3), 'show');
4438d6 275       else if ($col=='subject') {
bc3745 276         $cont = trim($IMAP->decode_header($header->$col));
44385f 277         if (!$cont) $cont = rcube_label('nosubject');
f52c93 278         $cont = Q($cont);
4438d6 279       }
4e17e6 280       else if ($col=='size')
T 281         $cont = show_bytes($header->$col);
282       else if ($col=='date')
f11541 283         $cont = format_date($header->date);
4e17e6 284       else
2bca6e 285         $cont = Q($header->$col);
9800a8 286
4e17e6 287       $a_msg_cols[$col] = $cont;
4438d6 288     }
4e17e6 289
f52c93 290     if ($header->depth)
T 291       $a_msg_flags['depth'] = $header->depth;
0e7b66 292     else if ($header->has_children)
A 293       $roots[] = $header->uid;
f52c93 294     if ($header->parent_uid)
T 295       $a_msg_flags['parent_uid'] = $header->parent_uid;
296     if ($header->has_children)
297       $a_msg_flags['has_children'] = $header->has_children;
298     if ($header->unread_children)
299       $a_msg_flags['unread_children'] = $header->unread_children;
c4b819 300     if ($header->deleted)
A 301       $a_msg_flags['deleted'] = 1;
302     if (!$header->seen)
303       $a_msg_flags['unread'] = 1;
304     if ($header->answered)
305       $a_msg_flags['replied'] = 1;
306     if ($header->forwarded)
307       $a_msg_flags['forwarded'] = 1;
308     if ($header->flagged)
309       $a_msg_flags['flagged'] = 1;
e25a35 310     if ($header->others['list-post'])
A 311       $a_msg_flags['ml'] = 1;
6b4929 312
A 313     $a_msg_flags['ctype'] = Q($header->ctype);
f52c93 314     $a_msg_flags['mbox'] = $mbox;
T 315
5bde17 316     // merge with plugin result
A 317     if (!empty($header->list_flags) && is_array($header->list_flags))
318       $a_msg_flags = array_merge($a_msg_flags, $header->list_flags);
319     if (!empty($header->list_cols) && is_array($header->list_cols))
320       $a_msg_cols = array_merge($a_msg_cols, $header->list_cols);
321
f11541 322     $OUTPUT->command('add_message_row',
T 323       $header->uid,
324       $a_msg_cols,
325       $a_msg_flags,
326       $insert_top);
4438d6 327   }
0e7b66 328
4438d6 329   if ($IMAP->threading) {
A 330     $OUTPUT->command('init_threads', (array) $roots);
331   }
b62c48 332 }
f52c93 333
T 334
335 /*
336  * Creates <THEAD> for message list table
337  */
338 function rcmail_message_list_head($attrib, $a_show_cols)
339 {
340   global $CONFIG;
341
342   $skin_path = $_SESSION['skin_path'];
343   $image_tag = html::img(array('src' => "%s%s", 'alt' => "%s"));
344
345   // check to see if we have some settings for sorting
346   $sort_col   = $_SESSION['sort_col'];
347   $sort_order = $_SESSION['sort_order'];
348
349   // define sortable columns
350   $a_sort_cols = array('subject', 'date', 'from', 'to', 'size', 'cc');
9800a8 351
1716d5 352   if (!empty($attrib['optionsmenuicon'])) {
A 353     $onclick = 'return ' . JS_OBJECT_NAME . ".command('menu-open', 'messagelistmenu')";
354     if ($attrib['optionsmenuicon'] === true || $attrib['optionsmenuicon'] == 'true')
355       $list_menu = html::div(array('onclick' => $onclick, 'class' => 'listmenu',
356         'id' => 'listmenulink', 'title' => rcube_label('listoptions')));
357     else
358       $list_menu = html::a(array('href' => '#', 'onclick' => $onclick),
359         html::img(array('src' => $skin_path . $attrib['optionsmenuicon'],
360           'id' => 'listmenulink', 'title' => rcube_label('listoptions')))
361       );
362   }
f52c93 363   else
T 364     $list_menu = '';
365
6c9d49 366   $cells = array();
f52c93 367
T 368   foreach ($a_show_cols as $col) {
369     // get column name
370     switch ($col) {
371       case 'flag':
e94706 372         $col_name = '<span class="flagged">&nbsp;</span>';
f52c93 373         break;
T 374       case 'attachment':
4438d6 375       case 'status':
A 376         $col_name = '<span class="' . $col .'">&nbsp;</span>';
f52c93 377         break;
6c9d49 378       case 'threads':
A 379         $col_name = $list_menu;
380         break;
f52c93 381       default:
T 382         $col_name = Q(rcube_label($col));
383     }
384
385     // make sort links
386     if (in_array($col, $a_sort_cols))
387       $col_name = html::a(array('href'=>"./#sort", 'onclick' => 'return '.JS_OBJECT_NAME.".command('sort','".$col."',this)", 'title' => rcube_label('sortby')), $col_name);
388
389     $sort_class = $col == $sort_col ? " sorted$sort_order" : '';
e94706 390     $class_name = $col.$sort_class;
f52c93 391
T 392     // put it all together
393     $cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name);
394   }
395
396   return $cells;
397 }
4e17e6 398
T 399
45f56c 400 /**
T 401  * return an HTML iframe for loading mail content
402  */
b19097 403 function rcmail_messagecontent_frame($attrib)
T 404   {
ce06d3 405   global $OUTPUT, $RCMAIL;
9800a8 406
b19097 407   if (empty($attrib['id']))
T 408     $attrib['id'] = 'rcmailcontentwindow';
409
e2c610 410   $attrib['name'] = $attrib['id'];
b19097 411
ce06d3 412   if ($RCMAIL->config->get('preview_pane'))
A 413     $OUTPUT->set_env('contentframe', $attrib['id']);
f11541 414   $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
b19097 415
95fcc3 416   return html::iframe($attrib);
b19097 417   }
T 418
4e17e6 419
T 420 function rcmail_messagecount_display($attrib)
421   {
29b397 422   global $RCMAIL;
9800a8 423
4e17e6 424   if (!$attrib['id'])
T 425     $attrib['id'] = 'rcmcountdisplay';
426
29b397 427   $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']);
4e17e6 428
29b397 429   $content =  $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : rcube_label('loading');
A 430
431   return html::span($attrib, $content);
4e17e6 432   }
T 433
434
4647e1 435 function rcmail_get_messagecount_text($count=NULL, $page=NULL)
4e17e6 436   {
29b397 437   global $RCMAIL, $IMAP;
31b2ce 438
4647e1 439   if ($page===NULL)
T 440     $page = $IMAP->list_page;
9800a8 441
4647e1 442   $start_msg = ($page-1) * $IMAP->page_size + 1;
9800a8 443
A 444   if ($count!==NULL)
445     $max = $count;
446   else if ($RCMAIL->action)
447     $max = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
4e17e6 448
T 449   if ($max==0)
450     $out = rcube_label('mailboxempty');
451   else
f52c93 452     $out = rcube_label(array('name' => $IMAP->threading ? 'threadsfromto' : 'messagesfromto',
T 453             'vars' => array('from'  => $start_msg,
454             'to'    => min($max, $start_msg + $IMAP->page_size - 1),
455             'count' => $max)));
4e17e6 456
2bca6e 457   return Q($out);
4e17e6 458   }
T 459
cbeea3 460
ac5d15 461 function rcmail_mailbox_name_display($attrib)
T 462 {
cbeea3 463   global $RCMAIL;
ac5d15 464
cbeea3 465   if (!$attrib['id'])
A 466     $attrib['id'] = 'rcmmailboxname';
ac5d15 467
cbeea3 468   $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']);
ac5d15 469
cbeea3 470   return html::span($attrib, rcmail_get_mailbox_name_text());
ac5d15 471 }
T 472
f96ffd 473
ac5d15 474 function rcmail_get_mailbox_name_text()
T 475 {
cbeea3 476   global $RCMAIL;
A 477   return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name());
ac5d15 478 }
T 479
cbeea3 480
2144f9 481 function rcmail_send_unread_count($mbox_name, $force=false, $count=null)
cbeea3 482 {
A 483   global $RCMAIL;
9800a8 484
b46edc 485   $old_unseen = rcmail_get_unseen_count($mbox_name);
2144f9 486
A 487   if ($count === null)
488     $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force);
489   else
490     $unseen = $count;
cbeea3 491
7d1db8 492   if ($unseen != $old_unseen || ($mbox_name == 'INBOX'))
cbeea3 493     $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, ($mbox_name == 'INBOX'));
A 494
b46edc 495   rcmail_set_unseen_count($mbox_name, $unseen);
9800a8 496
cbeea3 497   return $unseen;
A 498 }
f96ffd 499
cbeea3 500
b46edc 501 function rcmail_set_unseen_count($mbox_name, $count)
A 502 {
503   // @TODO: this data is doubled (session and cache tables) if caching is enabled
504
505   // Make sure we have an array here (#1487066)
506   if (!is_array($_SESSION['unseen_count']))
507     $_SESSION['unseen_count'] = array();
508
509   $_SESSION['unseen_count'][$mbox_name] = $count;
510 }
511
512
513 function rcmail_get_unseen_count($mbox_name)
514 {
515   if (is_array($_SESSION['unseen_count']) && array_key_exists($mbox_name, $_SESSION['unseen_count']))
516     return $_SESSION['unseen_count'][$mbox_name];
517   else
518     return null;
519 }
520
521
ec603f 522 /**
A 523  * Sets message is_safe flag according to 'show_images' option value
524  *
525  * @param object rcube_message Message
526  */
527 function rcmail_check_safe(&$message)
528 {
529   global $RCMAIL;
530
531   $show_images = $RCMAIL->config->get('show_images');
532   if (!$message->is_safe
533     && !empty($show_images)
534     && $message->has_html_part())
535   {
536     switch($show_images) {
537       case '1': // known senders only
8a78a1 538         $CONTACTS = new rcube_contacts($RCMAIL->db, $_SESSION['user_id']);
ec603f 539         if ($CONTACTS->search('email', $message->sender['mailto'], true, false)->count) {
A 540           $message->set_safe(true);
541         }
542       break;
543       case '2': // always
544         $message->set_safe(true);
545       break;
546     }
547   }
548 }
f96ffd 549
ec603f 550
A 551 /**
552  * Cleans up the given message HTML Body (for displaying)
553  *
554  * @param string HTML
555  * @param array  Display parameters 
556  * @param array  CID map replaces (inline images)
557  * @return string Clean HTML
558  */
559 function rcmail_wash_html($html, $p = array(), $cid_replaces)
560 {
561   global $REMOTE_OBJECTS;
69a7d3 562
ec603f 563   $p += array('safe' => false, 'inline_html' => true);
2337a8 564
ec603f 565   // special replacements (not properly handled by washtml class)
A 566   $html_search = array(
567     '/(<\/nobr>)(\s+)(<nobr>)/i',    // space(s) between <NOBR>
69a7d3 568     '/<title[^>]*>.*<\/title>/i',    // PHP bug #32547 workaround: remove title tag
3bde30 569     '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/',    // byte-order mark (only outlook?)
4f7aa8 570     '/<html\s[^>]+>/i',            // washtml/DOMDocument cannot handle xml namespaces
ec603f 571   );
A 572   $html_replace = array(
573     '\\1'.' &nbsp; '.'\\3',
574     '',
575     '',
6c2d7e 576     '<html>',
ec603f 577   );
21461d 578   $html = preg_replace($html_search, $html_replace, trim($html));
2337a8 579
b9ec2b 580   // PCRE errors handling (#1486856), should we use something like for every preg_* use?
A 581   if ($html === null && ($preg_error = preg_last_error()) != PREG_NO_ERROR) {
582     $errstr = "Could not clean up HTML message! PCRE Error: $preg_error.";
583
584     if ($preg_error == PREG_BACKTRACK_LIMIT_ERROR)
585       $errstr .= " Consider raising pcre.backtrack_limit!";
586     if ($preg_error == PREG_RECURSION_LIMIT_ERROR)
587       $errstr .= " Consider raising pcre.recursion_limit!";
588
782d85 589     raise_error(array('code' => 620, 'type' => 'php',
b9ec2b 590         'line' => __LINE__, 'file' => __FILE__,
A 591         'message' => $errstr), true, false);
592     return '';
593   }
594
2337a8 595   // fix (unknown/malformed) HTML tags before "wash"
b6673c 596   $html = preg_replace_callback('/(<[\/]*)([^\s>]+)/', 'rcmail_html_tag_callback', $html);
ec603f 597
a80b7d 598   // charset was converted to UTF-8 in rcube_imap::get_message_part(),
269fb8 599   // -> change charset specification in HTML accordingly
66c674 600   $charset_pattern = '(<meta\s+[^>]*content=)[\'"]?(\w+\/\w+;\s*charset=)([a-z0-9-_]+[\'"]?)';
f4bf20 601   if (preg_match("/$charset_pattern/Ui", $html)) {
69a7d3 602     $html = preg_replace("/$charset_pattern/i", '\\1"\\2'.RCMAIL_CHARSET.'"', $html);
ec603f 603   }
269fb8 604   else {
A 605     // add meta content-type to malformed messages, washtml cannot work without that
606     if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html))
607       $html = '<head></head>'. $html;
608     $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0);
609   }
c08b18 610
ec603f 611   // turn relative into absolute urls
A 612   $html = rcmail_resolve_base($html);
613
614   // clean HTML with washhtml by Frederic Motte
615   $wash_opts = array(
616     'show_washed' => false,
617     'allow_remote' => $p['safe'],
618     'blocked_src' => "./program/blocked.gif",
619     'charset' => RCMAIL_CHARSET,
620     'cid_map' => $cid_replaces,
621     'html_elements' => array('body'),
622   );
ce4673 623
ec603f 624   if (!$p['inline_html']) {
A 625     $wash_opts['html_elements'] = array('html','head','title','body');
626   }
627   if ($p['safe']) {
628     $wash_opts['html_elements'][] = 'link';
629     $wash_opts['html_attribs'] = array('rel','type');
630   }
9800a8 631
33da0b 632   // overwrite washer options with options from plugins
A 633   if (isset($p['html_elements']))
634     $wash_opts['html_elements'] = $p['html_elements'];
635   if (isset($p['html_attribs']))
636     $wash_opts['html_attribs'] = $p['html_attribs'];
637
638   // initialize HTML washer
ec603f 639   $washer = new washtml($wash_opts);
33da0b 640
A 641   if (!$p['skip_washer_form_callback'])
642     $washer->add_callback('form', 'rcmail_washtml_callback');
ec603f 643
2337a8 644   // allow CSS styles, will be sanitized by rcmail_washtml_callback()
33da0b 645   if (!$p['skip_washer_style_callback'])
A 646     $washer->add_callback('style', 'rcmail_washtml_callback');
bf1b66 647
ec603f 648   $html = $washer->wash($html);
A 649   $REMOTE_OBJECTS = $washer->extlinks;
5b3ed5 650
ec603f 651   return $html;
A 652 }
653
4e17e6 654
45f56c 655 /**
65cc1c 656  * Convert the given message part to proper HTML
T 657  * which can be displayed the message view
45f56c 658  *
65cc1c 659  * @param object rcube_message_part Message part
ec603f 660  * @param array  Display parameters array 
65cc1c 661  * @return string Formatted HTML string
45f56c 662  */
21e724 663 function rcmail_print_body($part, $p = array())
45f56c 664 {
cc97ea 665   global $RCMAIL;
9800a8 666
cc97ea 667   // trigger plugin hook
T 668   $data = $RCMAIL->plugins->exec_hook('message_part_before',
c9f673 669     array('type' => $part->ctype_secondary, 'body' => $part->body, 'id' => $part->mime_id)
A 670         + $p + array('safe' => false, 'plain' => false, 'inline_html' => true));
ec603f 671
5cc4b1 672   // convert html to text/plain
cc97ea 673   if ($data['type'] == 'html' && $data['plain']) {
T 674     $txt = new html2text($data['body'], false, true);
5cc4b1 675     $body = $txt->get_text();
T 676     $part->ctype_secondary = 'plain';
45f56c 677   }
4e17e6 678   // text/html
cc97ea 679   else if ($data['type'] == 'html') {
T 680     $body = rcmail_wash_html($data['body'], $data, $part->replaces);
681     $part->ctype_secondary = $data['type'];
45f56c 682   }
4e17e6 683   // text/enriched
cc97ea 684   else if ($data['type'] == 'enriched') {
cfe4a6 685     $part->ctype_secondary = 'html';
4351f7 686     require_once(INSTALL_PATH . 'program/lib/enriched.inc');
cc97ea 687     $body = Q(enriched_to_html($data['body']), 'show');
45f56c 688   }
cc97ea 689   else {
T 690     // assert plaintext
45f56c 691     $body = $part->body;
cc97ea 692     $part->ctype_secondary = $data['type'] = 'plain';
45f56c 693   }
9800a8 694
cc97ea 695   // free some memory (hopefully)
T 696   unset($data['body']);
45f56c 697
cc97ea 698   // plaintext postprocessing
4f6932 699   if ($part->ctype_secondary == 'plain')
99b8c1 700     $body = rcmail_plain_body($body, $part->ctype_parameters['format'] == 'flowed');
88ed23 701
cc97ea 702   // allow post-processing of the message body
c9f673 703   $data = $RCMAIL->plugins->exec_hook('message_part_after',
A 704     array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) + $data);
cc97ea 705
T 706   return $data['type'] == 'html' ? $data['body'] : html::tag('pre', array(), $data['body']);
4f6932 707 }
A 708
f96ffd 709
4f6932 710 /**
A 711  * Handle links and citation marks in plain text message
712  *
99b8c1 713  * @param string  Plain text string
A 714  * @param boolean Text uses format=flowed
715  *
4f6932 716  * @return string Formatted HTML string
A 717  */
99b8c1 718 function rcmail_plain_body($body, $flowed=false)
4f6932 719 {
33dfdd 720   global $RCMAIL;
A 721
4f6932 722   // make links and email-addresses clickable
99b8c1 723   $replacer = new rcube_string_replacer;
9800a8 724
4f6932 725   // search for patterns like links and e-mail addresses
99b8c1 726   $body = preg_replace_callback($replacer->link_pattern, array($replacer, 'link_callback'), $body);
A 727   $body = preg_replace_callback($replacer->mailto_pattern, array($replacer, 'mailto_callback'), $body);
4f6932 728
A 729   // split body into single lines
dd0ae6 730   $body = preg_split('/\r?\n/', $body);
4f6932 731   $quote_level = 0;
99b8c1 732   $last = -1;
4f6932 733
A 734   // find/mark quoted lines...
dd0ae6 735   for ($n=0, $cnt=count($body); $n < $cnt; $n++) {
A 736     if ($body[$n][0] == '>' && preg_match('/^(>+\s*)+/', $body[$n], $regs)) {
812728 737       $q = strlen(preg_replace('/\s/', '', $regs[0]));
dd0ae6 738       $body[$n] = substr($body[$n], strlen($regs[0]));
4f6932 739
dd0ae6 740       if ($q > $quote_level) {
A 741         $body[$n] = $replacer->get_replacement($replacer->add(
742           str_repeat('<blockquote>', $q - $quote_level))) . $body[$n];
743       }
744       else if ($q < $quote_level) {
745         $body[$n] = $replacer->get_replacement($replacer->add(
746           str_repeat('</blockquote>', $quote_level - $q))) . $body[$n];
747       }
99b8c1 748       else if ($flowed) {
A 749         // previous line is flowed
dd0ae6 750         if (isset($body[$last]) && $body[$n]
A 751           && $body[$last][strlen($body[$last])-1] == ' ') {
33dfdd 752           // merge lines
dd0ae6 753           $body[$last] .= $body[$n];
A 754           unset($body[$n]);
99b8c1 755         }
dd0ae6 756         else {
99b8c1 757           $last = $n;
dd0ae6 758         }
99b8c1 759       }
4f6932 760     }
99b8c1 761     else {
A 762       $q = 0;
763       if ($flowed) {
764         // sig separator - line is fixed
dd0ae6 765         if ($body[$n] == '-- ') {
A 766           $last = $last_sig = $n;
99b8c1 767         }
A 768         else {
769           // remove space-stuffing
dd0ae6 770           if ($body[$n][0] == ' ')
A 771             $body[$n] = substr($body[$n], 1);
99b8c1 772
A 773           // previous line is flowed?
dd0ae6 774           if (isset($body[$last]) && $body[$n]
A 775             && $last != $last_sig
776             && $body[$last][strlen($body[$last])-1] == ' '
99b8c1 777           ) {
dd0ae6 778             $body[$last] .= $body[$n];
A 779             unset($body[$n]);
99b8c1 780           }
A 781           else {
782             $last = $n;
783           }
784         }
785         if ($quote_level > 0)
dd0ae6 786           $body[$last] = $replacer->get_replacement($replacer->add(
A 787             str_repeat('</blockquote>', $quote_level))) . $body[$last];
99b8c1 788       }
A 789       else if ($quote_level > 0)
dd0ae6 790         $body[$n] = $replacer->get_replacement($replacer->add(
A 791           str_repeat('</blockquote>', $quote_level))) . $body[$n];
99b8c1 792     }
4f6932 793
A 794     $quote_level = $q;
795   }
796
dd0ae6 797   $body = join("\n", $body);
a4c970 798
A 799   // quote plain text (don't use Q() here, to display entities "as is")
800   $table = get_html_translation_table(HTML_SPECIALCHARS);
801   unset($table['?']);
802   $body = strtr($body, $table);
4f6932 803
ba12c7 804   // colorize signature (up to <sig_max_lines> lines)
33dfdd 805   $len = strlen($body);
ba12c7 806   $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15);
33dfdd 807   while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
A 808     if ($sp == 0 || $body[$sp-1] == "\n") {
809       // do not touch blocks with more that X lines
ba12c7 810       if (substr_count($body, "\n", $sp) < $sig_max_lines)
99b8c1 811         $body = substr($body, 0, max(0, $sp))
A 812           .'<span class="sig">'.substr($body, $sp).'</span>';
33dfdd 813       break;
4f6932 814     }
99b8c1 815   }
4f6932 816
99b8c1 817   // insert url/mailto links and citation tags
A 818   $body = $replacer->resolve($body);
4f6932 819
A 820   return $body;
21e724 821 }
4e17e6 822
21e724 823
T 824 /**
825  * Callback function for washtml cleaning class
826  */
827 function rcmail_washtml_callback($tagname, $attrib, $content)
828 {
829   switch ($tagname) {
830     case 'form':
831       $out = html::div('form', $content);
f54a3a 832       break;
9800a8 833
1c499a 834     case 'style':
T 835       // decode all escaped entities and reduce to ascii strings
79e634 836       $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', rcmail_xss_entity_decode($content));
9800a8 837
36c236 838       // now check for evil strings like expression, behavior or url()
79e634 839       if (!preg_match('/expression|behavior|url\(|import[^a]/', $stripped)) {
1c499a 840         $out = html::tag('style', array('type' => 'text/css'), $content);
T 841         break;
842       }
9800a8 843
21e724 844     default:
T 845       $out = '';
846   }
9800a8 847
21e724 848   return $out;
T 849 }
4e17e6 850
T 851
45f56c 852 /**
2337a8 853  * Callback function for HTML tags fixing
A 854  */
855 function rcmail_html_tag_callback($matches)
856 {
857   $tagname = $matches[2];
858
859   $tagname = preg_replace(array(
f96ffd 860     '/:.*$/',            // Microsoft's Smart Tags <st1:xxxx>
A 861     '/[^a-z0-9_\[\]\!-]/i',    // forbidden characters
2337a8 862     ), '', $tagname);
A 863
864   return $matches[1].$tagname;
865 }
866
867
868 /**
45f56c 869  * return table with message headers
T 870  */
4e17e6 871 function rcmail_message_headers($attrib, $headers=NULL)
T 872   {
cc97ea 873   global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL;
4e17e6 874   static $sa_attrib;
9800a8 875
4e17e6 876   // keep header table attrib
T 877   if (is_array($attrib) && !$sa_attrib)
878     $sa_attrib = $attrib;
879   else if (!is_array($attrib) && is_array($sa_attrib))
880     $attrib = $sa_attrib;
9800a8 881
4e17e6 882   if (!isset($MESSAGE))
T 883     return FALSE;
884
885   // get associative array of headers object
886   if (!$headers)
8fa58e 887     $headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers;
7c60ff 888
4e17e6 889   // show these headers
e25a35 890   $standard_headers = array('subject', 'from', 'to', 'cc', 'bcc', 'replyto',
A 891     'mail-reply-to', 'mail-followup-to', 'date');
cc97ea 892   $output_headers = array();
e5686f 893
cc97ea 894   foreach ($standard_headers as $hkey) {
e25a35 895     if ($headers[$hkey])
A 896       $value = $headers[$hkey];
897     else if ($headers['others'][$hkey])
898       $value = $headers['others'][$hkey];
899     else
4e17e6 900       continue;
T 901
cc97ea 902     if ($hkey == 'date') {
5b1de5 903       if ($PRINT_MODE)
e25a35 904         $header_value = format_date($value, $RCMAIL->config->get('date_long', 'x'));
5b1de5 905       else
e25a35 906         $header_value = format_date($value);
cc97ea 907     }
T 908     else if ($hkey == 'replyto') {
700320 909       if ($headers['replyto'] != $headers['from'])
e25a35 910         $header_value = rcmail_address_string($value, null, true, $attrib['addicon']);
700320 911       else
A 912         continue;
4e17e6 913     }
e25a35 914     else if ($hkey == 'mail-reply-to') {
A 915       if ($headers['mail-replyto'] != $headers['reply-to']
916         && $headers['reply-to'] != $headers['from']
917       )
918         $header_value = rcmail_address_string($value, null, true, $attrib['addicon']);
919       else
920         continue;
921     }
922     else if ($hkey == 'mail-followup-to') {
923       $header_value = rcmail_address_string($value, null, true, $attrib['addicon']);
924     }
cc97ea 925     else if (in_array($hkey, array('from', 'to', 'cc', 'bcc')))
e25a35 926       $header_value = rcmail_address_string($value, null, true, $attrib['addicon']);
A 927     else if ($hkey == 'subject' && empty($value))
cc97ea 928       $header_value = rcube_label('nosubject');
T 929     else
e25a35 930       $header_value = trim($IMAP->decode_header($value));
9800a8 931
3ee5a7 932     $output_headers[$hkey] = array(
A 933         'title' => rcube_label(preg_replace('/(^mail-|-)/', '', $hkey)),
934         'value' => $header_value, 'raw' => $value
935     );
cc97ea 936   }
9800a8 937
3ee5a7 938   $plugin = $RCMAIL->plugins->exec_hook('message_headers_output',
A 939     array('output' => $output_headers, 'headers' => $MESSAGE->headers));
9800a8 940
cc97ea 941   // compose html table
T 942   $table = new html_table(array('cols' => 2));
9800a8 943
cc97ea 944   foreach ($plugin['output'] as $hkey => $row) {
T 945     $table->add(array('class' => 'header-title'), Q($row['title']));
cb105a 946     $table->add(array('class' => 'header '.$hkey), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show')));
cc97ea 947   }
4e17e6 948
c6be45 949   return $table->show($attrib);
T 950 }
951
952
953 /**
954  * return block to show full message headers
955  */
956 function rcmail_message_full_headers($attrib, $headers=NULL)
957 {
958   global $OUTPUT;
c08b18 959
c6be45 960   $html = html::div(array('class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), '');
T 961   $html .= html::div(array('id' => "all-headers", 'class' => "all", 'style' => 'display:none'), html::div(array('id' => 'headers-source'), ''));
c08b18 962
e5686f 963   $OUTPUT->add_gui_object('all_headers_row', 'all-headers');
A 964   $OUTPUT->add_gui_object('all_headers_box', 'headers-source');
c08b18 965
c6be45 966   return html::div($attrib, $html);
T 967 }
4e17e6 968
T 969
45f56c 970 /**
21605c 971  * Handler for the 'messagebody' GUI object
45f56c 972  *
21605c 973  * @param array Named parameters
T 974  * @return string HTML content showing the message body
45f56c 975  */
4e17e6 976 function rcmail_message_body($attrib)
T 977   {
3c3433 978   global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $RCMAIL, $REMOTE_OBJECTS;
5f8686 979
8fa58e 980   if (!is_array($MESSAGE->parts) && empty($MESSAGE->body))
4e17e6 981     return '';
9800a8 982
4e17e6 983   if (!$attrib['id'])
T 984     $attrib['id'] = 'rcmailMsgBody';
985
8fa58e 986   $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
21605c 987   $out = '';
9800a8 988
4e17e6 989   $header_attrib = array();
T 990   foreach ($attrib as $attr => $value)
991     if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs))
992       $header_attrib[$regs[1]] = $value;
993
8fa58e 994   if (!empty($MESSAGE->parts))
4e17e6 995     {
8fa58e 996     foreach ($MESSAGE->parts as $i => $part)
4e17e6 997       {
8fa58e 998       if ($part->type == 'headers')
8d4bcd 999         $out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part->headers);
3b7e00 1000       else if ($part->type == 'content' && $part->size)
4e17e6 1001         {
8d4bcd 1002         if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset']))
8fa58e 1003           $part->ctype_parameters['charset'] = $MESSAGE->headers->charset;
a0109c 1004
8d4bcd 1005         // fetch part if not available
T 1006         if (!isset($part->body))
8fa58e 1007           $part->body = $MESSAGE->get_part_content($part->mime_id);
a0109c 1008
64e3e8 1009         // message is cached but not exists (#1485443), or other error
A 1010         if ($part->body === false) {
1011           rcmail_message_error($MESSAGE->uid);
1012         }
1013
3c3433 1014         $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', array(
A 1015           'part' => $part, 'prefix' => ''));
6b6f2e 1016
21e724 1017         $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html']));
5f8686 1018
7b808b 1019         if ($part->ctype_secondary == 'html') {
fb995a 1020           $body = rcmail_html4inline($body, $attrib['id'], 'rcmBody', $attrs);
7b808b 1021           $div_attr = array('class' => 'message-htmlpart');
fb995a 1022           $style = array();
A 1023
cb3dfd 1024           if (!empty($attrs)) {
A 1025             foreach ($attrs as $a_idx => $a_val)
1026               $style[] = $a_idx . ': ' . $a_val;
1027             if (!empty($style))
1028               $div_attr['style'] = implode('; ', $style);
1029           }
7b808b 1030
3c3433 1031           $out .= html::div($div_attr, $plugin['prefix'] . $body);
7b808b 1032         }
a2f2c5 1033         else
3c3433 1034           $out .= html::div('message-part', $plugin['prefix'] . $body);
4e17e6 1035         }
T 1036       }
1037     }
3c3433 1038   else {
A 1039     $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix', array(
1040       'part' => $MESSAGE, 'prefix' => ''));
1041
1042     $out .= html::div('message-part', $plugin['prefix'] . html::tag('pre', array(),
4f6932 1043       rcmail_plain_body(Q($MESSAGE->body, 'strict', false))));
3c3433 1044     }
4e17e6 1045
8fa58e 1046   $ctype_primary = strtolower($MESSAGE->structure->ctype_primary);
T 1047   $ctype_secondary = strtolower($MESSAGE->structure->ctype_secondary);
166b61 1048
4e17e6 1049   // list images after mail body
be5f03 1050   if ($CONFIG['inline_images']
2da368 1051       && $ctype_primary == 'multipart'
38d930 1052       && !empty($MESSAGE->attachments))
166b61 1053     {
8fa58e 1054     foreach ($MESSAGE->attachments as $attach_prop) {
47d06e 1055       // Content-Type: image/*...
A 1056       if (preg_match('/^image\//i', $attach_prop->mimetype) ||
1057         // ...or known file extension: many clients are using application/octet-stream
1058         ($attach_prop->filename &&
1059           preg_match('/^application\/octet-stream$/i', $attach_prop->mimetype) &&
1060           preg_match('/\.(jpg|jpeg|png|gif|bmp)$/i', $attach_prop->filename))
1061       ) {
8fa58e 1062         $out .= html::tag('hr') . html::p(array('align' => "center"),
T 1063           html::img(array(
1064             'src' => $MESSAGE->get_part_url($attach_prop->mime_id),
1065             'title' => $attach_prop->filename,
1066             'alt' => $attach_prop->filename,
1067           )));
1068         }
4e17e6 1069     }
8fa58e 1070   }
9800a8 1071
4e17e6 1072   // tell client that there are blocked remote objects
T 1073   if ($REMOTE_OBJECTS && !$safe_mode)
f11541 1074     $OUTPUT->set_env('blockedobjects', true);
4e17e6 1075
21605c 1076   return html::div($attrib, $out);
4e17e6 1077   }
T 1078
1079
aa055c 1080 /**
T 1081  * Convert all relative URLs according to a <base> in HTML
1082  */
1083 function rcmail_resolve_base($body)
1084 {
1085   // check for <base href=...>
1086   if (preg_match('!(<base.*href=["\']?)([hftps]{3,5}://[a-z0-9/.%-]+)!i', $body, $regs)) {
1087     $replacer = new rcube_base_replacer($regs[2]);
1088
1089     // replace all relative paths
c08b18 1090     $body = preg_replace_callback('/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body);
A 1091     $body = preg_replace_callback('/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body);
aa055c 1092   }
T 1093
1094   return $body;
1095 }
4e17e6 1096
45f56c 1097 /**
T 1098  * modify a HTML message that it can be displayed inside a HTML page
1099  */
fb995a 1100 function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null)
cb3dfd 1101 {
4e17e6 1102   $last_style_pos = 0;
T 1103   $body_lc = strtolower($body);
cb3dfd 1104   $cont_id = $container_id.($body_id ? ' div.'.$body_id : '');
9800a8 1105
4e17e6 1106   // find STYLE tags
T 1107   while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
cb3dfd 1108   {
ea206d 1109     $pos = strpos($body_lc, '>', $pos)+1;
T 1110
4e17e6 1111     // replace all css definitions with #container [def]
cb3dfd 1112     $styles = rcmail_mod_css_styles(
A 1113       substr($body, $pos, $pos2-$pos), $cont_id);
ea206d 1114
3b12ae 1115     $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
S 1116     $body_lc = strtolower($body);
4e17e6 1117     $last_style_pos = $pos2;
cb3dfd 1118   }
4e17e6 1119
fe79b1 1120   // modify HTML links to open a new window if clicked
115263 1121   $GLOBALS['rcmail_html_container_id'] = $container_id;
T 1122   $body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body);
1123   unset($GLOBALS['rcmail_html_container_id']);
4e17e6 1124
cb3dfd 1125   $body = preg_replace(array(
b488c1 1126       // add comments arround html and other tags
d7a411 1127       '/(<!DOCTYPE[^>]*>)/i',
A 1128       '/(<\?xml[^>]*>)/i',
06895c 1129       '/(<\/?html[^>]*>)/i',
T 1130       '/(<\/?head[^>]*>)/i',
1131       '/(<title[^>]*>.*<\/title>)/Ui',
b488c1 1132       '/(<\/?meta[^>]*>)/i',
A 1133       // quote <? of php and xml files that are specified as text/html
1134       '/<\?/',
1135       '/\?>/',
1136       // replace <body> with <div>
1137       '/<body([^>]*)>/i',
1138       '/<\/body>/i',
1139       ),
1140     array(
1141       '<!--\\1-->',
1142       '<!--\\1-->',
1143       '<!--\\1-->',
1144       '<!--\\1-->',
1145       '<!--\\1-->',
1146       '<!--\\1-->',
1147       '&lt;?',
1148       '?&gt;',
7b808b 1149       '<div class="'.$body_id.'"\\1>',
b488c1 1150       '</div>',
A 1151       ),
06895c 1152     $body);
a0109c 1153
fb995a 1154   $attributes = array();
A 1155
1156   // Handle body attributes that doesn't play nicely with div elements
ceb708 1157   $regexp = '/<div class="' . preg_quote($body_id, '/') . '"([^>]*)/';
A 1158   if (preg_match($regexp, $body, $m)) {
fb995a 1159     $attrs = $m[0];
A 1160     // Get bgcolor, we'll set it as background-color of the message container
ceb708 1161     if ($m[1] && preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $attrs, $mb)) {
cb3dfd 1162       $attributes['background-color'] = $mb[1];
fb995a 1163       $attrs = preg_replace('/bgcolor=["\']*([a-z0-9#]+)["\']*/', '', $attrs);
7b808b 1164     }
fb995a 1165     // Get background, we'll set it as background-image of the message container
ceb708 1166     if ($m[1] && preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) {
cb3dfd 1167       $attributes['background-image'] = 'url('.$mb[1].')';
fb995a 1168       $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs);
A 1169     }
ceb708 1170     if (!empty($attributes)) {
A 1171       $body = preg_replace($regexp, rtrim($attrs), $body, 1);
1172     }
cb3dfd 1173
A 1174     // handle body styles related to background image
1175     if ($attributes['background-image']) {
1176       // get body style
1177       if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) {
1178         // get background related style
1179         if (preg_match_all('/(background-position|background-repeat)\s*:\s*([^;]+);/i', $m[1], $ma, PREG_SET_ORDER)) {
1180           foreach ($ma as $style)
1181             $attributes[$style[1]] = $style[2];
1182         }
1183       }
1184     }
7b808b 1185   }
b488c1 1186   // make sure there's 'rcmBody' div, we need it for proper css modification
A 1187   // its name is hardcoded in rcmail_message_body() also
ceb708 1188   else {
cb3dfd 1189     $body = '<div class="' . $body_id . '">' . $body . '</div>';
ceb708 1190   }
86958f 1191
cb3dfd 1192   return $body;
A 1193 }
4e17e6 1194
T 1195
45f56c 1196 /**
T 1197  * parse link attributes and set correct target
1198  */
115263 1199 function rcmail_alter_html_link($matches)
e5af2f 1200 {
5c1dfb 1201   global $RCMAIL;
A 1202
1203   // Support unicode/punycode in top-level domain part
1204   $EMAIL_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[^&@"\'.][^@&"\']*\\.([^\\x00-\\x40\\x5b-\\x60\\x7b-\\x7f]{2,}|xn--[a-z0-9]{2,}))';
9800a8 1205
115263 1206   $tag = $matches[1];
T 1207   $attrib = parse_attrib_string($matches[2]);
e5af2f 1208   $end = '>';
84f5b7 1209
29c542 1210   // Remove non-printable characters in URL (#1487805)
A 1211   $attrib['href'] = preg_replace('/[\x00-\x1F]/', '', $attrib['href']);
1212
e5af2f 1213   if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) {
3e0e91 1214     $tempurl = 'tmp-' . md5($attrib['href']) . '.css';
T 1215     $_SESSION['modcssurls'][$tempurl] = $attrib['href'];
1216     $attrib['href'] = $RCMAIL->url(array('task' => 'utils', 'action' => 'modcss', 'u' => $tempurl, 'c' => $GLOBALS['rcmail_html_container_id']));
e5af2f 1217     $end = ' />';
T 1218   }
5c1dfb 1219   else if (preg_match('/^mailto:'.$EMAIL_PATTERN.'(\?[^"\'>]+)?/i', $attrib['href'], $mailto)) {
115263 1220     $attrib['href'] = $mailto[0];
97bd2c 1221     $attrib['onclick'] = sprintf(
T 1222       "return %s.command('compose','%s',this)",
1223       JS_OBJECT_NAME,
5c1dfb 1224       JQ($mailto[1].$mailto[3]));
4e17e6 1225   }
e5af2f 1226   else if (!empty($attrib['href']) && $attrib['href'][0] != '#') {
T 1227     $attrib['target'] = '_blank';
1228   }
1229
1230   return "<$tag" . html::attrib_string($attrib, array('href','name','target','onclick','id','class','style','title','rel','type','media')) . $end;
1231 }
4e17e6 1232
T 1233
45f56c 1234 /**
T 1235  * decode address string and re-format it as HTML links
1236  */
8e44f4 1237 function rcmail_address_string($input, $max=null, $linked=false, $addicon=null)
T 1238 {
e99991 1239   global $IMAP, $RCMAIL, $PRINT_MODE, $CONFIG;
1088d6 1240
4e17e6 1241   $a_parts = $IMAP->decode_address_list($input);
T 1242
1243   if (!sizeof($a_parts))
1244     return $input;
1245
1246   $c = count($a_parts);
1247   $j = 0;
1248   $out = '';
1249
ecb51c 1250   if ($addicon && !isset($_SESSION['writeable_abook'])) {
T 1251     $_SESSION['writeable_abook'] = $RCMAIL->get_address_sources(true) ? true : false;
55243b 1252   }
b579f4 1253
8e44f4 1254   foreach ($a_parts as $part) {
4e17e6 1255     $j++;
e99991 1256
A 1257     $name   = $part['name'];
1258     $mailto = $part['mailto'];
1259     $string = $part['string'];
1260
1261     // IDNA ASCII to Unicode
1262     if ($name == $mailto)
e8d5bd 1263       $name = rcube_idn_to_utf8($name);
e99991 1264     if ($string == $mailto)
e8d5bd 1265       $string = rcube_idn_to_utf8($string);
A 1266     $mailto = rcube_idn_to_utf8($mailto);
e99991 1267
8e44f4 1268     if ($PRINT_MODE) {
e99991 1269       $out .= sprintf('%s &lt;%s&gt;', Q($name), $mailto);
8e44f4 1270     }
1baeb6 1271     else if (check_email($part['mailto'], false)) {
8e44f4 1272       if ($linked) {
768091 1273         $address = html::a(array(
e99991 1274             'href' => 'mailto:'.$mailto,
A 1275             'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($mailto)),
1276             'title' => $mailto,
8e44f4 1277             'class' => "rcmContactAddress",
T 1278           ),
e99991 1279         Q($name ? $name : $mailto));
4e17e6 1280       }
8e44f4 1281       else {
768091 1282         $address = html::span(array('title' => $mailto, 'class' => "rcmContactAddress"),
e99991 1283           Q($name ? $name : $mailto));
8e44f4 1284       }
T 1285
ecb51c 1286       if ($addicon && $_SESSION['writeable_abook']) {
829cbf 1287         $address = html::span(null, $address . html::a(array(
8e44f4 1288             'href' => "#add",
e99991 1289             'onclick' => sprintf("return %s.command('add-contact','%s',this)", JS_OBJECT_NAME, urlencode($string)),
8e44f4 1290             'title' => rcube_label('addtoaddressbook'),
T 1291           ),
1292           html::img(array(
1293             'src' => $CONFIG['skin_path'] . $addicon,
1294             'alt' => "Add contact",
829cbf 1295           ))));
8e44f4 1296       }
768091 1297       $out .= $address;
8e44f4 1298     }
T 1299     else {
e99991 1300       if ($name)
A 1301         $out .= Q($name);
1302       if ($mailto)
1303         $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', Q($mailto));
8e44f4 1304     }
9800a8 1305
4e17e6 1306     if ($c>$j)
T 1307       $out .= ','.($max ? '&nbsp;' : ' ');
9800a8 1308
8e44f4 1309     if ($max && $j==$max && $c>$j) {
4e17e6 1310       $out .= '...';
T 1311       break;
1312     }
8e44f4 1313   }
9800a8 1314
4e17e6 1315   return $out;
8e44f4 1316 }
4e17e6 1317
T 1318
ccd63c 1319 /**
T 1320  * Wrap text to a given number of characters per line
6b6f2e 1321  * but respect the mail quotation of replies messages (>).
T 1322  * Finally add another quotation level by prpending the lines
1323  * with >
ccd63c 1324  *
T 1325  * @param string Text to wrap
1326  * @param int The line width
1327  * @return string The wrapped text
1328  */
6b6f2e 1329 function rcmail_wrap_and_quote($text, $length = 72)
ccd63c 1330 {
T 1331   // Rebuild the message body with a maximum of $max chars, while keeping quoted message.
dffcaa 1332   $max = min(77, $length + 8);
ccd63c 1333   $lines = preg_split('/\r?\n/', trim($text));
T 1334   $out = '';
1335
1336   foreach ($lines as $line) {
6b6f2e 1337     // don't wrap already quoted lines
T 1338     if ($line[0] == '>')
1339       $line = '>' . rtrim($line);
1340     else if (mb_strlen($line) > $max) {
1341       $newline = '';
1342       foreach(explode("\n", rc_wordwrap($line, $length - 2)) as $l) {
1343         if (strlen($l))
1344           $newline .= '> ' . $l . "\n";
1345         else
1346           $newline .= ">\n";
ccd63c 1347       }
6b6f2e 1348       $line = rtrim($newline);
ccd63c 1349     }
6b6f2e 1350     else
T 1351       $line = '> ' . $line;
ccd63c 1352
T 1353     // Append the line
1354     $out .= $line . "\n";
1355   }
9800a8 1356
ccd63c 1357   return $out;
T 1358 }
1359
1360
bc404f 1361 function rcmail_draftinfo_encode($p)
T 1362 {
1363   $parts = array();
1364   foreach ($p as $key => $val)
1365     $parts[] = $key . '=' . ($key == 'folder' ? base64_encode($val) : $val);
9800a8 1366
bc404f 1367   return join('; ', $parts);
T 1368 }
1369
1370
1371 function rcmail_draftinfo_decode($str)
1372 {
1373   $info = array();
1374   foreach (preg_split('/;\s+/', $str) as $part) {
1375     list($key, $val) = explode('=', $part, 2);
1376     if ($key == 'folder')
1377       $val = base64_decode($val);
1378     $info[$key] = $val;
1379   }
9800a8 1380
bc404f 1381   return $info;
T 1382 }
1383
1384
4e17e6 1385 function rcmail_message_part_controls()
e99991 1386 {
8fa58e 1387   global $MESSAGE;
9800a8 1388
d5342a 1389   $part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC));
8fa58e 1390   if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part])
4e17e6 1391     return '';
9800a8 1392
8fa58e 1393   $part = $MESSAGE->mime_parts[$part];
T 1394   $table = new html_table(array('cols' => 3));
9800a8 1395
8fa58e 1396   if (!empty($part->filename)) {
T 1397     $table->add('title', Q(rcube_label('filename')));
1398     $table->add(null, Q($part->filename));
8dc048 1399     $table->add(null, '[' . html::a('?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q(rcube_label('download'))) . ']');
8fa58e 1400   }
9800a8 1401
8fa58e 1402   if (!empty($part->size)) {
T 1403     $table->add('title', Q(rcube_label('filesize')));
1404     $table->add(null, Q(show_bytes($part->size)));
1405   }
9800a8 1406
8fa58e 1407   return $table->show($attrib);
e99991 1408 }
4e17e6 1409
T 1410
1411
1412 function rcmail_message_part_frame($attrib)
e99991 1413 {
4e17e6 1414   global $MESSAGE;
9800a8 1415
8fa58e 1416   $part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))];
4e17e6 1417   $ctype_primary = strtolower($part->ctype_primary);
T 1418
95fcc3 1419   $attrib['src'] = './?' . str_replace('_frame=', ($ctype_primary=='text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']);
4e17e6 1420
95fcc3 1421   return html::iframe($attrib);
e99991 1422 }
4e17e6 1423
T 1424
45f56c 1425 /**
T 1426  * clear message composing settings
1427  */
4591de 1428 function rcmail_compose_cleanup($id)
e99991 1429 {
4591de 1430   if (!isset($_SESSION['compose_data'][$id]))
4e17e6 1431     return;
70d4b9 1432
929a50 1433   $rcmail = rcmail::get_instance();
4591de 1434   $rcmail->plugins->exec_hook('attachments_cleanup', array('group' => $id));
T 1435   unset($_SESSION['compose_data'][$id]);
e99991 1436 }
9800a8 1437
fba1f5 1438
T 1439 /**
a99968 1440  * Send the MDN response
A 1441  *
1442  * @param mixed $message    Original message object (rcube_message) or UID
1443  * @param array $smtp_error SMTP error array (reference)
1444  *
1445  * @return boolean Send status
1446  */
1447 function rcmail_send_mdn($message, &$smtp_error)
0ea884 1448 {
83a763 1449   global $RCMAIL, $IMAP;
8fa58e 1450
a99968 1451   if (!is_a($message, rcube_message))
A 1452     $message = new rcube_message($message);
9800a8 1453
5c771c 1454   if ($message->headers->mdn_to && !$message->headers->mdn_sent &&
A 1455     ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')))
0ea884 1456   {
83a763 1457     $identity = $RCMAIL->user->get_identity();
0ea884 1458     $sender = format_email_recipient($identity['email'], $identity['name']);
8fa58e 1459     $recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to));
0ea884 1460     $mailto = $recipient['mailto'];
T 1461
ac8edb 1462     $compose = new Mail_mime("\r\n");
91790e 1463
A 1464     $compose->setParam('text_encoding', 'quoted-printable');
1465     $compose->setParam('html_encoding', 'quoted-printable');
1466     $compose->setParam('head_encoding', 'quoted-printable');
1467     $compose->setParam('head_charset', RCMAIL_CHARSET);
1468     $compose->setParam('html_charset', RCMAIL_CHARSET);
1469     $compose->setParam('text_charset', RCMAIL_CHARSET);
9800a8 1470
0ea884 1471     // compose headers array
T 1472     $headers = array(
2bf3cc 1473       'Date' => rcmail_user_date(),
0ea884 1474       'From' => $sender,
8fa58e 1475       'To'   => $message->headers->mdn_to,
T 1476       'Subject' => rcube_label('receiptread') . ': ' . $message->subject,
1d8cbc 1477       'Message-ID' => rcmail_gen_message_id(),
0ea884 1478       'X-Sender' => $identity['email'],
ea50e7 1479       'References' => trim($message->headers->references . ' ' . $message->headers->messageID),
0ea884 1480     );
9800a8 1481
83a763 1482     if ($agent = $RCMAIL->config->get('useragent'))
T 1483       $headers['User-Agent'] = $agent;
0ea884 1484
T 1485     $body = rcube_label("yourmessage") . "\r\n\r\n" .
8fa58e 1486       "\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" .
T 1487       "\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" .
83a763 1488       "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" .
0ea884 1489       "\r\n" . rcube_label("receiptnote") . "\r\n";
9800a8 1490
e019f2 1491     $ua = $RCMAIL->config->get('useragent', "Roundcube Webmail (Version ".RCMAIL_VERSION.")");
0ea884 1492     $report = "Reporting-UA: $ua\r\n";
9800a8 1493
8fa58e 1494     if ($message->headers->to)
T 1495         $report .= "Original-Recipient: {$message->headers->to}\r\n";
9800a8 1496
0ea884 1497     $report .= "Final-Recipient: rfc822; {$identity['email']}\r\n" .
8fa58e 1498                "Original-Message-ID: {$message->headers->messageID}\r\n" .
0ea884 1499                "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
9800a8 1500
8fa58e 1501     $compose->headers($headers);
6b0113 1502     $compose->setContentType('multipart/report', array('report-type'=> 'disposition-notification'));
7145e0 1503     $compose->setTXTBody(rc_wordwrap($body, 75, "\r\n"));
0ea884 1504     $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline');
T 1505
91790e 1506     $sent = rcmail_deliver_message($compose, $identity['email'], $mailto, $smtp_error, $body_file);
0ea884 1507
T 1508     if ($sent)
1509     {
8fa58e 1510       $IMAP->set_flag($message->uid, 'MDNSENT');
0ea884 1511       return true;
T 1512     }
1513   }
9800a8 1514
0ea884 1515   return false;
T 1516 }
1517
2bf3cc 1518
e0bd70 1519 // Fixes some content-type names
A 1520 function rcmail_fix_mimetype($name)
1521 {
1522   // Some versions of Outlook create garbage Content-Type:
1523   // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608
1524   if (preg_match('/^application\/pdf.+/', $name))
1525     $name = 'application/pdf';
1526
1527   return $name;
1528 }
2bf3cc 1529
e538b3 1530 function rcmail_search_filter($attrib)
A 1531 {
119cd1 1532   global $OUTPUT, $CONFIG;
e538b3 1533
A 1534   if (!strlen($attrib['id']))
1535     $attrib['id'] = 'rcmlistfilter';
1536
1537   $attrib['onchange'] = JS_OBJECT_NAME.'.filter_mailbox(this.value)';
9800a8 1538
e538b3 1539   /*
A 1540     RFC3501 (6.4.4): 'ALL', 'RECENT', 
1541     'ANSWERED', 'DELETED', 'FLAGGED', 'SEEN',
1542     'UNANSWERED', 'UNDELETED', 'UNFLAGGED', 'UNSEEN',
1543     'NEW', // = (RECENT UNSEEN)
1544     'OLD' // = NOT RECENT
1545   */
1546
1547   $select_filter = new html_select($attrib);
1548   $select_filter->add(rcube_label('all'), 'ALL');
1549   $select_filter->add(rcube_label('unread'), 'UNSEEN');
1550   $select_filter->add(rcube_label('flagged'), 'FLAGGED');
1551   $select_filter->add(rcube_label('unanswered'), 'UNANSWERED');
119cd1 1552   if (!$CONFIG['skip_deleted'])
A 1553     $select_filter->add(rcube_label('deleted'), 'DELETED');
e538b3 1554
A 1555   $out = $select_filter->show($_SESSION['search_filter']);
1556
1557   $OUTPUT->add_gui_object('search_filter', $attrib['id']);
1558
9800a8 1559   return $out;
e538b3 1560 }
A 1561
64e3e8 1562 function rcmail_message_error($uid=null)
A 1563 {
1564   global $RCMAIL;
1565
1566   // Set env variables for messageerror.html template
1567   if ($RCMAIL->action == 'show') {
1568     $mbox_name = $RCMAIL->imap->get_mailbox_name();
1569     $RCMAIL->output->set_env('mailbox', $mbox_name);
1570     $RCMAIL->output->set_env('uid', null);
1571   }
1572   // display error message
1573   $RCMAIL->output->show_message('messageopenerror', 'error');
1574   // ... display message error page
1575   $RCMAIL->output->send('messageerror');
1576 }
9b3fdc 1577
f11541 1578 // register UI objects
T 1579 $OUTPUT->add_handlers(array(
1580   'mailboxlist' => 'rcmail_mailbox_list',
1581   'messages' => 'rcmail_message_list',
1582   'messagecountdisplay' => 'rcmail_messagecount_display',
1583   'quotadisplay' => 'rcmail_quota_display',
ac5d15 1584   'mailboxname' => 'rcmail_mailbox_name_display',
f11541 1585   'messageheaders' => 'rcmail_message_headers',
c6be45 1586   'messagefullheaders' => 'rcmail_message_full_headers',
f11541 1587   'messagebody' => 'rcmail_message_body',
T 1588   'messagecontentframe' => 'rcmail_messagecontent_frame',
1589   'messagepartframe' => 'rcmail_message_part_frame',
1590   'messagepartcontrols' => 'rcmail_message_part_controls',
e538b3 1591   'searchfilter' => 'rcmail_search_filter',
47124c 1592   'searchform' => array($OUTPUT, 'search_form'),
f11541 1593 ));
T 1594
68d2d5 1595 // register action aliases
A 1596 $RCMAIL->register_action_map(array(
1597     'preview' => 'show.inc',
1598     'print'   => 'show.inc',
1599     'moveto'  => 'move_del.inc',
1600     'delete'  => 'move_del.inc',
1601     'send'    => 'sendmail.inc',
1602     'expunge' => 'folders.inc',
1603     'purge'   => 'folders.inc',
1604     'remove-attachment'  => 'attachments.inc',
1605     'display-attachment' => 'attachments.inc',
1606     'upload'             => 'attachments.inc',
1607     'group-expand'       => 'autocomplete.inc',
1608 ));