4 +-----------------------------------------------------------------------+
5 | program/steps/mail/func.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide webmail functionality and GUI objects |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: func.inc 3058 2009-10-24 19:09:23Z alec $
22 $EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9][a-z0-9\-\.]*\\.[a-z]{2,5})';
24 // actions that do not require imap connection
25 $NOIMAP_ACTIONS = array('spell', 'addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment');
28 // log in to imap server
29 if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) {
30 $RCMAIL->kill_session();
32 if ($OUTPUT->ajax_call)
33 $OUTPUT->redirect(array(), 2000);
35 $OUTPUT->set_env('task', 'login');
36 $OUTPUT->send('login');
40 // set imap properties and session vars
41 if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC))
42 $IMAP->set_mailbox(($_SESSION['mbox'] = $mbox));
44 $_SESSION['mbox'] = $IMAP->get_mailbox_name();
46 if (!empty($_GET['_page']))
47 $IMAP->set_page(($_SESSION['page'] = intval($_GET['_page'])));
49 // set default sort col/order to session
50 if (!isset($_SESSION['sort_col']))
51 $_SESSION['sort_col'] = $CONFIG['message_sort_col'];
52 if (!isset($_SESSION['sort_order']))
53 $_SESSION['sort_order'] = $CONFIG['message_sort_order'];
55 // set message set for search result
56 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
58 $IMAP->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
59 $OUTPUT->set_env('search_request', $_REQUEST['_search']);
60 $OUTPUT->set_env('search_text', $_SESSION['last_text_search']);
63 // set main env variables, labels and page title
64 if (empty($RCMAIL->action) || $RCMAIL->action == 'list')
66 $mbox_name = $IMAP->get_mailbox_name();
68 if (empty($RCMAIL->action))
70 // initialize searching result if search_filter is used
71 if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL')
73 $search_request = md5($mbox_name.$_SESSION['search_filter']);
75 $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']);
76 $_SESSION['search'][$search_request] = $IMAP->get_search_set();
77 $OUTPUT->set_env('search_request', $search_request);
80 $OUTPUT->set_env('search_mods', $_SESSION['search_mods'] ? $_SESSION['search_mods'] : array('subject'=>'subject'));
81 // make sure the message count is refreshed (for default view)
82 $IMAP->messagecount($mbox_name, 'ALL', true);
85 // set current mailbox in client environment
86 $OUTPUT->set_env('mailbox', $mbox_name);
87 $OUTPUT->set_env('quota', $IMAP->get_capability('quota'));
88 $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
90 if ($CONFIG['flag_for_deletion'])
91 $OUTPUT->set_env('flag_for_deletion', true);
92 if ($CONFIG['read_when_deleted'])
93 $OUTPUT->set_env('read_when_deleted', true);
94 if ($CONFIG['skip_deleted'])
95 $OUTPUT->set_env('skip_deleted', true);
96 if ($CONFIG['display_next'])
97 $OUTPUT->set_env('display_next', true);
99 if ($CONFIG['trash_mbox'])
100 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
101 if ($CONFIG['drafts_mbox'])
102 $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
103 if ($CONFIG['junk_mbox'])
104 $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']);
106 if (!$OUTPUT->ajax_call)
107 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
109 $OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name));
114 * return the message list as HTML table
116 function rcmail_message_list($attrib)
118 global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT;
120 $skin_path = $CONFIG['skin_path'];
121 $image_tag = '<img src="%s%s" alt="%s" />';
123 // check to see if we have some settings for sorting
124 $sort_col = $_SESSION['sort_col'];
125 $sort_order = $_SESSION['sort_order'];
127 // add some labels to client
128 $OUTPUT->add_label('from', 'to');
130 // get message headers
131 $a_headers = $IMAP->list_headers('', '', $sort_col, $sort_order);
133 // add id to message list table if not specified
134 if (!strlen($attrib['id']))
135 $attrib['id'] = 'rcubemessagelist';
137 // allow the following attributes to be added to the <table> tag
138 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
140 $out = '<table' . $attrib_str . ">\n";
142 // define list of cols to be displayed based on parameter or config
143 if (empty($attrib['columns']))
144 $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
146 $a_show_cols = preg_split('/[\s,;]+/', strip_quotes($attrib['columns']));
148 // store column list in a session-variable
149 $_SESSION['list_columns'] = $a_show_cols;
151 // define sortable columns
152 $a_sort_cols = array('subject', 'date', 'from', 'to', 'size');
154 $mbox = $IMAP->get_mailbox_name();
155 $delim = $IMAP->get_hierarchy_delimiter();
157 // show 'to' instead of 'from' in sent/draft messages
158 if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0)
159 && ($f = array_search('from', $a_show_cols)) && !array_search('to', $a_show_cols))
160 $a_show_cols[$f] = 'to';
162 // add col definition
163 $out .= '<colgroup>';
164 $out .= '<col class="icon" />';
166 foreach ($a_show_cols as $col)
167 $out .= ($col!='attachment') ? sprintf('<col class="%s" />', $col) : '<col class="icon" />';
169 $out .= "</colgroup>\n";
172 $out .= "<thead><tr>\n<td class=\"icon\"> </td>\n";
175 foreach ($a_show_cols as $col)
181 $col_name = sprintf($image_tag, $skin_path, $attrib['unflaggedicon'], '');
184 $col_name = sprintf($image_tag, $skin_path, $attrib['attachmenticon'], '');
187 $col_name = Q(rcube_label($col));
192 if (in_array($col, $a_sort_cols))
194 // have buttons configured
195 if (!empty($attrib['sortdescbutton']) || !empty($attrib['sortascbutton']))
197 $sort = ' ';
200 if (!empty($attrib['sortascbutton']))
202 $sort .= $OUTPUT->button(array(
204 'prop' => $col.'_ASC',
205 'image' => $attrib['sortascbutton'],
206 'align' => 'absmiddle',
207 'title' => 'sortasc'));
211 if (!empty($attrib['sortdescbutton']))
213 $sort .= $OUTPUT->button(array(
215 'prop' => $col.'_DESC',
216 'image' => $attrib['sortdescbutton'],
217 'align' => 'absmiddle',
218 'title' => 'sortdesc'));
221 // just add a link tag to the header
225 '<a href="./#sort" onclick="return %s.command(\'sort\',\'%s\',this)" title="%s">%s</a>',
228 rcube_label('sortby'),
233 $sort_class = $col==$sort_col ? " sorted$sort_order" : '';
235 // put it all together
236 if ($col!='attachment')
237 $out .= '<td class="'.$col.$sort_class.'" id="rcm'.$col.'">' . "$col_name$sort</td>\n";
239 $out .= '<td class="icon" id="rcm'.$col.'">' . "$col_name$sort</td>\n";
242 $out .= "</tr></thead>\n<tbody>\n";
244 // no messages in this mailbox
245 if (!sizeof($a_headers))
246 $OUTPUT->show_message('nomessagesfound', 'notice');
248 $a_js_message_arr = array();
250 // create row for each message
251 foreach ($a_headers as $i => $header) //while (list($i, $header) = each($a_headers))
253 $message_icon = $attach_icon = $flagged_icon = '';
254 $js_row_arr = array();
255 $zebra_class = $i%2 ? ' even' : ' odd';
257 // set messag attributes to javascript array
258 if ($header->deleted)
259 $js_row_arr['deleted'] = true;
261 $js_row_arr['unread'] = true;
262 if ($header->answered)
263 $js_row_arr['replied'] = true;
264 if ($header->forwarded)
265 $js_row_arr['forwarded'] = true;
266 if ($header->flagged)
267 $js_row_arr['flagged'] = true;
270 if ($attrib['deletedicon'] && $header->deleted)
271 $message_icon = $attrib['deletedicon'];
272 else if ($attrib['repliedicon'] && $header->answered)
274 if ($attrib['forwardedrepliedicon'] && $header->forwarded)
275 $message_icon = $attrib['forwardedrepliedicon'];
277 $message_icon = $attrib['repliedicon'];
279 else if ($attrib['forwardedicon'] && $header->forwarded)
280 $message_icon = $attrib['forwardedicon'];
281 else if ($attrib['unreadicon'] && !$header->seen)
282 $message_icon = $attrib['unreadicon'];
283 else if ($attrib['messageicon'])
284 $message_icon = $attrib['messageicon'];
286 if ($attrib['flaggedicon'] && $header->flagged)
287 $flagged_icon = $attrib['flaggedicon'];
288 else if ($attrib['unflaggedicon'] && !$header->flagged)
289 $flagged_icon = $attrib['unflaggedicon'];
291 // set attachment icon
292 if ($attrib['attachmenticon'] && preg_match("/multipart\/m/i", $header->ctype))
293 $attach_icon = $attrib['attachmenticon'];
295 $out .= sprintf('<tr id="rcmrow%d" class="message%s%s%s%s">'."\n",
297 $header->seen ? '' : ' unread',
298 $header->deleted ? ' deleted' : '',
299 $header->flagged ? ' flagged' : '',
302 $out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : '');
304 $IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']);
307 foreach ($a_show_cols as $col)
309 if ($col=='from' || $col=='to')
310 $cont = Q(rcmail_address_string($header->$col, 3, false, $attrib['addicon']), 'show');
311 else if ($col=='subject')
313 $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show';
314 $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid';
315 $cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160);
316 if (empty($cont)) $cont = rcube_label('nosubject');
317 $cont = $OUTPUT->browser->ie ? Q($cont) : sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), Q($cont));
319 else if ($col=='flag')
320 $cont = $flagged_icon ? sprintf($image_tag, $skin_path, $flagged_icon, '') : '';
321 else if ($col=='size')
322 $cont = show_bytes($header->$col);
323 else if ($col=='date')
324 $cont = format_date($header->date);
326 $cont = Q($header->$col);
328 if ($col!='attachment')
329 $out .= '<td class="'.$col.'">' . $cont . "</td>\n";
331 $out .= sprintf("<td class=\"icon\">%s</td>\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : ' ');
336 if (sizeof($js_row_arr))
337 $a_js_message_arr[$header->uid] = $js_row_arr;
340 // complete message table
341 $out .= "</tbody></table>\n";
343 $message_count = $IMAP->messagecount();
346 $OUTPUT->add_gui_object('mailcontframe', 'mailcontframe');
347 $OUTPUT->add_gui_object('messagelist', $attrib['id']);
348 $OUTPUT->set_env('messagecount', $message_count);
349 $OUTPUT->set_env('current_page', $IMAP->list_page);
350 $OUTPUT->set_env('pagecount', ceil($message_count/$IMAP->page_size));
351 $OUTPUT->set_env('sort_col', $sort_col);
352 $OUTPUT->set_env('sort_order', $sort_order);
354 if ($attrib['messageicon'])
355 $OUTPUT->set_env('messageicon', $skin_path . $attrib['messageicon']);
356 if ($attrib['deletedicon'])
357 $OUTPUT->set_env('deletedicon', $skin_path . $attrib['deletedicon']);
358 if ($attrib['unreadicon'])
359 $OUTPUT->set_env('unreadicon', $skin_path . $attrib['unreadicon']);
360 if ($attrib['repliedicon'])
361 $OUTPUT->set_env('repliedicon', $skin_path . $attrib['repliedicon']);
362 if ($attrib['forwardedicon'])
363 $OUTPUT->set_env('forwardedicon', $skin_path . $attrib['forwardedicon']);
364 if ($attrib['forwardedrepliedicon'])
365 $OUTPUT->set_env('forwardedrepliedicon', $skin_path . $attrib['forwardedrepliedicon']);
366 if ($attrib['attachmenticon'])
367 $OUTPUT->set_env('attachmenticon', $skin_path . $attrib['attachmenticon']);
368 if ($attrib['flaggedicon'])
369 $OUTPUT->set_env('flaggedicon', $skin_path . $attrib['flaggedicon']);
370 if ($attrib['unflaggedicon'])
371 $OUTPUT->set_env('unflaggedicon', $skin_path . $attrib['unflaggedicon']);
373 $OUTPUT->set_env('messages', $a_js_message_arr);
374 $OUTPUT->set_env('coltypes', $a_show_cols);
376 $OUTPUT->include_script('list.js');
383 * return javascript commands to add rows to the message list
384 * or to replace the whole list (IE only)
386 function rcmail_js_message_list($a_headers, $insert_top=FALSE, $replace=TRUE)
388 global $CONFIG, $IMAP, $OUTPUT;
390 if (empty($_SESSION['list_columns']))
391 $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
393 $a_show_cols = $_SESSION['list_columns'];
395 $mbox = $IMAP->get_mailbox_name();
396 $delim = $IMAP->get_hierarchy_delimiter();
398 // show 'to' instead of 'from' in sent/draft messages
399 if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0)
400 && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
401 $a_show_cols[$f] = 'to';
403 $browser = new rcube_browser;
405 $OUTPUT->command('set_message_coltypes', $a_show_cols);
407 // remove 'attachment' and 'flag' columns, we don't need them here
408 if(($key = array_search('attachment', $a_show_cols)) !== FALSE)
409 unset($a_show_cols[$key]);
410 if(($key = array_search('flag', $a_show_cols)) !== FALSE)
411 unset($a_show_cols[$key]);
413 if ($browser->ie && $replace)
414 $OUTPUT->command('offline_message_list', true);
416 // loop through message headers
417 foreach ($a_headers as $n => $header)
419 $a_msg_cols = array();
420 $a_msg_flags = array();
425 $IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']);
427 // format each col; similar as in rcmail_message_list()
428 foreach ($a_show_cols as $col)
430 if ($col=='from' || $col=='to')
431 $cont = Q(rcmail_address_string($header->$col, 3), 'show');
432 else if ($col=='subject')
434 $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show';
435 $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid';
436 $cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160);
437 if (!$cont) $cont = rcube_label('nosubject');
438 $cont = $browser->ie ? Q($cont) : sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), Q($cont));
440 else if ($col=='size')
441 $cont = show_bytes($header->$col);
442 else if ($col=='date')
443 $cont = format_date($header->date);
445 $cont = Q($header->$col);
447 $a_msg_cols[$col] = $cont;
450 if ($header->deleted)
451 $a_msg_flags['deleted'] = 1;
453 $a_msg_flags['unread'] = 1;
454 if ($header->answered)
455 $a_msg_flags['replied'] = 1;
456 if ($header->forwarded)
457 $a_msg_flags['forwarded'] = 1;
458 if ($header->flagged)
459 $a_msg_flags['flagged'] = 1;
462 $a_msg_cols = rc_utf8_clean($a_msg_cols);
464 $OUTPUT->command('add_message_row',
468 preg_match("/multipart\/m/i", $header->ctype),
472 if ($browser->ie && $replace)
473 $OUTPUT->command('offline_message_list', false);
478 * return an HTML iframe for loading mail content
480 function rcmail_messagecontent_frame($attrib)
484 if (empty($attrib['id']))
485 $attrib['id'] = 'rcmailcontentwindow';
487 $attrib['name'] = $attrib['id'];
489 $OUTPUT->set_env('contentframe', $attrib['id']);
490 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
492 return html::iframe($attrib);
496 function rcmail_messagecount_display($attrib)
498 global $IMAP, $OUTPUT;
501 $attrib['id'] = 'rcmcountdisplay';
503 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
505 return html::span($attrib, rcmail_get_messagecount_text());
509 function rcmail_quota_display($attrib)
511 global $OUTPUT, $COMM_PATH;
514 $attrib['id'] = 'rcmquotadisplay';
516 if(isset($attrib['display']))
517 $_SESSION['quota_display'] = $attrib['display'];
519 $OUTPUT->add_gui_object('quotadisplay', $attrib['id']);
521 $quota = rcmail_quota_content(NULL, $attrib);
523 if (is_array($quota)) {
524 $OUTPUT->add_script('$(document).ready(function(){
525 rcmail.set_quota('.json_serialize($quota).')});', 'foot');
529 return html::span($attrib, $quota);
533 function rcmail_quota_content($quota=NULL, $attrib=NULL)
535 global $IMAP, $COMM_PATH, $RCMAIL;
537 $display = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';
540 if (!$IMAP->get_capability('QUOTA'))
541 return rcube_label('unknown');
543 $quota = $IMAP->get_quota();
546 if ($quota && !($quota['total']==0 && $RCMAIL->config->get('quota_zero_as_unlimited')))
548 $quota_result = sprintf('%s / %s (%.0f%%)',
549 show_bytes($quota['used'] * 1024), show_bytes($quota['total'] * 1024),
552 if ($display == 'image') {
553 $quota_result = array(
554 'percent' => $quota['percent'],
555 'title' => $quota_result,
557 if ($attrib['width'])
558 $quota_result['width'] = $attrib['width'];
559 if ($attrib['height'])
560 $quota_result['height'] = $attrib['height'];
564 return rcube_label('unlimited');
566 return $quota_result;
570 function rcmail_get_messagecount_text($count=NULL, $page=NULL)
572 global $IMAP, $MESSAGE;
574 if (isset($MESSAGE->index))
576 return rcube_label(array('name' => 'messagenrof',
577 'vars' => array('nr' => $MESSAGE->index+1,
578 'count' => $count!==NULL ? $count : $IMAP->messagecount())));
582 $page = $IMAP->list_page;
584 $start_msg = ($page-1) * $IMAP->page_size + 1;
585 $max = $count!==NULL ? $count : $IMAP->messagecount();
588 $out = rcube_label('mailboxempty');
590 $out = rcube_label(array('name' => 'messagesfromto',
591 'vars' => array('from' => $start_msg,
592 'to' => min($max, $start_msg + $IMAP->page_size - 1),
599 function rcmail_mailbox_name_display($attrib)
604 $attrib['id'] = 'rcmmailboxname';
606 $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']);
608 return html::span($attrib, rcmail_get_mailbox_name_text());
611 function rcmail_get_mailbox_name_text()
614 return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name());
618 function rcmail_send_unread_count($mbox_name, $force=false)
622 $old_unseen = $_SESSION['unseen_count'][$mbox_name];
623 $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force);
625 if ($unseen != $old_unseen || ($mbox_name == 'INBOX'))
626 $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, ($mbox_name == 'INBOX'));
628 // @TODO: this data is doubled (session and cache tables) if caching is enabled
629 $_SESSION['unseen_count'][$mbox_name] = $unseen;
636 * Sets message is_safe flag according to 'show_images' option value
638 * @param object rcube_message Message
640 function rcmail_check_safe(&$message)
644 $show_images = $RCMAIL->config->get('show_images');
645 if (!$message->is_safe
646 && !empty($show_images)
647 && $message->has_html_part())
649 switch($show_images) {
650 case '1': // known senders only
651 $CONTACTS = new rcube_contacts($RCMAIL->db, $_SESSION['user_id']);
652 if ($CONTACTS->search('email', $message->sender['mailto'], true, false)->count) {
653 $message->set_safe(true);
657 $message->set_safe(true);
664 * Cleans up the given message HTML Body (for displaying)
667 * @param array Display parameters
668 * @param array CID map replaces (inline images)
669 * @return string Clean HTML
671 function rcmail_wash_html($html, $p = array(), $cid_replaces)
673 global $REMOTE_OBJECTS;
675 $p += array('safe' => false, 'inline_html' => true);
677 // special replacements (not properly handled by washtml class)
678 $html_search = array(
679 '/(<\/nobr>)(\s+)(<nobr>)/i', // space(s) between <NOBR>
680 '/<title>.*<\/title>/i', // PHP bug #32547 workaround: remove title tag
681 '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', // byte-order mark (only outlook?)
682 '/<html\s[^>]+>/i', // washtml/DOMDocument cannot handle xml namespaces
684 $html_replace = array(
685 '\\1'.' '.'\\3',
690 $html = preg_replace($html_search, $html_replace, $html);
692 // fix (unknown/malformed) HTML tags before "wash"
693 $html = preg_replace_callback('/(<[\/]*)([^\s>]+)/', 'rcmail_html_tag_callback', $html);
695 // charset was converted to UTF-8 in rcube_imap::get_message_part(),
696 // -> change charset specification in HTML accordingly
697 $charset_pattern = '(<meta\s+[^>]*)(content=[\'"]?\w+\/\w+;\s*charset)=([a-z0-9-_]+)';
698 if (preg_match("/$charset_pattern/Ui", $html)) {
699 $html = preg_replace("/$charset_pattern/i", '\\1\\2='.RCMAIL_CHARSET, $html);
702 // add meta content-type to malformed messages, washtml cannot work without that
703 if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html))
704 $html = '<head></head>'. $html;
705 $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0);
708 // turn relative into absolute urls
709 $html = rcmail_resolve_base($html);
711 // clean HTML with washhtml by Frederic Motte
713 'show_washed' => false,
714 'allow_remote' => $p['safe'],
715 'blocked_src' => "./program/blocked.gif",
716 'charset' => RCMAIL_CHARSET,
717 'cid_map' => $cid_replaces,
718 'html_elements' => array('body'),
721 if (!$p['inline_html']) {
722 $wash_opts['html_elements'] = array('html','head','title','body');
725 $wash_opts['html_elements'][] = 'link';
726 $wash_opts['html_attribs'] = array('rel','type');
729 $washer = new washtml($wash_opts);
730 $washer->add_callback('form', 'rcmail_washtml_callback');
732 // allow CSS styles, will be sanitized by rcmail_washtml_callback()
733 $washer->add_callback('style', 'rcmail_washtml_callback');
735 $html = $washer->wash($html);
736 $REMOTE_OBJECTS = $washer->extlinks;
743 * Convert the given message part to proper HTML
744 * which can be displayed the message view
746 * @param object rcube_message_part Message part
747 * @param array Display parameters array
748 * @return string Formatted HTML string
750 function rcmail_print_body($part, $p = array())
754 // trigger plugin hook
755 $data = $RCMAIL->plugins->exec_hook('message_part_before',
756 array('type' => $part->ctype_secondary, 'body' => $part->body) + $p + array('safe' => false, 'plain' => false, 'inline_html' => true));
758 // convert html to text/plain
759 if ($data['type'] == 'html' && $data['plain']) {
760 $txt = new html2text($data['body'], false, true);
761 $body = $txt->get_text();
762 $part->ctype_secondary = 'plain';
765 else if ($data['type'] == 'html') {
766 $body = rcmail_wash_html($data['body'], $data, $part->replaces);
767 $part->ctype_secondary = $data['type'];
770 else if ($data['type'] == 'enriched') {
771 $part->ctype_secondary = 'html';
772 require_once('lib/enriched.inc');
773 $body = Q(enriched_to_html($data['body']), 'show');
778 $part->ctype_secondary = $data['type'] = 'plain';
781 // free some memory (hopefully)
782 unset($data['body']);
784 // plaintext postprocessing
785 if ($part->ctype_secondary == 'plain')
786 $body = rcmail_plain_body($body);
788 // allow post-processing of the message body
789 $data = $RCMAIL->plugins->exec_hook('message_part_after', array('type' => $part->ctype_secondary, 'body' => $body) + $data);
791 return $data['type'] == 'html' ? $data['body'] : html::tag('pre', array(), $data['body']);
795 * Handle links and citation marks in plain text message
797 * @param string Plain text string
798 * @return string Formatted HTML string
800 function rcmail_plain_body($body)
802 // make links and email-addresses clickable
803 $replacements = new rcube_string_replacer;
805 // search for patterns like links and e-mail addresses
806 $body = preg_replace_callback($replacements->link_pattern, array($replacements, 'link_callback'), $body);
807 $body = preg_replace_callback($replacements->mailto_pattern, array($replacements, 'mailto_callback'), $body);
809 // split body into single lines
810 $a_lines = preg_split('/\r?\n/', $body);
814 // find/mark quoted lines...
815 for ($n=0, $cnt=count($a_lines); $n < $cnt; $n++) {
818 if ($a_lines[$n][0] == '>' && preg_match('/^(>+\s*)+/', $a_lines[$n], $regs)) {
819 $q = strlen(preg_replace('/\s/', '', $regs[0]));
820 $a_lines[$n] = substr($a_lines[$n], strlen($regs[0]));
822 if ($q > $quote_level)
823 $q_lines[$n]['quote'] = $q - $quote_level;
824 else if ($q < $quote_level)
825 $q_lines[$n]['endquote'] = $quote_level - $q;
827 else if ($quote_level > 0)
828 $q_lines[$n]['endquote'] = $quote_level;
834 $body = Q(join("\n", $a_lines), 'replace', false);
836 // colorize signature
837 if (($sp = strrpos($body, '-- ')) !== false)
838 if (($sp == 0 || $body[$sp-1] == "\n") && $body[$sp+3] == "\n") {
839 $body = substr($body, 0, max(0, $sp))
840 .'<span class="sig">'.substr($body, $sp).'</span>';
843 // colorize quoted lines
844 $a_lines = preg_split('/\n/', $body);
845 foreach ($q_lines as $i => $q)
847 $a_lines[$i] = str_repeat('<blockquote>', $q['quote']) . $a_lines[$i];
848 else if ($q['endquote'])
849 $a_lines[$i] = str_repeat('</blockquote>', $q['endquote']) . $a_lines[$i];
851 // insert the links for urls and mailtos
852 $body = $replacements->resolve(join("\n", $a_lines));
859 * add a string to the replacement array and return a replacement string
861 function rcmail_str_replacement($str, &$rep)
864 $rep[$count] = stripslashes($str);
865 return "##string_replacement{".($count++)."}##";
870 * Callback function for washtml cleaning class
872 function rcmail_washtml_callback($tagname, $attrib, $content)
876 $out = html::div('form', $content);
880 // decode all escaped entities and reduce to ascii strings
881 $stripped = preg_replace('/[^a-zA-Z\(:]/', '', rcmail_xss_entity_decode($content));
883 // now check for evil strings like expression, behavior or url()
884 if (!preg_match('/expression|behavior|url\(|import/', $stripped)) {
885 $out = html::tag('style', array('type' => 'text/css'), $content);
898 * Callback function for HTML tags fixing
900 function rcmail_html_tag_callback($matches)
902 $tagname = $matches[2];
904 $tagname = preg_replace(array(
905 '/:.*$/', // Microsoft's Smart Tags <st1:xxxx>
906 '/[^a-z0-9_-]/i', // forbidden characters
909 return $matches[1].$tagname;
914 * return table with message headers
916 function rcmail_message_headers($attrib, $headers=NULL)
918 global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL;
921 // keep header table attrib
922 if (is_array($attrib) && !$sa_attrib)
923 $sa_attrib = $attrib;
924 else if (!is_array($attrib) && is_array($sa_attrib))
925 $attrib = $sa_attrib;
927 if (!isset($MESSAGE))
930 // get associative array of headers object
932 $headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers;
934 // show these headers
935 $standard_headers = array('subject', 'from', 'to', 'cc', 'bcc', 'replyto', 'date');
936 $output_headers = array();
938 foreach ($standard_headers as $hkey) {
939 if (!$headers[$hkey])
942 if ($hkey == 'date') {
944 $header_value = format_date($headers[$hkey], $RCMAIL->config->get('date_long', 'x'));
946 $header_value = format_date($headers[$hkey]);
948 else if ($hkey == 'replyto') {
949 if ($headers['replyto'] != $headers['from'])
950 $header_value = rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']);
954 else if (in_array($hkey, array('from', 'to', 'cc', 'bcc')))
955 $header_value = rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']);
956 else if ($hkey == 'subject' && empty($headers[$hkey]))
957 $header_value = rcube_label('nosubject');
959 $header_value = trim($IMAP->decode_header($headers[$hkey]));
961 $output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $headers[$hkey]);
964 $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers));
966 // compose html table
967 $table = new html_table(array('cols' => 2));
969 foreach ($plugin['output'] as $hkey => $row) {
970 $table->add(array('class' => 'header-title'), Q($row['title']));
971 $table->add(array('class' => $hkey, 'width' => "90%"), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show')));
974 // all headers division
975 $table->add(array('colspan' => 2, 'class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), '');
976 $table->add_row(array('id' => "all-headers"));
977 $table->add(array('colspan' => 2, 'class' => "all"), html::div(array('id' => 'headers-source'), ''));
979 $OUTPUT->add_gui_object('all_headers_row', 'all-headers');
980 $OUTPUT->add_gui_object('all_headers_box', 'headers-source');
982 return $table->show($attrib);
987 * Handler for the 'messagebody' GUI object
989 * @param array Named parameters
990 * @return string HTML content showing the message body
992 function rcmail_message_body($attrib)
994 global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $REMOTE_OBJECTS;
996 if (!is_array($MESSAGE->parts) && empty($MESSAGE->body))
1000 $attrib['id'] = 'rcmailMsgBody';
1002 $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
1005 $header_attrib = array();
1006 foreach ($attrib as $attr => $value)
1007 if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs))
1008 $header_attrib[$regs[1]] = $value;
1010 if (!empty($MESSAGE->parts))
1012 foreach ($MESSAGE->parts as $i => $part)
1014 if ($part->type == 'headers')
1015 $out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part->headers);
1016 else if ($part->type == 'content' && $part->size)
1018 if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset']))
1019 $part->ctype_parameters['charset'] = $MESSAGE->headers->charset;
1021 // fetch part if not available
1022 if (!isset($part->body))
1023 $part->body = $MESSAGE->get_part_content($part->mime_id);
1025 $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html']));
1027 if ($part->ctype_secondary == 'html')
1028 $out .= html::div('message-htmlpart', rcmail_html4inline($body, $attrib['id']));
1030 $out .= html::div('message-part', $body);
1035 $out .= html::div('message-part', html::tag('pre', array(),
1036 rcmail_plain_body(Q($MESSAGE->body, 'strict', false))));
1038 $ctype_primary = strtolower($MESSAGE->structure->ctype_primary);
1039 $ctype_secondary = strtolower($MESSAGE->structure->ctype_secondary);
1041 // list images after mail body
1042 if ($CONFIG['inline_images']
1043 && $ctype_primary == 'multipart'
1044 && !empty($MESSAGE->attachments)
1045 && !strstr($message_body, '<html'))
1047 foreach ($MESSAGE->attachments as $attach_prop) {
1048 if (strpos($attach_prop->mimetype, 'image/') === 0) {
1049 $out .= html::tag('hr') . html::p(array('align' => "center"),
1051 'src' => $MESSAGE->get_part_url($attach_prop->mime_id),
1052 'title' => $attach_prop->filename,
1053 'alt' => $attach_prop->filename,
1059 // tell client that there are blocked remote objects
1060 if ($REMOTE_OBJECTS && !$safe_mode)
1061 $OUTPUT->set_env('blockedobjects', true);
1063 return html::div($attrib, $out);
1068 * Convert all relative URLs according to a <base> in HTML
1070 function rcmail_resolve_base($body)
1072 // check for <base href=...>
1073 if (preg_match('!(<base.*href=["\']?)([hftps]{3,5}://[a-z0-9/.%-]+)!i', $body, $regs)) {
1074 $replacer = new rcube_base_replacer($regs[2]);
1076 // replace all relative paths
1077 $body = preg_replace_callback('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body);
1078 $body = preg_replace_callback('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body);
1085 * modify a HTML message that it can be displayed inside a HTML page
1087 function rcmail_html4inline($body, $container_id)
1089 $last_style_pos = 0;
1090 $body_lc = strtolower($body);
1093 while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
1095 $pos = strpos($body_lc, '>', $pos)+1;
1097 // replace all css definitions with #container [def]
1098 $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id);
1100 $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
1101 $body_lc = strtolower($body);
1102 $last_style_pos = $pos2;
1105 // modify HTML links to open a new window if clicked
1106 $GLOBALS['rcmail_html_container_id'] = $container_id;
1107 $body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body);
1108 unset($GLOBALS['rcmail_html_container_id']);
1110 // add comments arround html and other tags
1111 $out = preg_replace(array(
1112 '/(<!DOCTYPE[^>]*>)/i',
1113 '/(<\?xml[^>]*>)/i',
1114 '/(<\/?html[^>]*>)/i',
1115 '/(<\/?head[^>]*>)/i',
1116 '/(<title[^>]*>.*<\/title>)/Ui',
1117 '/(<\/?meta[^>]*>)/i'),
1121 $out = preg_replace(
1122 array('/<body([^>]*)>/i', '/<\/body>/i'),
1123 array('<div class="rcmBody"\\1>', '</div>'),
1126 // quote <? of php and xml files that are specified as text/html
1127 $out = preg_replace(array('/<\?/', '/\?>/'), array('<?', '?>'), $out);
1134 * parse link attributes and set correct target
1136 function rcmail_alter_html_link($matches)
1138 global $EMAIL_ADDRESS_PATTERN;
1141 $attrib = parse_attrib_string($matches[2]);
1144 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) {
1145 $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($GLOBALS['rcmail_html_container_id']);
1148 else if (preg_match("/^mailto:$EMAIL_ADDRESS_PATTERN/i", $attrib['href'], $mailto)) {
1149 $attrib['href'] = $mailto[0];
1150 $attrib['onclick'] = sprintf(
1151 "return %s.command('compose','%s',this)",
1155 else if (!empty($attrib['href']) && $attrib['href'][0] != '#') {
1156 $attrib['target'] = '_blank';
1159 return "<$tag" . html::attrib_string($attrib, array('href','name','target','onclick','id','class','style','title','rel','type','media')) . $end;
1164 * decode address string and re-format it as HTML links
1166 function rcmail_address_string($input, $max=null, $linked=false, $addicon=null)
1168 global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $EMAIL_ADDRESS_PATTERN;
1170 $a_parts = $IMAP->decode_address_list($input);
1172 if (!sizeof($a_parts))
1175 $c = count($a_parts);
1179 foreach ($a_parts as $part) {
1182 $out .= sprintf('%s <%s>', Q($part['name']), $part['mailto']);
1184 else if (preg_match("/$EMAIL_ADDRESS_PATTERN/i", $part['mailto'])) {
1186 $out .= html::a(array(
1187 'href' => 'mailto:'.$part['mailto'],
1188 'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($part['mailto'])),
1189 'title' => $part['mailto'],
1190 'class' => "rcmContactAddress",
1195 $out .= html::span(array('title' => $part['mailto'], 'class' => "rcmContactAddress"), Q($part['name']));
1199 $out .= ' ' . html::a(array(
1201 'onclick' => sprintf("return %s.command('add-contact','%s',this)", JS_OBJECT_NAME, urlencode($part['string'])),
1202 'title' => rcube_label('addtoaddressbook'),
1205 'src' => $CONFIG['skin_path'] . $addicon,
1206 'alt' => "Add contact",
1212 $out .= Q($part['name']);
1213 if ($part['mailto'])
1214 $out .= (strlen($out) ? ' ' : '') . sprintf('<%s>', Q($part['mailto']));
1218 $out .= ','.($max ? ' ' : ' ');
1220 if ($max && $j==$max && $c>$j) {
1231 * Wrap text to a given number of characters per line
1232 * but respect the mail quotation of replies messages (>)
1234 * @param string Text to wrap
1235 * @param int The line width
1236 * @return string The wrapped text
1238 function rcmail_wrap_quoted($text, $max = 76)
1240 // Rebuild the message body with a maximum of $max chars, while keeping quoted message.
1241 $lines = preg_split('/\r?\n/', trim($text));
1244 foreach ($lines as $line) {
1245 if (strlen($line) > $max) {
1246 if (preg_match('/^([>\s]+)/', $line, $regs)) {
1247 $length = strlen($regs[0]);
1248 $prefix = substr($line, 0, $length);
1250 // Remove '> ' from the line, then wordwrap() the line
1251 $line = rc_wordwrap(substr($line, $length), $max - $length);
1253 // Rebuild the line with '> ' at the beginning of each 'subline'
1255 foreach (explode("\n", $line) as $l) {
1256 $newline .= $prefix . $l . "\n";
1259 // Remove the righest newline char
1260 $line = rtrim($newline);
1263 $line = rc_wordwrap($line, $max);
1268 $out .= $line . "\n";
1275 function rcmail_message_part_controls()
1279 $part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC));
1280 if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part])
1283 $part = $MESSAGE->mime_parts[$part];
1284 $table = new html_table(array('cols' => 3));
1286 if (!empty($part->filename)) {
1287 $table->add('title', Q(rcube_label('filename')));
1288 $table->add(null, Q($part->filename));
1289 $table->add(null, '[' . html::a('?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q(rcube_label('download'))) . ']');
1292 if (!empty($part->size)) {
1293 $table->add('title', Q(rcube_label('filesize')));
1294 $table->add(null, Q(show_bytes($part->size)));
1297 return $table->show($attrib);
1302 function rcmail_message_part_frame($attrib)
1306 $part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))];
1307 $ctype_primary = strtolower($part->ctype_primary);
1309 $attrib['src'] = './?' . str_replace('_frame=', ($ctype_primary=='text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']);
1311 return html::iframe($attrib);
1316 * clear message composing settings
1318 function rcmail_compose_cleanup()
1320 if (!isset($_SESSION['compose']))
1323 rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array());
1325 rcube_sess_unset('compose');
1330 * Send the given message compose object using the configured method
1332 function rcmail_deliver_message(&$message, $from, $mailto, &$smtp_error)
1334 global $CONFIG, $RCMAIL;
1336 $msg_body = $message->get();
1337 $headers = $message->headers();
1339 // send thru SMTP server using custom SMTP library
1340 if ($CONFIG['smtp_server']) {
1341 // generate list of recipients
1342 $a_recipients = array($mailto);
1344 if (strlen($headers['Cc']))
1345 $a_recipients[] = $headers['Cc'];
1346 if (strlen($headers['Bcc']))
1347 $a_recipients[] = $headers['Bcc'];
1349 // clean Bcc from header for recipients
1350 $send_headers = $headers;
1351 unset($send_headers['Bcc']);
1352 // here too, it because txtHeaders() below use $message->_headers not only $send_headers
1353 unset($message->_headers['Bcc']);
1356 if (!is_object($RCMAIL->smtp))
1357 $RCMAIL->smtp_init(true);
1359 $sent = $RCMAIL->smtp->send_mail($from, $a_recipients, ($foo = $message->txtHeaders($send_headers, true)), $msg_body);
1360 $smtp_response = $RCMAIL->smtp->get_response();
1361 $smtp_error = $RCMAIL->smtp->get_error();
1365 raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__,
1366 'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE);
1368 // send mail using PHP's mail() function
1370 // unset some headers because they will be added by the mail() function
1371 $headers_enc = $message->headers($headers);
1372 $headers_php = $message->_headers;
1373 unset($headers_php['To'], $headers_php['Subject']);
1375 // reset stored headers and overwrite
1376 $message->_headers = array();
1377 $header_str = $message->txtHeaders($headers_php);
1380 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1381 if (preg_match_all('/<([^@]+@[^>]+)>/', $headers_enc['To'], $m)) {
1382 $headers_enc['To'] = implode(', ', $m[1]);
1386 if (ini_get('safe_mode'))
1387 $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str);
1389 $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
1393 $RCMAIL->plugins->exec_hook('message_sent', array('headers' => $headers, 'body' => $msg_body));
1395 // remove MDN headers after sending
1396 unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']);
1398 if ($CONFIG['smtp_log']) {
1399 write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s",
1400 $RCMAIL->user->get_username(),
1401 $_SERVER['REMOTE_ADDR'],
1403 !empty($smtp_response) ? join('; ', $smtp_response) : ''));
1407 $message->_headers = array();
1408 $message->headers($headers);
1414 function rcmail_send_mdn($uid, &$smtp_error)
1416 global $RCMAIL, $IMAP;
1418 $message = new rcube_message($uid);
1420 if ($message->headers->mdn_to && !$message->headers->mdn_sent &&
1421 ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')))
1423 $identity = $RCMAIL->user->get_identity();
1424 $sender = format_email_recipient($identity['email'], $identity['name']);
1425 $recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to));
1426 $mailto = $recipient['mailto'];
1428 $compose = new rcube_mail_mime($RCMAIL->config->header_delimiter());
1429 $compose->setParam(array(
1430 'text_encoding' => 'quoted-printable',
1431 'html_encoding' => 'quoted-printable',
1432 'head_encoding' => 'quoted-printable',
1433 'head_charset' => RCMAIL_CHARSET,
1434 'html_charset' => RCMAIL_CHARSET,
1435 'text_charset' => RCMAIL_CHARSET,
1438 // compose headers array
1440 'Date' => date('r'),
1442 'To' => $message->headers->mdn_to,
1443 'Subject' => rcube_label('receiptread') . ': ' . $message->subject,
1444 'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.mt_rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])),
1445 'X-Sender' => $identity['email'],
1446 'Content-Type' => 'multipart/report; report-type=disposition-notification',
1449 if ($agent = $RCMAIL->config->get('useragent'))
1450 $headers['User-Agent'] = $agent;
1452 $body = rcube_label("yourmessage") . "\r\n\r\n" .
1453 "\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" .
1454 "\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" .
1455 "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" .
1456 "\r\n" . rcube_label("receiptnote") . "\r\n";
1458 $ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")");
1459 $report = "Reporting-UA: $ua\r\n";
1461 if ($message->headers->to)
1462 $report .= "Original-Recipient: {$message->headers->to}\r\n";
1464 $report .= "Final-Recipient: rfc822; {$identity['email']}\r\n" .
1465 "Original-Message-ID: {$message->headers->messageID}\r\n" .
1466 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
1468 $compose->headers($headers);
1469 $compose->setTXTBody(rc_wordwrap($body, 75, "\r\n"));
1470 $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline');
1472 $sent = rcmail_deliver_message($compose, $identity['email'], $mailto, $smtp_error);
1476 $IMAP->set_flag($message->uid, 'MDNSENT');
1485 function rcmail_search_filter($attrib)
1487 global $OUTPUT, $CONFIG;
1489 if (!strlen($attrib['id']))
1490 $attrib['id'] = 'rcmlistfilter';
1492 $attrib['onchange'] = JS_OBJECT_NAME.'.filter_mailbox(this.value)';
1495 RFC3501 (6.4.4): 'ALL', 'RECENT',
1496 'ANSWERED', 'DELETED', 'FLAGGED', 'SEEN',
1497 'UNANSWERED', 'UNDELETED', 'UNFLAGGED', 'UNSEEN',
1498 'NEW', // = (RECENT UNSEEN)
1499 'OLD' // = NOT RECENT
1502 $select_filter = new html_select($attrib);
1503 $select_filter->add(rcube_label('all'), 'ALL');
1504 $select_filter->add(rcube_label('unread'), 'UNSEEN');
1505 $select_filter->add(rcube_label('flagged'), 'FLAGGED');
1506 $select_filter->add(rcube_label('unanswered'), 'UNANSWERED');
1507 if (!$CONFIG['skip_deleted'])
1508 $select_filter->add(rcube_label('deleted'), 'DELETED');
1510 $out = $select_filter->show($_SESSION['search_filter']);
1512 $OUTPUT->add_gui_object('search_filter', $attrib['id']);
1517 // register UI objects
1518 $OUTPUT->add_handlers(array(
1519 'mailboxlist' => 'rcmail_mailbox_list',
1520 'messages' => 'rcmail_message_list',
1521 'messagecountdisplay' => 'rcmail_messagecount_display',
1522 'quotadisplay' => 'rcmail_quota_display',
1523 'mailboxname' => 'rcmail_mailbox_name_display',
1524 'messageheaders' => 'rcmail_message_headers',
1525 'messagebody' => 'rcmail_message_body',
1526 'messagecontentframe' => 'rcmail_messagecontent_frame',
1527 'messagepartframe' => 'rcmail_message_part_frame',
1528 'messagepartcontrols' => 'rcmail_message_part_controls',
1529 'searchfilter' => 'rcmail_search_filter',
1530 'searchform' => array($OUTPUT, 'search_form'),