source: github/program/steps/mail/func.inc @ 2106ec7

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 2106ec7 was 2106ec7, checked in by alecpl <alec@…>, 5 years ago
  • don't show 'To' header if contains only /undisclosed-recipients[:;]*$/
  • Property mode set to 100644
File size: 41.6 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/func.inc                                           |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
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
22require_once('lib/enriched.inc');
23require_once('include/rcube_smtp.inc');
24
25
26$EMAIL_ADDRESS_PATTERN = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i';
27
28if (empty($_SESSION['mbox']))
29  $_SESSION['mbox'] = $IMAP->get_mailbox_name();
30
31// set imap properties and session vars
32if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC))
33  $IMAP->set_mailbox(($_SESSION['mbox'] = $mbox));
34
35if (!empty($_GET['_page']))
36  $IMAP->set_page(($_SESSION['page'] = intval($_GET['_page'])));
37
38// set mailbox to INBOX if not set
39if (empty($_SESSION['mbox']))
40  $_SESSION['mbox'] = $IMAP->get_mailbox_name();
41
42// set default sort col/order to session
43if (!isset($_SESSION['sort_col']))
44  $_SESSION['sort_col'] = $CONFIG['message_sort_col'];
45if (!isset($_SESSION['sort_order']))
46  $_SESSION['sort_order'] = $CONFIG['message_sort_order'];
47
48// set message set for search result
49if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
50  {
51  $IMAP->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
52  $OUTPUT->set_env('search_request', $_REQUEST['_search']);
53  $OUTPUT->set_env('search_text', $_SESSION['last_text_search']);
54  }
55
56
57// set current mailbox in client environment
58$OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name());
59$OUTPUT->set_env('quota', $IMAP->get_capability('quota'));
60$OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
61
62if ($CONFIG['trash_mbox'])
63  $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
64if ($CONFIG['drafts_mbox'])
65  $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
66if ($CONFIG['junk_mbox'])
67  $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']);
68
69if (!$OUTPUT->ajax_call)
70  rcube_add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
71
72// set page title
73if (empty($RCMAIL->action) || $RCMAIL->action == 'list')
74  $OUTPUT->set_pagetitle(rcmail_localize_foldername($IMAP->get_mailbox_name()));
75
76
77/**
78 * return the message list as HTML table
79 */
80function rcmail_message_list($attrib)
81  {
82  global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT;
83
84  $skin_path = $CONFIG['skin_path'];
85  $image_tag = '<img src="%s%s" alt="%s" />';
86
87  // check to see if we have some settings for sorting
88  $sort_col   = $_SESSION['sort_col'];
89  $sort_order = $_SESSION['sort_order'];
90 
91  // add some labels to client
92  rcube_add_label('from', 'to');
93
94  // get message headers
95  $a_headers = $IMAP->list_headers('', '', $sort_col, $sort_order);
96
97  // add id to message list table if not specified
98  if (!strlen($attrib['id']))
99    $attrib['id'] = 'rcubemessagelist';
100
101  // allow the following attributes to be added to the <table> tag
102  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
103
104  $out = '<table' . $attrib_str . ">\n";
105
106  // define list of cols to be displayed
107  $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
108  $a_sort_cols = array('subject', 'date', 'from', 'to', 'size');
109
110  $mbox = $IMAP->get_mailbox_name();
111 
112  // show 'to' instead of from in sent messages
113  if (($mbox==$CONFIG['sent_mbox'] || $mbox==$CONFIG['drafts_mbox']) && ($f = array_search('from', $a_show_cols))
114      && !array_search('to', $a_show_cols))
115    $a_show_cols[$f] = 'to';
116 
117  // add col definition
118  $out .= '<colgroup>';
119  $out .= '<col class="icon" />';
120
121  foreach ($a_show_cols as $col)
122    $out .= sprintf('<col class="%s" />', $col);
123
124  $out .= '<col class="icon" />';
125  $out .= "</colgroup>\n";
126
127  // add table title
128  $out .= "<thead><tr>\n<td class=\"icon\">&nbsp;</td>\n";
129
130  $javascript = '';
131  foreach ($a_show_cols as $col)
132    {
133    // get column name
134    $col_name = $col != 'flag' ? Q(rcube_label($col)) : sprintf($image_tag, $skin_path, $attrib['unflaggedicon'], '');
135
136    // make sort links
137    $sort = '';
138    if (in_array($col, $a_sort_cols))
139      {
140      // have buttons configured
141      if (!empty($attrib['sortdescbutton']) || !empty($attrib['sortascbutton']))
142        {
143        $sort = '&nbsp;&nbsp;';
144
145        // asc link
146        if (!empty($attrib['sortascbutton']))
147          {
148          $sort .= $OUTPUT->button(array(
149            'command' => 'sort',
150            'prop' => $col.'_ASC',
151            'image' => $attrib['sortascbutton'],
152            'align' => 'absmiddle',
153            'title' => 'sortasc'));
154          }       
155       
156        // desc link
157        if (!empty($attrib['sortdescbutton']))
158          {
159          $sort .= $OUTPUT->button(array(
160            'command' => 'sort',
161            'prop' => $col.'_DESC',
162            'image' => $attrib['sortdescbutton'],
163            'align' => 'absmiddle',
164            'title' => 'sortdesc'));
165          }
166        }
167      // just add a link tag to the header
168      else
169        {
170        $col_name = sprintf(
171          '<a href="./#sort" onclick="return %s.command(\'sort\',\'%s\',this)" title="%s">%s</a>',
172          JS_OBJECT_NAME,
173          $col,
174          rcube_label('sortby'),
175          $col_name);
176        }
177      }
178     
179    $sort_class = $col==$sort_col ? " sorted$sort_order" : '';
180
181    // put it all together
182    $out .= '<td class="'.$col.$sort_class.'" id="rcmHead'.$col.'">' . "$col_name$sort</td>\n";   
183    }
184
185  $out .= '<td class="icon">'.($attrib['attachmenticon'] ? sprintf($image_tag, $skin_path, $attrib['attachmenticon'], '') : '')."</td>\n";
186  $out .= "</tr></thead>\n<tbody>\n";
187
188  // no messages in this mailbox
189  if (!sizeof($a_headers))
190    $OUTPUT->show_message('nomessagesfound', 'notice');
191
192
193  $a_js_message_arr = array();
194
195  // create row for each message
196  foreach ($a_headers as $i => $header)  //while (list($i, $header) = each($a_headers))
197    {
198    $message_icon = $attach_icon = $flagged_icon = '';
199    $js_row_arr = array();
200    $zebra_class = $i%2 ? 'even' : 'odd';
201
202    // set messag attributes to javascript array
203    if ($header->deleted)
204      $js_row_arr['deleted'] = true;
205    if (!$header->seen)
206      $js_row_arr['unread'] = true;
207    if ($header->answered)
208      $js_row_arr['replied'] = true;
209    if ($header->flagged)
210      $js_row_arr['flagged'] = true;
211
212    // set message icon 
213    if ($attrib['deletedicon'] && $header->deleted)
214      $message_icon = $attrib['deletedicon'];
215    else if ($attrib['unreadicon'] && !$header->seen)
216      $message_icon = $attrib['unreadicon'];
217    else if ($attrib['repliedicon'] && $header->answered)
218      $message_icon = $attrib['repliedicon'];
219    else if ($attrib['messageicon'])
220      $message_icon = $attrib['messageicon'];
221
222    if ($attrib['flaggedicon'] && $header->flagged)
223      $flagged_icon = $attrib['flaggedicon'];
224    else if ($attrib['unflaggedicon'] && !$header->flagged)
225      $flagged_icon = $attrib['unflaggedicon'];
226   
227    // set attachment icon
228    if ($attrib['attachmenticon'] && preg_match("/multipart\/[mr]/i", $header->ctype))
229      $attach_icon = $attrib['attachmenticon'];
230       
231    $out .= sprintf('<tr id="rcmrow%d" class="message%s%s %s">'."\n",
232                    $header->uid,
233                    $header->seen ? '' : ' unread',
234                    $header->deleted ? ' deleted' : '',
235                    $header->flagged ? ' flagged' : '',
236                    $zebra_class);   
237   
238    $out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : '');
239
240
241    if (!empty($header->charset))
242      $IMAP->set_charset($header->charset);
243 
244    // format each col
245    foreach ($a_show_cols as $col)
246      {
247      if ($col=='from' || $col=='to')
248        $cont = Q(rcmail_address_string($header->$col, 3, false, $attrib['addicon']), 'show');
249      else if ($col=='subject')
250        {
251        $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show';
252        $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid';
253        $cont = Q($IMAP->decode_header($header->$col));
254        if (empty($cont)) $cont = Q(rcube_label('nosubject'));
255        $cont = sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), $cont);
256        }
257      else if ($col=='flag')
258        $cont = $flagged_icon ? sprintf($image_tag, $skin_path, $flagged_icon, '') : '';
259      else if ($col=='size')
260        $cont = show_bytes($header->$col);
261      else if ($col=='date')
262        $cont = format_date($header->date);
263      else
264        $cont = Q($header->$col);
265       
266      $out .= '<td class="'.$col.'">' . $cont . "</td>\n";
267      }
268
269    $out .= sprintf("<td class=\"icon\">%s</td>\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : '');
270    $out .= "</tr>\n";
271   
272    if (sizeof($js_row_arr))
273      $a_js_message_arr[$header->uid] = $js_row_arr;
274    }
275 
276  // complete message table
277  $out .= "</tbody></table>\n";
278 
279 
280  $message_count = $IMAP->messagecount();
281 
282  // set client env
283  $OUTPUT->add_gui_object('mailcontframe', 'mailcontframe');
284  $OUTPUT->add_gui_object('messagelist', $attrib['id']);
285  $OUTPUT->set_env('messagecount', $message_count);
286  $OUTPUT->set_env('current_page', $IMAP->list_page);
287  $OUTPUT->set_env('pagecount', ceil($message_count/$IMAP->page_size));
288  $OUTPUT->set_env('sort_col', $sort_col);
289  $OUTPUT->set_env('sort_order', $sort_order);
290 
291  if ($attrib['messageicon'])
292    $OUTPUT->set_env('messageicon', $skin_path . $attrib['messageicon']);
293  if ($attrib['deletedicon'])
294    $OUTPUT->set_env('deletedicon', $skin_path . $attrib['deletedicon']);
295  if ($attrib['unreadicon'])
296    $OUTPUT->set_env('unreadicon', $skin_path . $attrib['unreadicon']);
297  if ($attrib['repliedicon'])
298    $OUTPUT->set_env('repliedicon', $skin_path . $attrib['repliedicon']);
299  if ($attrib['attachmenticon'])
300    $OUTPUT->set_env('attachmenticon', $skin_path . $attrib['attachmenticon']);
301  if ($attrib['flaggedicon'])
302    $OUTPUT->set_env('flaggedicon', $skin_path . $attrib['flaggedicon']);
303  if ($attrib['unflaggedicon'])
304    $OUTPUT->set_env('unflaggedicon', $skin_path . $attrib['unflaggedicon']);
305 
306  $OUTPUT->set_env('messages', $a_js_message_arr);
307  $OUTPUT->set_env('coltypes', $a_show_cols);
308 
309  $OUTPUT->include_script('list.js');
310 
311  return $out;
312  }
313
314
315/**
316 * return javascript commands to add rows to the message list
317 */
318function rcmail_js_message_list($a_headers, $insert_top=FALSE)
319  {
320  global $CONFIG, $IMAP, $OUTPUT;
321
322  $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
323  $mbox = $IMAP->get_mailbox_name();
324
325  // show 'to' instead of from in sent messages
326  if (($mbox == $CONFIG['sent_mbox'] || $mbox == $CONFIG['drafts_mbox'])
327      && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
328    $a_show_cols[$f] = 'to';
329
330  $OUTPUT->command('set_message_coltypes', $a_show_cols);
331
332  // loop through message headers
333  foreach ($a_headers as $n => $header)
334    {
335    $a_msg_cols = array();
336    $a_msg_flags = array();
337   
338    if (empty($header))
339      continue;
340
341    if (!empty($header->charset))
342      $IMAP->set_charset($header->charset);
343
344    // format each col; similar as in rcmail_message_list()
345    foreach ($a_show_cols as $col)
346      {
347      if ($col=='from' || $col=='to')
348        $cont = Q(rcmail_address_string($header->$col, 3), 'show');
349      else if ($col=='subject')
350        {
351        $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show';
352        $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid';
353        $cont = Q($IMAP->decode_header($header->$col));
354        if (!$cont) $cont = Q(rcube_label('nosubject'));
355        $cont = sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), $cont);
356        }
357      else if ($col=='size')
358        $cont = show_bytes($header->$col);
359      else if ($col=='date')
360        $cont = format_date($header->date);
361      else
362        $cont = Q($header->$col);
363         
364      $a_msg_cols[$col] = $cont;
365      }
366
367    $a_msg_flags['deleted'] = $header->deleted ? 1 : 0;
368    $a_msg_flags['unread'] = $header->seen ? 0 : 1;
369    $a_msg_flags['replied'] = $header->answered ? 1 : 0;
370    $a_msg_flags['flagged'] = $header->flagged ? 1 : 0;
371   
372    $OUTPUT->command('add_message_row',
373      $header->uid,
374      $a_msg_cols,
375      $a_msg_flags,
376      preg_match("/multipart\/m/i", $header->ctype),
377      $insert_top);
378    }
379  }
380
381
382/**
383 * return an HTML iframe for loading mail content
384 */
385function rcmail_messagecontent_frame($attrib)
386  {
387  global $OUTPUT;
388 
389  if (empty($attrib['id']))
390    $attrib['id'] = 'rcmailcontentwindow';
391
392  // allow the following attributes to be added to the <iframe> tag
393  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
394  $framename = $attrib['id'];
395
396  $out = sprintf('<iframe name="%s"%s></iframe>'."\n",
397         $framename,
398         $attrib_str);
399
400  $OUTPUT->set_env('contentframe', $framename);
401  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
402
403  return $out;
404  }
405
406
407/**
408 *
409 */
410function rcmail_messagecount_display($attrib)
411  {
412  global $IMAP, $OUTPUT;
413 
414  if (!$attrib['id'])
415    $attrib['id'] = 'rcmcountdisplay';
416
417  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
418
419  // allow the following attributes to be added to the <span> tag
420  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
421
422 
423  $out = '<span' . $attrib_str . '>';
424  $out .= rcmail_get_messagecount_text();
425  $out .= '</span>';
426  return $out;
427  }
428
429
430/**
431 *
432 */
433function rcmail_quota_display($attrib)
434  {
435  global $OUTPUT, $COMM_PATH;
436
437  if (!$attrib['id'])
438    $attrib['id'] = 'rcmquotadisplay';
439
440  if(isset($attrib['display']))
441    $_SESSION['quota_display'] = $attrib['display'];
442
443  $OUTPUT->add_gui_object('quotadisplay', $attrib['id']);
444
445  // allow the following attributes to be added to the <span> tag
446  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'display'));
447
448  $out = '<span' . $attrib_str . '>';
449  $out .= rcmail_quota_content(NULL, $attrib);
450  $out .= '</span>';
451  return $out;
452  }
453
454
455/**
456 *
457 */
458function rcmail_quota_content($quota=NULL, $attrib=NULL)
459  {
460  global $IMAP, $COMM_PATH, $RCMAIL;
461
462  $display = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';
463
464  if (is_array($quota) && !empty($quota['used']) && !empty($quota['total']))
465    {
466      if (!isset($quota['percent']))
467        $quota['percent'] = $quota['used'] / $quota['total'];
468    }
469  elseif (!$IMAP->get_capability('QUOTA'))
470    return rcube_label('unknown');
471  else
472    $quota = $IMAP->get_quota();
473
474  if ($quota && !($quota['total']==0 && $RCMAIL->config->get('quota_zero_as_unlimited')))
475    {
476    $quota_text = sprintf('%s / %s (%.0f%%)',
477                          show_bytes($quota['used'] * 1024),
478                          show_bytes($quota['total'] * 1024),
479                          $quota['percent']);
480
481    // show quota as image (by Brett Patterson)
482    if ($display == 'image' && function_exists('imagegif'))
483      {
484      if (!$attrib['width'])
485        $attrib['width'] = isset($_SESSION['quota_width']) ? $_SESSION['quota_width'] : 100;
486      else
487        $_SESSION['quota_width'] = $attrib['width'];
488
489      if (!$attrib['height'])
490        $attrib['height'] = isset($_SESSION['quota_height']) ? $_SESSION['quota_height'] : 14;
491      else
492        $_SESSION['quota_height'] = $attrib['height'];
493           
494      $quota_text = sprintf('<img src="./bin/quotaimg.php?u=%s&amp;q=%d&amp;w=%d&amp;h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />',
495                            $quota['used'], $quota['total'],
496                            $attrib['width'], $attrib['height'],
497                            $attrib['width'], $attrib['height'],
498                            $quota_text,
499                            show_bytes($quota['used'] * 1024),
500                            show_bytes($quota['total'] * 1024));
501      }
502    }
503  else
504    $quota_text = rcube_label('unlimited');
505
506  return $quota_text;
507  }
508
509
510/**
511 *
512 */
513function rcmail_get_messagecount_text($count=NULL, $page=NULL)
514  {
515  global $IMAP, $MESSAGE;
516 
517  if (isset($MESSAGE->index))
518    {
519    return rcube_label(array('name' => 'messagenrof',
520                             'vars' => array('nr'  => $MESSAGE->index+1,
521                                             'count' => $count!==NULL ? $count : $IMAP->messagecount())));
522    }
523
524  if ($page===NULL)
525    $page = $IMAP->list_page;
526   
527  $start_msg = ($page-1) * $IMAP->page_size + 1;
528  $max = $count!==NULL ? $count : $IMAP->messagecount();
529
530  if ($max==0)
531    $out = rcube_label('mailboxempty');
532  else
533    $out = rcube_label(array('name' => 'messagesfromto',
534                              'vars' => array('from'  => $start_msg,
535                                              'to'    => min($max, $start_msg + $IMAP->page_size - 1),
536                                              'count' => $max)));
537
538  return Q($out);
539  }
540
541/**
542 *
543 */
544function rcmail_mailbox_name_display($attrib)
545{
546    global $RCMAIL;
547
548    if (!$attrib['id'])
549        $attrib['id'] = 'rcmmailboxname';
550
551    $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']);
552
553    return html::span($attrib, rcmail_get_mailbox_name_text());
554}
555
556function rcmail_get_mailbox_name_text()
557{
558    global $RCMAIL;
559    return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name());
560}
561
562
563/**
564 * Convert the given message part to proper HTML
565 * which can be displayed the message view
566 *
567 * @param object rcube_message_part Message part
568 * @param bool  True if external objects (ie. images ) are allowed
569 * @param bool  True if part should be converted to plaintext
570 * @return string Formatted HTML string
571 */
572function rcmail_print_body($part, $p = array())
573{
574  global $REMOTE_OBJECTS;
575 
576  $p += array('safe' => false, 'plain' => false, 'inline_html' => true);
577 
578  // convert html to text/plain
579  if ($part->ctype_secondary == 'html' && $p['plain']) {
580    $txt = new html2text($part->body, false, true);
581    $body = $txt->get_text();
582    $part->ctype_secondary = 'plain';
583  }
584  // text/html
585  else if ($part->ctype_secondary == 'html') {
586    // charset was converted to UTF-8 in rcube_imap::get_message_part() -> change charset specification in HTML accordingly
587    $html = $part->body;
588    if (preg_match('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', $html))
589      $html = preg_replace('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', '\\1='.RCMAIL_CHARSET, $html);
590    else {
591      // add <head> for malformed messages, washtml cannot work without that
592      if (!preg_match('/<head>(.*)<\\/head>/Uims', $html))
593        $html = '<head></head>' . $html;
594      $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '</head>')), 0);
595    }
596
597    // PHP bug #32547 workaround: remove title tag
598    $html = preg_replace('/<title>.*<\/title>/', '', $html);
599
600    // clean HTML with washhtml by Frederic Motte
601    $wash_opts = array(
602      'show_washed' => false,
603      'allow_remote' => $p['safe'],
604      'blocked_src' => "./program/blocked.gif",
605      'charset' => RCMAIL_CHARSET,
606      'cid_map' => $part->replaces,
607      'html_elements' => array('body'),
608    );
609   
610    if (!$p['inline_html']) {
611      $wash_opts['html_elements'] = array('html','head','title','body');
612    }
613   
614    // allow CSS styles, will be sanitized by rcmail_washtml_callback()
615    if ($p['safe']) {
616      $wash_opts['html_elements'][] = 'style';
617    }
618   
619    $washer = new washtml($wash_opts);
620    $washer->add_callback('form', 'rcmail_washtml_callback');
621    $washer->add_callback('style', 'rcmail_washtml_callback');
622    $body = $washer->wash($html);
623    $REMOTE_OBJECTS = $washer->extlinks;
624
625    return $body;
626  }
627  // text/enriched
628  else if ($part->ctype_secondary=='enriched') {
629    $part->ctype_secondary = 'html';
630    return Q(enriched_to_html($part->body), 'show');
631  }
632  else
633    $body = $part->body;
634
635
636  /**** assert plaintext ****/
637
638  // make links and email-addresses clickable
639  $convert_patterns = $convert_replaces = $replace_strings = array();
640 
641  $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;';
642  $url_chars_within = '\?\.~,!';
643
644  $convert_patterns[] = "/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie";
645  $convert_replaces[] = "rcmail_str_replacement('<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>', \$replace_strings)";
646
647  $convert_patterns[] = "/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie";
648  $convert_replaces[] = "rcmail_str_replacement('\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>', \$replace_strings)";
649 
650  $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie';
651  $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return ".JS_OBJECT_NAME.".command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)";
652 
653  // search for patterns like links and e-mail addresses
654  $body = preg_replace($convert_patterns, $convert_replaces, $body);
655
656  // split body into single lines
657  $a_lines = preg_split('/\r?\n/', $body);
658  $quote_level = 0;
659
660  // colorize quoted parts
661  for ($n=0; $n < sizeof($a_lines); $n++) {
662    $line = $a_lines[$n];
663    $quotation = '';
664    $q = 0;
665   
666    if (preg_match('/^(>+\s*)+/', $line, $regs)) {
667      $q    = strlen(preg_replace('/\s/', '', $regs[0]));
668      $line = substr($line, strlen($regs[0]));
669
670      if ($q > $quote_level)
671        $quotation = str_repeat('<blockquote>', $q - $quote_level);
672      else if ($q < $quote_level)
673        $quotation = str_repeat("</blockquote>", $quote_level - $q);
674    }
675    else if ($quote_level > 0)
676      $quotation = str_repeat("</blockquote>", $quote_level);
677
678    $quote_level = $q;
679    $a_lines[$n] = $quotation . Q($line, 'replace', false);  // htmlquote plaintext
680  }
681
682  // insert the links for urls and mailtos
683  $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines));
684 
685  return "<div class=\"pre\">".$body."\n</div>";
686}
687
688/**
689 * add a string to the replacement array and return a replacement string
690 */
691function rcmail_str_replacement($str, &$rep)
692{
693  static $count = 0;
694  $rep[$count] = stripslashes($str);
695  return "##string_replacement{".($count++)."}##";
696}
697
698
699/**
700 * Callback function for washtml cleaning class
701 */
702function rcmail_washtml_callback($tagname, $attrib, $content)
703{
704  switch ($tagname) {
705    case 'form':
706      $out = html::div('form', $content);
707      break;
708     
709    case 'style':
710      // decode all escaped entities and reduce to ascii strings
711      $stripped = preg_replace('/[^a-zA-Z\(:]/', '', rcmail_xss_entitiy_decode($source));
712     
713      // now check for evli strings like expression, behavior or url()
714      if (!preg_match('/expression|behavior|url\(|import/', $css)) {
715        $out = html::tag('style', array('type' => 'text/css'), $content);
716        break;
717      }
718   
719    default:
720      $out = '';
721  }
722 
723  return $out;
724}
725
726
727/**
728 * return table with message headers
729 */
730function rcmail_message_headers($attrib, $headers=NULL)
731  {
732  global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $CONFIG;
733  static $sa_attrib;
734 
735  // keep header table attrib
736  if (is_array($attrib) && !$sa_attrib)
737    $sa_attrib = $attrib;
738  else if (!is_array($attrib) && is_array($sa_attrib))
739    $attrib = $sa_attrib;
740 
741 
742  if (!isset($MESSAGE))
743    return FALSE;
744
745  // get associative array of headers object
746  if (!$headers)
747    $headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers;
748   
749  // add empty subject if none exsists
750  if (empty($headers['subject']))
751    $headers['subject'] = rcube_label('nosubject');
752
753  $header_count = 0;
754 
755  // allow the following attributes to be added to the <table> tag
756  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
757  $out = '<table' . $attrib_str . ">\n";
758
759  // show these headers
760  $standard_headers = array('subject', 'from', 'organization', 'to', 'cc', 'bcc', 'replyto', 'date');
761
762  foreach ($standard_headers as $hkey)
763    {
764    if (!$headers[$hkey])
765      continue;
766
767    if ($hkey == 'date')
768      {
769      if ($PRINT_MODE)
770        $header_value = format_date($headers[$hkey], $CONFIG['date_long'] ? $CONFIG['date_long'] : 'x');
771      else
772        $header_value = format_date($headers[$hkey]);
773      }
774    else if ($hkey == 'replyto')
775      {
776      if ($headers['replyto'] != $headers['from'])
777        $header_value = Q(rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']), 'show');
778      else
779        continue;
780      }
781    else if ($hkey == 'to' && preg_match('/^undisclosed-recipients[:;]*$/', $headers['to']))
782      continue;
783    else if (in_array($hkey, array('from', 'to', 'cc', 'bcc')))
784      $header_value = Q(rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']), 'show');
785    else
786      $header_value = Q($IMAP->decode_header($headers[$hkey]));
787
788    $out .= "\n<tr>\n";
789    $out .= '<td class="header-title">'.Q(rcube_label($hkey)).":&nbsp;</td>\n";
790    $out .= '<td class="'.$hkey.'" width="90%">'.$header_value."</td>\n</tr>";
791    $header_count++;
792    }
793
794  // all headers division
795  $out .= "\n".'<tr><td colspan="2" class="more-headers show-headers"
796        onclick="return '.JS_OBJECT_NAME.'.command(\'load-headers\', \'\', this)"></td></tr>';
797  $out .= "\n".'<tr id="all-headers"><td colspan="2" class="all"><div id="headers-source"></div></td></tr>';
798
799  $OUTPUT->add_gui_object('all_headers_row', 'all-headers');
800  $OUTPUT->add_gui_object('all_headers_box', 'headers-source');
801
802  $out .= "\n</table>\n\n";
803
804  return $header_count ? $out : ''; 
805  }
806
807
808/**
809 * Handler for the 'messagebody' GUI object
810 *
811 * @param array Named parameters
812 * @return string HTML content showing the message body
813 */
814function rcmail_message_body($attrib)
815  {
816  global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $REMOTE_OBJECTS;
817
818  if (!is_array($MESSAGE->parts) && empty($MESSAGE->body))
819    return '';
820   
821  if (!$attrib['id'])
822    $attrib['id'] = 'rcmailMsgBody';
823
824  $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
825  $out = '';
826 
827  $header_attrib = array();
828  foreach ($attrib as $attr => $value)
829    if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs))
830      $header_attrib[$regs[1]] = $value;
831
832  if (!empty($MESSAGE->parts))
833    {
834    foreach ($MESSAGE->parts as $i => $part)
835      {
836      if ($part->type == 'headers')
837        $out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part->headers);
838      else if ($part->type == 'content')
839        {
840        if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset']))
841          $part->ctype_parameters['charset'] = $MESSAGE->headers->charset;
842
843        // fetch part if not available
844        if (!isset($part->body))
845          $part->body = $MESSAGE->get_part_content($part->mime_id);
846
847        $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html']));
848
849        if ($part->ctype_secondary == 'html')
850          $out .= html::div('message-htmlpart', rcmail_html4inline($body, $attrib['id']));
851        else
852          $out .= html::div('message-part', $body);
853        }
854      }
855    }
856  else
857    $out .= html::div('message-part', html::div('pre', Q($MESSAGE->body)));
858
859
860  $ctype_primary = strtolower($MESSAGE->structure->ctype_primary);
861  $ctype_secondary = strtolower($MESSAGE->structure->ctype_secondary);
862
863  // list images after mail body
864  if ($CONFIG['inline_images']
865      && $ctype_primary == 'multipart'
866      && !empty($MESSAGE->attachments)
867      && !strstr($message_body, '<html'))
868    {
869    foreach ($MESSAGE->attachments as $attach_prop) {
870      if (strpos($attach_prop->mimetype, 'image/') === 0) {
871        $out .= html::tag('hr') . html::p(array('align' => "center"),
872          html::img(array(
873            'src' => $MESSAGE->get_part_url($attach_prop->mime_id),
874            'title' => $attach_prop->filename,
875            'alt' => $attach_prop->filename,
876          )));
877        }
878    }
879  }
880 
881  // tell client that there are blocked remote objects
882  if ($REMOTE_OBJECTS && !$safe_mode)
883    $OUTPUT->set_env('blockedobjects', true);
884
885  return html::div($attrib, $out);
886  }
887
888
889
890/**
891 * modify a HTML message that it can be displayed inside a HTML page
892 */
893function rcmail_html4inline($body, $container_id)
894  {
895  $base_url = "";
896  $last_style_pos = 0;
897  $body_lc = strtolower($body);
898 
899  // check for <base href>
900  if (preg_match(($base_reg = '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i'), $body, $base_regs))
901    $base_url = $base_regs[2];
902 
903  // find STYLE tags
904  while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
905    {
906    $pos = strpos($body_lc, '>', $pos)+1;
907
908    // replace all css definitions with #container [def]
909    $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id, $base_url);
910
911    $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
912    $body_lc = strtolower($body);
913    $last_style_pos = $pos2;
914    }
915
916  // resolve <base href>
917  if ($base_url)
918    {
919    $body = preg_replace('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Uie', "'\\1=\"'.make_absolute_url('\\3', '$base_url').'\"'", $body);
920    $body = preg_replace('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Uie', "'\\1\''.make_absolute_url('\\3', '$base_url').'\')'", $body);
921    $body = preg_replace($base_reg, '', $body);
922    }
923   
924  // modify HTML links to open a new window if clicked
925  $body = preg_replace('/<(a|link)\s+([^>]+)>/Uie', "rcmail_alter_html_link('\\1','\\2', '$container_id');", $body);
926
927  // add comments arround html and other tags
928  $out = preg_replace(array(
929      '/(<!DOCTYPE[^>]*>)/i',
930      '/(<\?xml[^>]*>)/i',
931      '/(<\/?html[^>]*>)/i',
932      '/(<\/?head[^>]*>)/i',
933      '/(<title[^>]*>.*<\/title>)/Ui',
934      '/(<\/?meta[^>]*>)/i'),
935    '<!--\\1-->',
936    $body);
937
938  $out = preg_replace(
939    array('/<body([^>]*)>/i', '/<\/body>/i'),
940    array('<div class="rcmBody"\\1>', '</div>'),
941    $out);
942
943  // quote <? of php and xml files that are specified as text/html
944  $out = preg_replace(array('/<\?/', '/\?>/'), array('&lt;?', '?&gt;'), $out);
945
946  return $out;
947  }
948
949
950/**
951 * parse link attributes and set correct target
952 */
953function rcmail_alter_html_link($tag, $attrs, $container_id)
954  {
955  $attrib = parse_attrib_string($attrs);
956
957  if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href']))
958    $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&amp;c=" . urlencode($container_id);
959
960  else if (stristr((string)$attrib['href'], 'mailto:'))
961    $attrib['onclick'] = sprintf(
962      "return %s.command('compose','%s',this)",
963      JS_OBJECT_NAME,
964      JQ(substr($attrib['href'], 7)));
965
966  else if (!empty($attrib['href']) && $attrib['href']{0}!='#')
967    $attrib['target'] = '_blank';
968
969  return "<$tag" . create_attrib_string($attrib, array('href','name','target','onclick','id','class','style','title','rel','type','media')) . ' />';
970  }
971
972
973/**
974 * decode address string and re-format it as HTML links
975 */
976function rcmail_address_string($input, $max=null, $linked=false, $addicon=null)
977{
978  global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $EMAIL_ADDRESS_PATTERN;
979
980  $a_parts = $IMAP->decode_address_list($input);
981
982  if (!sizeof($a_parts))
983    return $input;
984
985  $c = count($a_parts);
986  $j = 0;
987  $out = '';
988
989  foreach ($a_parts as $part) {
990    $j++;
991    if ($PRINT_MODE) {
992      $out .= sprintf('%s &lt;%s&gt;', Q($part['name']), $part['mailto']);
993    }
994    else if (preg_match($EMAIL_ADDRESS_PATTERN, $part['mailto'])) {
995      if ($linked) {
996        $out .= html::a(array(
997            'href' => 'mailto:'.$part['mailto'],
998            'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($part['mailto'])),
999            'title' => $part['mailto'],
1000            'class' => "rcmContactAddress",
1001          ),
1002        Q($part['name']));
1003      }
1004      else {
1005        $out .= html::span(array('title' => $part['mailto'], 'class' => "rcmContactAddress"), Q($part['name']));
1006      }
1007
1008      if ($addicon) {
1009        $out .= '&nbsp;' . html::a(array(
1010            'href' => "#add",
1011            'onclick' => sprintf("return %s.command('add-contact','%s',this)", JS_OBJECT_NAME, urlencode($part['string'])),
1012            'title' => rcube_label('addtoaddressbook'),
1013          ),
1014          html::img(array(
1015            'src' => $CONFIG['skin_path'] . $addicon,
1016            'alt' => "Add contact",
1017            'border' => 0,
1018          )));
1019      }
1020    }
1021    else {
1022      if ($part['name'])
1023        $out .= Q($part['name']);
1024      if ($part['mailto'])
1025        $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', Q($part['mailto']));
1026    }
1027     
1028    if ($c>$j)
1029      $out .= ','.($max ? '&nbsp;' : ' ');
1030       
1031    if ($max && $j==$max && $c>$j) {
1032      $out .= '...';
1033      break;
1034    }
1035  }
1036   
1037  return $out;
1038}
1039
1040
1041/**
1042 * Wrap text to a given number of characters per line
1043 * but respect the mail quotation of replies messages (>)
1044 *
1045 * @param string Text to wrap
1046 * @param int The line width
1047 * @return string The wrapped text
1048 */
1049function rcmail_wrap_quoted($text, $max = 76)
1050{
1051  // Rebuild the message body with a maximum of $max chars, while keeping quoted message.
1052  $lines = preg_split('/\r?\n/', trim($text));
1053  $out = '';
1054
1055  foreach ($lines as $line) {
1056    if (strlen($line) > $max) {
1057      if (preg_match('/^([>\s]+)/', $line, $regs)) {
1058        $length = strlen($regs[0]);
1059        $prefix = substr($line, 0, $length);
1060
1061        // Remove '> ' from the line, then wordwrap() the line
1062        $line = wordwrap(substr($line, $length), $max - $length);
1063
1064        // Rebuild the line with '> ' at the beginning of each 'subline'
1065        $newline = '';
1066        foreach (explode("\n", $line) as $l) {
1067          $newline .= $prefix . $l . "\n";
1068        }
1069
1070        // Remove the righest newline char
1071        $line = rtrim($newline);
1072      }
1073      else {
1074        $line = wordwrap($line, $max);
1075      }
1076    }
1077
1078    // Append the line
1079    $out .= $line . "\n";
1080  }
1081 
1082  return $out;
1083}
1084
1085
1086function rcmail_message_part_controls()
1087  {
1088  global $MESSAGE;
1089 
1090  $part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC));
1091  if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part])
1092    return '';
1093   
1094  $part = $MESSAGE->mime_parts[$part];
1095  $table = new html_table(array('cols' => 3));
1096 
1097  if (!empty($part->filename)) {
1098    $table->add('title', Q(rcube_label('filename')));
1099    $table->add(null, Q($part->filename));
1100    $table->add(null, '[' . html::a('?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q(rcube_label('download'))) . ']');
1101  }
1102 
1103  if (!empty($part->size)) {
1104    $table->add('title', Q(rcube_label('filesize')));
1105    $table->add(null, Q(show_bytes($part->size)));
1106  }
1107 
1108  return $table->show($attrib);
1109  }
1110
1111
1112
1113function rcmail_message_part_frame($attrib)
1114  {
1115  global $MESSAGE;
1116 
1117  $part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))];
1118  $ctype_primary = strtolower($part->ctype_primary);
1119
1120  $attrib['src'] = Q('./?'.str_replace('_frame=', ($ctype_primary=='text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']));
1121
1122  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'src', 'width', 'height'));
1123  $out = '<iframe '. $attrib_str . "></iframe>";
1124   
1125  return $out;
1126  }
1127
1128
1129/**
1130 * clear message composing settings
1131 */
1132function rcmail_compose_cleanup()
1133  {
1134  if (!isset($_SESSION['compose']))
1135    return;
1136
1137  // remove attachment files from temp dir
1138  if (is_array($_SESSION['compose']['attachments']))
1139    foreach ($_SESSION['compose']['attachments'] as $attachment)
1140      @unlink($attachment['path']);
1141 
1142  unset($_SESSION['compose']);
1143  }
1144 
1145
1146/**
1147 * Send the given message compose object using the configured method
1148 */
1149function rcmail_deliver_message(&$message, $from, $mailto)
1150{
1151  global $CONFIG;
1152
1153  $msg_body = $message->get();
1154  $headers = $message->headers();
1155
1156  // send thru SMTP server using custom SMTP library
1157  if ($CONFIG['smtp_server'])
1158    {
1159    // generate list of recipients
1160    $a_recipients = array($mailto);
1161 
1162    if (strlen($headers['Cc']))
1163      $a_recipients[] = $headers['Cc'];
1164    if (strlen($headers['Bcc']))
1165      $a_recipients[] = $headers['Bcc'];
1166 
1167    // clean Bcc from header for recipients
1168    $send_headers = $headers;
1169    unset($send_headers['Bcc']);
1170    // here too, it because txtHeaders() below use $message->_headers not only $send_headers
1171    unset($message->_headers['Bcc']);
1172
1173    // send message
1174    $smtp_response = array();
1175    $sent = smtp_mail($from, $a_recipients, ($foo = $message->txtHeaders($send_headers, true)), $msg_body, $smtp_response);
1176
1177    // log error
1178    if (!$sent)
1179      raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__,
1180                        'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE);
1181    }
1182 
1183  // send mail using PHP's mail() function
1184  else
1185    {
1186    // unset some headers because they will be added by the mail() function
1187    $headers_enc = $message->headers($headers);
1188    $headers_php = $message->_headers;
1189    unset($headers_php['To'], $headers_php['Subject']);
1190   
1191    // reset stored headers and overwrite
1192    $message->_headers = array();
1193    $header_str = $message->txtHeaders($headers_php);
1194 
1195    if (ini_get('safe_mode'))
1196      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str);
1197    else
1198      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
1199    }
1200 
1201  if ($sent)
1202  {
1203    // remove MDN headers after sending
1204    unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']);
1205   
1206    if ($CONFIG['smtp_log'])
1207      write_log('sendmail', sprintf("[%s] User: %d on %s; Message for %s; %s",
1208                date("d-M-Y H:i:s O", mktime()),
1209                $_SESSION['user_id'],
1210                $_SERVER['REMOTE_ADDR'],
1211                $mailto,
1212                !empty($smtp_response) ? join('; ', $smtp_response) : ''));
1213  }
1214 
1215  $message->_headers = array();
1216  $message->headers($headers);
1217 
1218  return $sent;
1219}
1220
1221
1222function rcmail_send_mdn($uid)
1223{
1224  global $RCMAIL, $IMAP;
1225
1226  $message = new rcube_message($uid);
1227 
1228  if ($message->headers->mdn_to && !$message->headers->mdn_sent && $IMAP->check_permflag('MDNSENT'))
1229  {
1230    $identity = $RCMAIL->user->get_identity();
1231    $sender = format_email_recipient($identity['email'], $identity['name']);
1232    $recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to));
1233    $mailto = $recipient['mailto'];
1234
1235    $compose = new rcube_mail_mime($RCMAIL->config->header_delimiter());
1236    $compose->setParam(array(
1237      'text_encoding' => 'quoted-printable',
1238      'html_encoding' => 'quoted-printable',
1239      'head_encoding' => 'quoted-printable',
1240      'head_charset'  => RCMAIL_CHARSET,
1241      'html_charset'  => RCMAIL_CHARSET,
1242      'text_charset'  => RCMAIL_CHARSET,
1243    ));
1244   
1245    // compose headers array
1246    $headers = array(
1247      'Date' => date('r'),
1248      'From' => $sender,
1249      'To'   => $message->headers->mdn_to,
1250      'Subject' => rcube_label('receiptread') . ': ' . $message->subject,
1251      'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])),
1252      'X-Sender' => $identity['email'],
1253      'Content-Type' => 'multipart/report; report-type=disposition-notification',
1254    );
1255   
1256    if ($agent = $RCMAIL->config->get('useragent'))
1257      $headers['User-Agent'] = $agent;
1258
1259    $body = rcube_label("yourmessage") . "\r\n\r\n" .
1260      "\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" .
1261      "\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" .
1262      "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" .
1263      "\r\n" . rcube_label("receiptnote") . "\r\n";
1264   
1265    $ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")");
1266    $report = "Reporting-UA: $ua\r\n";
1267   
1268    if ($message->headers->to)
1269        $report .= "Original-Recipient: {$message->headers->to}\r\n";
1270   
1271    $report .= "Final-Recipient: rfc822; {$identity['email']}\r\n" .
1272               "Original-Message-ID: {$message->headers->messageID}\r\n" .
1273               "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
1274   
1275    $compose->headers($headers);
1276    $compose->setTXTBody(wordwrap($body, 75, "\r\n"));
1277    $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline');
1278
1279    $sent = rcmail_deliver_message($compose, $identity['email'], $mailto);
1280
1281    if ($sent)
1282    {
1283      $IMAP->set_flag($message->uid, 'MDNSENT');
1284      return true;
1285    }
1286  }
1287 
1288  return false;
1289}
1290
1291
1292// register UI objects
1293$OUTPUT->add_handlers(array(
1294  'mailboxlist' => 'rcmail_mailbox_list',
1295  'messages' => 'rcmail_message_list',
1296  'messagecountdisplay' => 'rcmail_messagecount_display',
1297  'quotadisplay' => 'rcmail_quota_display',
1298  'mailboxname' => 'rcmail_mailbox_name_display',
1299  'messageheaders' => 'rcmail_message_headers',
1300  'messagebody' => 'rcmail_message_body',
1301  'messagecontentframe' => 'rcmail_messagecontent_frame',
1302  'messagepartframe' => 'rcmail_message_part_frame',
1303  'messagepartcontrols' => 'rcmail_message_part_controls',
1304  'searchform' => array($OUTPUT, 'search_form'),
1305));
1306
1307?>
Note: See TracBrowser for help on using the repository browser.