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