source: github/program/steps/mail/func.inc @ 09941ea

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 09941ea was 09941ea, checked in by thomascube <thomas@…>, 8 years ago

Some error messages added

  • Property mode set to 100644
File size: 42.7 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, 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/html2text.inc');
23require_once('lib/enriched.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
28// set imap properties and session vars
29if (strlen($_GET['_mbox']))
30  {
31  $IMAP->set_mailbox($_GET['_mbox']);
32  $_SESSION['mbox'] = $_GET['_mbox'];
33  }
34
35if (strlen($_GET['_page']))
36  {
37  $IMAP->set_page($_GET['_page']);
38  $_SESSION['page'] = $_GET['_page'];
39  }
40
41
42// define url for getting message parts
43if (strlen($_GET['_uid']))
44  $GET_URL = sprintf('%s&_action=get&_mbox=%s&_uid=%d', $COMM_PATH, $IMAP->get_mailbox_name(), $_GET['_uid']);
45
46
47// set current mailbox in client environment
48$OUTPUT->add_script(sprintf("%s.set_env('mailbox', '%s');", $JS_OBJECT_NAME, $IMAP->get_mailbox_name()));
49
50
51if ($CONFIG['trash_mbox'])
52  $OUTPUT->add_script(sprintf("%s.set_env('trash_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['trash_mbox']));
53
54
55
56// return the mailboxlist in HTML
57function rcmail_mailbox_list($attrib)
58  {
59  global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
60  static $s_added_script = FALSE;
61  static $a_mailboxes;
62 
63  $type = $attrib['type'] ? $attrib['type'] : 'ul';
64  $add_attrib = $type=='select' ? array('style', 'class', 'id', 'name', 'onchange') :
65                                  array('style', 'class', 'id');
66                                 
67  if ($type=='ul' && !$attrib['id'])
68    $attrib['id'] = 'rcmboxlist';
69
70  // allow the following attributes to be added to the <ul> tag
71  $attrib_str = create_attrib_string($attrib, $add_attrib);
72 
73  $out = '<' . $type . $attrib_str . ">\n";
74 
75  // add no-selection option
76  if ($type=='select' && $attrib['noselection'])
77    $out .= sprintf('<option value="0">%s</option>'."\n",
78                    rcube_label($attrib['noselection']));
79 
80  // get mailbox list
81  $mbox = $IMAP->get_mailbox_name();
82 
83  // for these mailboxes we have localized labels
84  $special_mailboxes = array('inbox', 'sent', 'drafts', 'trash', 'junk');
85
86
87  // build the folders tree
88  if (empty($a_mailboxes))
89    {
90    // get mailbox list
91    $a_folders = $IMAP->list_mailboxes();
92    $delimiter = $IMAP->get_hierarchy_delimiter();
93    $a_mailboxes = array();
94   
95    foreach ($a_folders as $folder)
96      rcmail_build_folder_tree($a_mailboxes, $folder, $delimiter);
97    }
98
99// var_dump($a_mailboxes);
100
101  if ($type=='select')
102    $out .= rcmail_render_folder_tree_select($a_mailboxes, $special_mailboxes, $mbox);
103   else
104    $out .= rcmail_render_folder_tree_html($a_mailboxes, $special_mailboxes, $mbox);
105
106
107/*
108  foreach ($a_folders as $i => $folder)
109    {
110    $zebra_class = $i%2 ? 'even' : 'odd';
111    $folder_prop = $a_subfolders[$folder];
112    $foldername = isset($folder_prop) ? $folder_prop['name'] : $folder;
113
114    $folder_lc = strtolower($foldername);
115    if (in_array($folder_lc, $special_mailboxes))
116      $foldername = rcube_label($folder_lc);
117       
118    if ($unread_count = $IMAP->messagecount($folder, 'UNSEEN'))
119      $foldername .= sprintf(' (%d)', $unread_count);
120
121    $indent = isset($folder_prop) ? sprintf(' indent%d', $folder_prop['level']) : '';
122    $indent_str = isset($folder_prop) ? str_repeat('&nbsp;&nbsp;', (int)$folder_prop['level']) : '';
123 
124    // compose mailbox line
125    if ($type=='select')
126      $out .= sprintf('<option value="%s">%s%s</option>'."\n",
127                      $folder,
128                      $indent_str,
129                      rep_specialchars_output($foldername));
130   
131    else
132      $out .= sprintf('<li class="mailbox %s %s%s%s%s"><a href="#%s" onclick="return %s.command(\'list\',\'%s\')" onmouseup="return %s.mbox_mouse_up(\'%s\')">%s</a></li>'."\n",
133                       preg_replace('/[^a-z0-9\-_]/', '', strtolower($folder)),
134                       $zebra_class,
135                       $unread_count ? ' unread' : '',
136                       $folder==$mbox ? ' selected' : '',
137                       $indent,
138                       $folder,
139                       $JS_OBJECT_NAME,
140                       $folder,
141                       $JS_OBJECT_NAME,
142                       $folder,
143                       rep_specialchars_output($foldername));
144    }
145*/
146
147  if ($type=='ul')
148    $OUTPUT->add_script(sprintf("%s.gui_object('mailboxlist', '%s');", $JS_OBJECT_NAME, $attrib['id']));
149
150
151/*  this is added further up
152  if (!$s_added_script)
153    {
154    $javascript .= sprintf("%s.set_env('mailbox', '%s');", $JS_OBJECT_NAME, $mbox);
155    $OUTPUT->add_script($javascript);
156    $s_added_script = TRUE;
157    }
158*/
159  return $out . "</$type>";
160  }
161
162
163
164
165// create a hierarchical array of the mailbox list
166function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='')
167  {
168  $pos = strpos($folder, $delm);
169  if ($pos !== false)
170    {
171    $subFolders = substr($folder, $pos+1);
172    $currentFolder = substr($folder, 0, $pos);
173    }
174  else
175    {
176    $subFolders = false;
177    $currentFolder = $folder;
178    }
179
180  $path .= $currentFolder;
181
182  if (!isset($arrFolders[$currentFolder]))
183    {
184    $arrFolders[$currentFolder] = array('id' => $path,
185                                        'name' => $currentFolder,
186                                        'folders' => array());
187    }
188
189  if (!empty($subFolders))
190    rcmail_build_folder_tree($arrFolders[$currentFolder]['folders'], $subFolders, $delm, $path.$delm);
191  }
192 
193
194// return html for a structured list <ul> for the mailbox tree
195function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox, $nestLevel = 0)
196  {
197  global $JS_OBJECT_NAME, $IMAP;
198
199  $idx = 0;
200  $out = '';
201  foreach ($arrFolders as $key => $folder)
202    {
203    $zebra_class = ($nestLevel*$idx)%2 ? 'even' : 'odd';
204
205    $folder_lc = strtolower($folder['id']);
206    if (in_array($folder_lc, $special))
207      $foldername = rcube_label($folder_lc);
208    else
209      $foldername = $folder['name'];
210
211    if ($unread_count = $IMAP->messagecount($folder['id'], 'UNSEEN'))
212      $foldername .= sprintf(' (%d)', $unread_count);
213
214    $out .= sprintf('<li class="mailbox %s %s%s%s"><a href="#%s" onclick="return %s.command(\'list\',\'%s\')" onmouseup="return %s.mbox_mouse_up(\'%s\')">%s</a>'."\n",
215                    preg_replace('/[^a-z0-9\-_]/', '', $folder_lc),
216                    $zebra_class,
217                    $unread_count ? ' unread' : '',
218                    $folder['id']==$mbox ? ' selected' : '',
219                    $folder['id'],
220                    $JS_OBJECT_NAME,
221                    $folder['id'],
222                    $JS_OBJECT_NAME,
223                    $folder['id'],
224                    rep_specialchars_output($foldername));
225
226    if (!empty($folder['folders']))
227      $out .= '<ul>' . rcmail_render_folder_tree_html($folder['folders'], $special, $mbox, $nestLevel+1) . "</ul>\n";
228
229    $out .= "</li>\n";
230    $idx++;
231    }
232
233  return $out;
234  }
235
236
237// return html for a flat list <select> for the mailbox tree
238function rcmail_render_folder_tree_select(&$arrFolders, &$special, &$mbox, $nestLevel=0)
239  {
240  global $IMAP;
241
242  $idx = 0;
243  $out = '';
244  foreach ($arrFolders as $key=>$folder)
245    {
246    $out .= sprintf('<option value="%s">%s%s</option>'."\n",
247                    $folder['id'],
248                    str_repeat('&nbsp;', $nestLevel*4),
249                    rep_specialchars_output($folder['name']));
250
251    if (!empty($folder['folders']))
252      $out .= rcmail_render_folder_tree_select($folder['folders'], $special, $mbox, $nestLevel+1);
253
254    $idx++;
255    }
256
257  return $out;
258  }
259
260
261// return the message list as HTML table
262function rcmail_message_list($attrib)
263  {
264  global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT, $JS_OBJECT_NAME;
265 
266  $skin_path = $CONFIG['skin_path'];
267  $image_tag = '<img src="%s%s" alt="%s" border="0" />';
268 
269  // get message headers
270  $a_headers = $IMAP->list_headers();
271
272  // add id to message list table if not specified
273  if (!strlen($attrib['id']))
274    $attrib['id'] = 'rcubemessagelist';
275
276  // allow the following attributes to be added to the <table> tag
277  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
278
279  $out = '<table' . $attrib_str . ">\n";
280 
281  // define list of cols to be displayed
282  $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
283 
284  // show 'to' instead of from in sent messages
285  if (strtolower($IMAP->get_mailbox_name())=='sent' && ($f = array_search('from', $a_show_cols)))
286    $a_show_cols[$f] = 'to';
287
288
289  // add table title
290  $out .= "<thead><tr>\n<td class=\"icon\">&nbsp;</td>\n";
291 
292  foreach ($a_show_cols as $col)
293    $out .= '<td class="'.$col.'">' . rcube_label($col) . "</td>\n";
294
295  $out .= '<td class="icon">'.($attrib['attachmenticon'] ? sprintf($image_tag, $skin_path, $attrib['attachmenticon'], '') : '')."</td>\n";
296  $out .= "</tr></thead>\n<tbody>\n";
297
298
299  // no messages in this mailbox
300  if (!sizeof($a_headers))
301    {
302    $out .= sprintf('<tr><td colspan="%d">%s</td></tr>',
303                   sizeof($a_show_cols)+2,
304                   rcube_label('nomessagesfound'));
305    }
306
307
308  $a_js_message_arr = array();
309
310  // create row for each message
311  foreach ($a_headers as $i => $header)  //while (list($i, $header) = each($a_headers))
312    {
313    $message_icon = $attach_icon = '';
314    $js_row_arr = array();
315    $zebra_class = $i%2 ? 'even' : 'odd';
316
317    // set messag attributes to javascript array
318    if (!$header->seen)
319      $js_row_arr['unread'] = true;
320    if ($header->answered)
321      $js_row_arr['replied'] = true;
322
323        // set message icon   
324    if ($attrib['unreadicon'] && !$header->seen)
325      $message_icon = $attrib['unreadicon'];
326    else if ($attrib['repliedicon'] && $header->answered)
327      $message_icon = $attrib['repliedicon'];
328    else if ($attrib['messageicon'])
329      $message_icon = $attrib['messageicon'];
330   
331        // set attachment icon
332    if ($attrib['attachmenticon'] && preg_match("/multipart\/m/i", $header->ctype))
333      $attach_icon = $attrib['attachmenticon'];
334       
335    $out .= sprintf('<tr id="rcmrow%d" class="message'.($header->seen ? '' : ' unread').' '.$zebra_class.'">'."\n", $header->uid);
336    $out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : '');
337       
338    // format each col
339    foreach ($a_show_cols as $col)
340      {
341      if ($col=='from' || $col=='to')
342        $cont = rep_specialchars_output(rcmail_address_string($header->$col, 3, $attrib['addicon']));
343      else if ($col=='subject')
344        $cont = rep_specialchars_output($IMAP->decode_header($header->$col));
345      else if ($col=='size')
346        $cont = show_bytes($header->$col);
347      else if ($col=='date')
348        $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date));
349      else
350        $cont = rep_specialchars_output($header->$col);
351       
352          $out .= '<td class="'.$col.'">' . $cont . "</td>\n";
353      }
354
355    $out .= sprintf("<td class=\"icon\">%s</td>\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : '');
356    $out .= "</tr>\n";
357   
358    if (sizeof($js_row_arr))
359      $a_js_message_arr[$header->uid] = $js_row_arr;
360    }
361 
362  // complete message table
363  $out .= "</tbody></table>\n";
364 
365 
366  $message_count = $IMAP->messagecount();
367 
368  // set client env
369  $javascript = sprintf("%s.gui_object('messagelist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']);
370  $javascript .= sprintf("%s.set_env('messagecount', %d);\n", $JS_OBJECT_NAME, $message_count);
371  $javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $IMAP->list_page);
372  $javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($message_count/$IMAP->page_size));
373 
374  if ($attrib['messageicon'])
375    $javascript .= sprintf("%s.set_env('messageicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['messageicon']);
376  if ($attrib['unreadicon'])
377    $javascript .= sprintf("%s.set_env('unreadicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['unreadicon']);
378  if ($attrib['repliedicon'])
379    $javascript .= sprintf("%s.set_env('repliedicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['repliedicon']);
380  if ($attrib['attachmenticon'])
381    $javascript .= sprintf("%s.set_env('attachmenticon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['attachmenticon']);
382   
383  $javascript .= sprintf("%s.set_env('messages', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr));
384 
385  $OUTPUT->add_script($javascript); 
386 
387  return $out;
388  }
389
390
391
392
393// return javascript commands to add rows to the message list
394function rcmail_js_message_list($a_headers, $insert_top=FALSE)
395  {
396  global $CONFIG, $IMAP;
397
398  $commands = '';
399  $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
400
401  // show 'to' instead of from in sent messages
402  if (strtolower($IMAP->get_mailbox_name())=='sent' && ($f = array_search('from', $a_show_cols)))
403    $a_show_cols[$f] = 'to';
404
405  // loop through message headers
406  for ($n=0; $a_headers[$n]; $n++)
407    {
408    $header = $a_headers[$n];
409    $a_msg_cols = array();
410    $a_msg_flags = array();
411     
412    // format each col; similar as in rcmail_message_list()
413    foreach ($a_show_cols as $col)
414      {
415      if ($col=='from' || $col=='to')
416        $cont = rep_specialchars_output(rcmail_address_string($header->$col, 3));
417      else if ($col=='subject')
418        $cont = rep_specialchars_output($IMAP->decode_header($header->$col));
419      else if ($col=='size')
420        $cont = show_bytes($header->$col);
421      else if ($col=='date')
422        $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date));
423      else
424        $cont = rep_specialchars_output($header->$col);
425         
426      $a_msg_cols[$col] = $cont;
427      }
428
429    $a_msg_flags['unread'] = $header->seen ? 0 : 1;
430    $a_msg_flags['replied'] = $header->answered ? 1 : 0;
431 
432    $commands .= sprintf("this.add_message_row(%s, %s, %s, %b);\n",
433                         $header->uid,
434                         array2js($a_msg_cols),
435                         array2js($a_msg_flags),
436                         preg_match("/multipart\/m/i", $header->ctype));
437    }
438
439  return $commands;
440  }
441
442
443
444function rcmail_messagecount_display($attrib)
445  {
446  global $IMAP, $OUTPUT, $JS_OBJECT_NAME;
447 
448  if (!$attrib['id'])
449    $attrib['id'] = 'rcmcountdisplay';
450
451  $OUTPUT->add_script(sprintf("%s.gui_object('countdisplay', '%s');", $JS_OBJECT_NAME, $attrib['id']));
452
453  // allow the following attributes to be added to the <span> tag
454  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
455
456 
457  $out = '<span' . $attrib_str . '>';
458  $out .= rcmail_get_messagecount_text();
459  $out .= '</span>';
460  return $out;
461  }
462
463
464
465function rcmail_get_messagecount_text()
466  {
467  global $IMAP, $MESSAGE;
468 
469  if (isset($MESSAGE['index']))
470    {
471    $a_msg_index = $IMAP->message_index();
472    return rcube_label(array('name' => 'messagenrof',
473                             'vars' => array('nr'  => $MESSAGE['index']+1,
474                                             'count' => sizeof($a_msg_index))));
475    }
476 
477  $start_msg = ($IMAP->list_page-1) * $IMAP->page_size + 1;
478  $max = $IMAP->messagecount();
479
480  if ($max==0)
481    $out = rcube_label('mailboxempty');
482  else
483    $out = rcube_label(array('name' => 'messagesfromto',
484                              'vars' => array('from'  => $start_msg,
485                                              'to'    => min($max, $start_msg + $IMAP->page_size - 1),
486                                              'count' => $max)));
487
488  return $out;
489  }
490
491
492function rcmail_print_body($part, $safe=FALSE, $plain=FALSE) // $body, $ctype_primary='text', $ctype_secondary='plain', $encoding='7bit', $safe=FALSE, $plain=FALSE)
493  {
494  global $IMAP, $REMOTE_OBJECTS, $JS_OBJECT_NAME;
495
496  // extract part properties: body, ctype_primary, ctype_secondary, encoding, parameters
497  extract($part);
498 
499  $block = $plain ? '%s' : '%s'; //'<div style="display:block;">%s</div>';
500  $body = $IMAP->mime_decode($body, $encoding);
501  $body = $IMAP->charset_decode($body, $parameters);
502
503
504  // text/html
505  if ($ctype_secondary=='html')
506    {
507    if (!$safe)  // remove remote images and scripts
508      {
509      $remote_patterns = array('/(src|background)=(["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)(\2|\s|>)/Ui',
510                           //  '/(src|background)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Ui',
511                               '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i',
512                               '/(<link.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i',
513                               '/url\s*\(["\']?([hftps]{3,5}:\/{2}[^"\'\s]+)["\']?\)/i',
514                               '/url\s*\(["\']?([\.\/]+[^"\'\s]+)["\']?\)/i',
515                               '/<script.+<\/script>/Umis');
516
517      $remote_replaces = array('\\1=\\2#\\4',
518                            // '\\1=\\2#\\4',
519                               '',
520                               '\\1#\\3',
521                               'none',
522                               'none',
523                               '');
524     
525      // set flag if message containes remote obejcts that where blocked
526      foreach ($remote_patterns as $pattern)
527        {
528        if (preg_match($pattern, $body))
529          {
530          $REMOTE_OBJECTS = TRUE;
531          break;
532          }
533        }
534
535      $body = preg_replace($remote_patterns, $remote_replaces, $body);
536      }
537
538    return sprintf($block, rep_specialchars_output($body, 'html', '', FALSE));
539    }
540
541  // text/enriched
542  if ($ctype_secondary=='enriched')
543    {
544    $body = enriched_to_html($body);
545    return sprintf($block, rep_specialchars_output($body, 'html'));
546    }
547  else
548    {
549    // make links and email-addresses clickable
550    $convert_patterns = $convert_replaces = $replace_strings = array();
551   
552    $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:';
553    $url_chars_within = '\?\.~,!';
554
555    $convert_patterns[] = "/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie";
556    $convert_replaces[] = "rcmail_str_replacement('<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>', \$replace_strings)";
557
558    $convert_patterns[] = "/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie";
559    $convert_replaces[] = "rcmail_str_replacement('\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>', \$replace_strings)";
560   
561    $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie';
562    $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return $JS_OBJECT_NAME.command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)";
563
564    $body = wordwrap(trim($body), 80);
565    $body = preg_replace($convert_patterns, $convert_replaces, $body);
566
567    // split body into single lines
568    $a_lines = preg_split('/\r?\n/', $body);
569
570    // colorize quoted parts
571    for($n=0; $n<sizeof($a_lines); $n++)
572      {
573      $line = $a_lines[$n];
574
575      if ($line{2}=='>')
576        $color = 'red';
577      else if ($line{1}=='>')
578        $color = 'green';
579      else if ($line{0}=='>')
580        $color = 'blue';
581      else
582        $color = FALSE;
583
584      $line = rep_specialchars_output($line, 'html', 'replace', FALSE);
585       
586      if ($color)
587        $a_lines[$n] = sprintf('<font color="%s">%s</font>', $color, $line);
588      else
589        $a_lines[$n] = $line;
590      }
591
592    // insert the links for urls and mailtos
593    $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines));
594   
595    return sprintf($block, "<pre>\n".$body."\n</pre>");
596    }
597  }
598
599
600
601// add a string to the replacement array and return a replacement string
602function rcmail_str_replacement($str, &$rep)
603  {
604  static $count = 0;
605  $rep[$count] = stripslashes($str);
606  return "##string_replacement{".($count++)."}##";
607  }
608
609
610function rcmail_parse_message($structure, $arg=array(), $recursive=FALSE)
611  {
612  global $IMAP;
613  static $sa_inline_objects = array();
614
615  // arguments are: (bool)$prefer_html, (string)$get_url
616  extract($arg);
617
618  $a_attachments = array();
619  $a_return_parts = array();
620  $out = '';
621
622  $message_ctype_primary = strtolower($structure->ctype_primary);
623  $message_ctype_secondary = strtolower($structure->ctype_secondary);
624
625  // show message headers
626  if ($recursive && is_array($structure->headers) && isset($structure->headers['subject']))
627    $a_return_parts[] = array('type' => 'headers',
628                              'headers' => $structure->headers);
629
630  // print body if message doesn't have multiple parts
631  if ($message_ctype_primary=='text')
632    {
633    $a_return_parts[] = array('type' => 'content',
634                              'body' => $structure->body,
635                              'ctype_primary' => $message_ctype_primary,
636                              'ctype_secondary' => $message_ctype_secondary,
637                              'encoding' => $structure->headers['content-transfer-encoding']);
638    }
639
640  // message contains alternative parts
641  else if ($message_ctype_primary=='multipart' && $message_ctype_secondary=='alternative' && is_array($structure->parts))
642    {
643    // get html/plaintext parts
644    $plain_part = $html_part = $print_part = $related_part = NULL;
645   
646    foreach ($structure->parts as $p => $sub_part)
647      {
648      $sub_ctype_primary = strtolower($sub_part->ctype_primary);
649      $sub_ctype_secondary = strtolower($sub_part->ctype_secondary);
650
651      // check if sub part is
652      if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='plain')
653        $plain_part = $p;
654      else if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='html')
655        $html_part = $p;
656      else if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='enriched')
657        $enriched_part = $p;
658      else if ($sub_ctype_primary=='multipart' && $sub_ctype_secondary=='related')
659        $related_part = $p;
660      }
661
662    // parse related part (alternative part could be in here)
663    if ($related_part!==NULL && $prefer_html)
664      {
665      list($parts, $attachmnts) = rcmail_parse_message($structure->parts[$related_part], $arg, TRUE);
666      $a_return_parts = array_merge($a_return_parts, $parts);
667      $a_attachments = array_merge($a_attachments, $attachmnts);
668      }
669
670    // print html/plain part
671    else if ($html_part!==NULL && $prefer_html)
672      $print_part = $structure->parts[$html_part];
673    else if ($enriched_part!==NULL)
674      $print_part = $structure->parts[$enriched_part];
675    else if ($plain_part!==NULL)
676      $print_part = $structure->parts[$plain_part];
677
678    // show message body
679    if (is_object($print_part))
680      $a_return_parts[] = array('type' => 'content',
681                                'body' => $print_part->body,
682                                'ctype_primary' => strtolower($print_part->ctype_primary),
683                                'ctype_secondary' => strtolower($print_part->ctype_secondary),
684                                'parameters' => $print_part->ctype_parameters,
685                                'encoding' => $print_part->headers['content-transfer-encoding']);
686    // show plaintext warning
687    else if ($html_part!==NULL)
688      $a_return_parts[] = array('type' => 'content',
689                                'body' => rcube_label('htmlmessage'),
690                                'ctype_primary' => 'text',
691                                'ctype_secondary' => 'plain');
692                               
693    // add html part as attachment
694    if ($html_part!==NULL && $structure->parts[$html_part]!==$print_part)
695      {
696      $html_part = $structure->parts[$html_part];
697      $a_attachments[] = array('filename' => rcube_label('htmlmessage'),
698                               'encoding' => $html_part->headers['content-transfer-encoding'],
699                               'mimetype' => 'text/html',
700                               'part_id'  => $html_part->mime_id,
701                               'size'     => strlen($IMAP->mime_decode($html_part->body, $html_part->headers['content-transfer-encoding'])));
702      }
703    }
704
705  // message contains multiple parts
706  else if ($message_ctype_primary=='multipart' && is_array($structure->parts))
707    {
708    foreach ($structure->parts as $mail_part)
709      {
710      $primary_type = strtolower($mail_part->ctype_primary);
711      $secondary_type = strtolower($mail_part->ctype_secondary);
712
713      // multipart/alternative
714      if ($primary_type=='multipart') // && ($secondary_type=='alternative' || $secondary_type=='mixed' || $secondary_type=='related'))
715        {
716        list($parts, $attachmnts) = rcmail_parse_message($mail_part, $arg, TRUE);
717
718        $a_return_parts = array_merge($a_return_parts, $parts);
719        $a_attachments = array_merge($a_attachments, $attachmnts);
720        }
721
722      // part text/[plain|html] OR message/delivery-status
723      else if (($primary_type=='text' && ($secondary_type=='plain' || $secondary_type=='html')) ||
724               ($primary_type=='message' && $secondary_type=='delivery-status'))
725        {
726        $a_return_parts[] = array('type' => 'content',
727                                  'body' => $mail_part->body,
728                                  'ctype_primary' => $primary_type,
729                                  'ctype_secondary' => $secondary_type,
730                                  'encoding' => $mail_part->headers['content-transfer-encoding']);
731        }
732
733      // part message/*
734      else if ($primary_type=='message')
735        {
736        /* don't parse headers here; they're parsed within the recursive call to rcmail_parse_message()
737        if ($mail_part->parts[0]->headers)
738          $a_return_parts[] = array('type' => 'headers',
739                                    'headers' => $mail_part->parts[0]->headers);
740        */
741                                     
742        list($parts, $attachmnts) = rcmail_parse_message($mail_part->parts[0], $arg, TRUE);
743
744        $a_return_parts = array_merge($a_return_parts, $parts);
745        $a_attachments = array_merge($a_attachments, $attachmnts);
746        }
747
748      // part is file/attachment
749      else if ($mail_part->disposition=='attachment' || $mail_part->disposition=='inline' || $mail_part->headers['content-id'])
750        {
751        if ($message_ctype_secondary=='related' && $mail_part->headers['content-id'])
752          $sa_inline_objects[] = array('filename' => $mail_part->d_parameters['filename'],
753                                       'mimetype' => strtolower("$primary_type/$secondary_type"),
754                                       'part_id'  => $mail_part->mime_id,
755                                       'content_id' => preg_replace(array('/^</', '/>$/'), '', $mail_part->headers['content-id']));
756
757        else if ($mail_part->d_parameters['filename'])
758          $a_attachments[] = array('filename' => $mail_part->d_parameters['filename'],
759                                   'encoding' => strtolower($mail_part->headers['content-transfer-encoding']),
760                                   'mimetype' => strtolower("$primary_type/$secondary_type"),
761                                   'part_id'  => $mail_part->mime_id,
762                                   'size'     => strlen($IMAP->mime_decode($mail_part->body, $mail_part->headers['content-transfer-encoding'])) /*,
763                                   'content'  => $mail_part->body */);
764                                   
765        else if ($mail_part->ctype_parameters['name'])
766          $a_attachments[] = array('filename' => $mail_part->ctype_parameters['name'],
767                                   'encoding' => strtolower($mail_part->headers['content-transfer-encoding']),
768                                   'mimetype' => strtolower("$primary_type/$secondary_type"),
769                                   'part_id'  => $mail_part->mime_id,
770                                   'size'     => strlen($IMAP->mime_decode($mail_part->body, $mail_part->headers['content-transfer-encoding'])) /*,
771                                   'content'  => $mail_part->body */);
772                                   
773                                   
774        }
775      }
776
777
778    // if this was a related part try to resolve references
779    if ($message_ctype_secondary=='related' && sizeof($sa_inline_objects))
780      {
781      $a_replace_patters = array();
782      $a_replace_strings = array();
783       
784      foreach ($sa_inline_objects as $inline_object)
785        {
786        $a_replace_patters[] = 'cid:'.$inline_object['content_id'];
787        $a_replace_strings[] = sprintf($get_url, $inline_object['part_id']);
788        }
789     
790      foreach ($a_return_parts as $i => $return_part)
791        {
792        if ($return_part['type']!='content')
793          continue;
794
795        // decode body and replace cid:...
796        $a_return_parts[$i]['body'] = str_replace($a_replace_patters, $a_replace_strings, $IMAP->mime_decode($return_part['body'], $return_part['encoding']));
797        $a_return_parts[$i]['encoding'] = '7bit';
798        }
799      }
800    }
801   
802
803  // join all parts together
804  //$out .= join($part_delimiter, $a_return_parts);
805
806  return array($a_return_parts, $a_attachments);
807  }
808
809
810
811
812// return table with message headers
813function rcmail_message_headers($attrib, $headers=NULL)
814  {
815  global $IMAP, $OUTPUT, $MESSAGE;
816  static $sa_attrib;
817 
818  // keep header table attrib
819  if (is_array($attrib) && !$sa_attrib)
820    $sa_attrib = $attrib;
821  else if (!is_array($attrib) && is_array($sa_attrib))
822    $attrib = $sa_attrib;
823 
824 
825  if (!isset($MESSAGE))
826    return FALSE;
827
828  // get associative array of headers object
829  if (!$headers)
830    $headers = is_object($MESSAGE['headers']) ? get_object_vars($MESSAGE['headers']) : $MESSAGE['headers'];
831   
832  $header_count = 0;
833 
834  // allow the following attributes to be added to the <table> tag
835  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
836  $out = '<table' . $attrib_str . ">\n";
837
838  // show these headers
839  $standard_headers = array('subject', 'from', 'organization', 'to', 'cc', 'reply-to', 'date');
840 
841  foreach ($standard_headers as $hkey)
842    {
843    if (!$headers[$hkey])
844      continue;
845
846    if ($hkey=='date')
847      $header_value = format_date(strtotime($headers[$hkey]));
848    else if (in_array($hkey, array('from', 'to', 'cc', 'reply-to')))
849      $header_value = rep_specialchars_output(rcmail_address_string($IMAP->decode_header($headers[$hkey]), NULL, $attrib['addicon']));
850    else
851      $header_value = rep_specialchars_output($IMAP->decode_header($headers[$hkey]), '', 'all');
852
853    $out .= "\n<tr>\n";
854    $out .= '<td class="header-title">'.rcube_label($hkey).":&nbsp;</td>\n";
855    $out .= '<td class="'.$hkey.'" width="90%">'.$header_value."</td>\n</tr>";
856    $header_count++;
857    }
858
859  $out .= "\n</table>\n\n";
860
861  return $header_count ? $out : ''; 
862  }
863
864
865
866function rcmail_message_body($attrib)
867  {
868  global $CONFIG, $OUTPUT, $MESSAGE, $GET_URL, $REMOTE_OBJECTS, $JS_OBJECT_NAME;
869 
870  if (!is_array($MESSAGE['parts']) && !$MESSAGE['body'])
871    return '';
872   
873  if (!$attrib['id'])
874    $attrib['id'] = 'rcmailMsgBody';
875
876  $safe_mode = (bool)$_GET['_safe'];
877  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
878  $out = '<div '. $attrib_str . ">\n";
879 
880  $header_attrib = array();
881  foreach ($attrib as $attr => $value)
882    if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs))
883      $header_attrib[$regs[1]] = $value;
884
885
886  // this is an ecrypted message
887  // -> create a plaintext body with the according message
888  if (!sizeof($MESSAGE['parts']) && $MESSAGE['headers']->ctype=='multipart/encrypted')
889    {
890    $MESSAGE['parts'][0] = array('type' => 'content',
891                                 'ctype_primary' => 'text',
892                                 'ctype_secondary' => 'plain',
893                                 'body' => rcube_label('encryptedmessage'));
894    }
895 
896  if ($MESSAGE['parts'])
897    {
898    foreach ($MESSAGE['parts'] as $i => $part)
899      {
900      if ($part['type']=='headers')
901        $out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part['headers']);
902      else if ($part['type']=='content')
903        {
904//        var_dump($part['parameters']);
905        // $body = rcmail_print_body($part['body'], $part['ctype_primary'], $part['ctype_secondary'], $part['encoding'], $safe_mode);
906        $body = rcmail_print_body($part, $safe_mode);
907        $out .= '<div class="message-part">';
908        $out .= rcmail_mod_html_body($body, $attrib['id']);
909        $out .= "</div>\n";
910        }
911      }
912    }
913  else
914    $out .= $MESSAGE['body'];
915
916
917  $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
918  $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
919 
920  // list images after mail body
921  if (get_boolean($attrib['showimages']) && $ctype_primary=='multipart' && $ctype_secondary=='mixed' &&
922      sizeof($MESSAGE['attachments']) && !strstr($message_body, '<html') && strlen($GET_URL))
923    {
924    foreach ($MESSAGE['attachments'] as $attach_prop)
925      {
926      if (strpos($attach_prop['mimetype'], 'image/')===0)
927        $out .= sprintf("\n<hr />\n<p align=\"center\"><img src=\"%s&_part=%s\" alt=\"%s\" title=\"%s\" /></p>\n",
928                        $GET_URL, $attach_prop['part_id'],
929                        $attach_prop['filename'],
930                        $attach_prop['filename']);
931      }
932    }
933 
934  // tell client that there are blocked remote objects
935  if ($REMOTE_OBJECTS && !$safe_mode)
936    $OUTPUT->add_script(sprintf("%s.set_env('blockedobjects', true);", $JS_OBJECT_NAME));
937
938  $out .= "\n</div>";
939  return $out;
940  }
941
942
943
944// modify a HTML message that it can be displayed inside a HTML page
945function rcmail_mod_html_body($body, $container_id)
946  {
947  $last_style_pos = 0;
948  $body_lc = strtolower($body);
949 
950  // find STYLE tags
951  while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
952    {
953    $pos2 += 8;
954    $body_pre = substr($body, 0, $pos);
955    $styles = substr($body, $pos, $pos2-$pos);
956    $body_post = substr($body, $pos2, strlen($body)-$pos2);
957   
958    // replace all css definitions with #container [def]
959    $styles = rcmail_mod_css_styles($styles, $container_id);
960   
961    $body = $body_pre . $styles . $body_post;
962    $last_style_pos = $pos2;
963    }
964
965
966  // remove SCRIPT tags
967  while (($pos = strpos($body_lc, '<script')) && ($pos2 = strpos($body_lc, '</script>', $pos)))
968    {
969    $pos2 += 8;
970    $body = substr($body, 0, $pos) . substr($body, $pos2, strlen($body)-$pos2);
971    $body_lc = strtolower($body);
972    }
973 
974
975  // resolve <base href>
976  $base_reg = '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i';
977  if (preg_match($base_reg, $body, $regs))
978    {
979    $base_url = $regs[2];
980    $body = preg_replace('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Uie', "'\\1=\"'.make_absolute_url('\\3', '$base_url').'\"'", $body);
981    $body = preg_replace('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Uie', "'\\1\''.make_absolute_url('\\3', '$base_url').'\')'", $body);
982    $body = preg_replace($base_reg, '', $body);
983    }
984
985
986  // add comments arround html and other tags
987  $out = preg_replace(array('/(<\/?html[^>]*>)/i',
988                            '/(<\/?head[^>]*>)/i',
989                            '/(<title[^>]*>.+<\/title>)/ui',
990                            '/(<\/?meta[^>]*>)/i'),
991                      '<!--\\1-->',
992                      $body);
993                     
994  $out = preg_replace(array('/(<body[^>]*>)/i',
995                            '/(<\/body>)/i'),
996                      array('<div class="rcmBody">',
997                            '</div>'),
998                      $out);
999
1000 
1001  return $out;
1002  }
1003
1004
1005
1006// replace all css definitions with #container [def]
1007function rcmail_mod_css_styles($source, $container_id)
1008  {
1009  $a_css_values = array();
1010  $last_pos = 0;
1011 
1012  // cut out all contents between { and }
1013  while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos)))
1014    {
1015    $key = sizeof($a_css_values);
1016    $a_css_values[$key] = substr($source, $pos+1, $pos2-($pos+1));
1017    $source = substr($source, 0, $pos+1) . "<<str_replacement[$key]>>" . substr($source, $pos2, strlen($source)-$pos2);
1018    $last_pos = $pos+2;
1019    }
1020 
1021  $styles = preg_replace('/(^\s*|,\s*)([a-z0-9\._][a-z0-9\.\-_]*)/im', "\\1#$container_id \\2", $source);
1022  $styles = preg_replace('/<<str_replacement\[([0-9]+)\]>>/e', "\$a_css_values[\\1]", $styles);
1023 
1024  // replace body definition because we also stripped off the <body> tag
1025  $styles = preg_replace("/$container_id\s+body/i", "$container_id div.rcmBody", $styles);
1026 
1027  return $styles;
1028  }
1029
1030
1031
1032// return first text part of a message
1033function rcmail_first_text_part($message_parts)
1034  {
1035  if (!is_array($message_parts))
1036    return FALSE;
1037   
1038  $html_part = NULL;
1039     
1040  // check all message parts
1041  foreach ($message_parts as $pid => $part)
1042    {
1043    $mimetype = strtolower($part->ctype_primary.'/'.$part->ctype_secondary);
1044    if ($mimetype=='text/plain')
1045      {
1046      $body = rcube_imap::mime_decode($part->body, $part->headers['content-transfer-encoding']);
1047      $body = rcube_imap::charset_decode($body, $part->ctype_parameters);
1048      return $body;
1049      }
1050    else if ($mimetype=='text/html')
1051      {
1052      $html_part = rcube_imap::mime_decode($part->body, $part->headers['content-transfer-encoding']);
1053      $html_part = rcube_imap::charset_decode($html_part, $part->ctype_parameters);
1054      }
1055    }
1056   
1057
1058  // convert HTML to plain text
1059  if ($html_part)
1060    {   
1061    // remove special chars encoding
1062    $trans = array_flip(get_html_translation_table(HTML_ENTITIES));
1063    $html_part = strtr($html_part, $trans);
1064
1065    // create instance of html2text class
1066    $txt = new html2text($html_part);
1067    return $txt->get_text();
1068    }
1069
1070  return FALSE;
1071  }
1072
1073
1074// get source code of a specific message and cache it
1075function rcmail_message_source($uid)
1076  {
1077  global $IMAP, $DB;
1078
1079  // get message ID if uid is given 
1080  $headers = $IMAP->get_headers($uid);
1081  $message_id = $headers->messageID;
1082 
1083  // get cached message source
1084  $msg_source = rcube_read_cache($message_id);
1085
1086  // get message from server and cache it
1087  if (!$msg_source)
1088    {
1089    $msg_source = $IMAP->get_raw_body($uid);
1090    rcube_write_cache($message_id, $msg_source, TRUE);
1091    }
1092
1093  return $msg_source;
1094  }
1095
1096
1097// decode address string and re-format it as HTML links
1098function rcmail_address_string($input, $max=NULL, $addicon=NULL)
1099  {
1100  global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $EMAIL_ADDRESS_PATTERN;
1101 
1102  $a_parts = $IMAP->decode_address_list($input);
1103
1104  if (!sizeof($a_parts))
1105    return $input;
1106
1107  $c = count($a_parts);
1108  $j = 0;
1109  $out = '';
1110
1111  foreach ($a_parts as $part)
1112    {
1113    $j++;
1114    if ($PRINT_MODE)
1115      $out .= sprintf('%s &lt;%s&gt;', htmlentities($part['name']), $part['mailto']);
1116    else if (preg_match($EMAIL_ADDRESS_PATTERN, $part['mailto']))
1117      {
1118      $out .= sprintf('<a href="mailto:%s" onclick="return %s.command(\'compose\',\'%s\',this)" class="rcmContactAddress" title="%s">%s</a>',
1119                      $part['mailto'],
1120                      $JS_OBJECT_NAME,
1121                      $part['mailto'],
1122                      $part['mailto'],
1123                      htmlentities($part['name']));
1124                     
1125      if ($addicon)
1126        $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>',
1127                        $JS_OBJECT_NAME,
1128                        urlencode($part['string']),
1129                        rcube_label('addtoaddressbook'),
1130                        $CONFIG['skin_path'],
1131                        $addicon);
1132      }
1133    else
1134      {
1135      if ($part['name'])
1136        $out .= htmlentities($part['name']);
1137      if ($part['mailto'])
1138        $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', $part['mailto']);
1139      }
1140     
1141    if ($c>$j)
1142      $out .= ','.($max ? '&nbsp;' : ' ');
1143       
1144    if ($max && $j==$max && $c>$j)
1145      {
1146      $out .= '...';
1147      break;
1148      }       
1149    }
1150   
1151  return $out;
1152  }
1153
1154
1155function rcmail_message_part_controls()
1156  {
1157  global $CONFIG, $IMAP, $MESSAGE;
1158 
1159  if (!is_array($MESSAGE) || !is_array($MESSAGE['parts']) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE['parts'][$_GET['_part']])
1160    return '';
1161   
1162  $part = $MESSAGE['parts'][$_GET['_part']];
1163 
1164  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'cellspacing', 'cellpadding', 'border', 'summary'));
1165  $out = '<table '. $attrib_str . ">\n";
1166 
1167  $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
1168  $filesize = strlen($IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
1169 
1170  if ($filename)
1171    {
1172    $out .= sprintf('<tr><td class="title">%s</td><td>%s</td><td>[<a href="./?%s">%s</a>]</tr>'."\n",
1173                    rcube_label('filename'),
1174                    rep_specialchars_output($filename),
1175                    str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']),
1176                    rcube_label('download'));
1177    }
1178   
1179  if ($filesize)
1180    $out .= sprintf('<tr><td class="title">%s</td><td>%s</td></tr>'."\n",
1181                    rcube_label('filesize'),
1182                    show_bytes($filesize));
1183 
1184  $out .= "\n</table>";
1185 
1186  return $out;
1187  }
1188
1189
1190
1191function rcmail_message_part_frame($attrib)
1192  {
1193  global $MESSAGE;
1194 
1195  $part = $MESSAGE['parts'][$_GET['_part']];
1196  $ctype_primary = strtolower($part->ctype_primary);
1197
1198  $attrib['src'] = './?'.str_replace('_frame=', ($ctype_primary=='text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']);
1199
1200  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'src', 'width', 'height'));
1201  $out = '<iframe '. $attrib_str . "></ifame>";
1202   
1203  return $out;
1204  }
1205
1206
1207// create temp dir for attachments
1208function rcmail_create_compose_tempdir()
1209  {
1210  global $CONFIG;
1211 
1212  if ($_SESSION['compose']['temp_dir'])
1213    return $_SESSION['compose']['temp_dir'];
1214 
1215  if (!empty($CONFIG['temp_dir']))
1216    $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$', $CONFIG['temp_dir']) ? '/' : '').$_SESSION['compose']['id'];
1217
1218  // create temp-dir for uploaded attachments
1219  if (!empty($CONFIG['temp_dir']) && is_writeable($CONFIG['temp_dir']))
1220    {
1221    mkdir($temp_dir);
1222    $_SESSION['compose']['temp_dir'] = $temp_dir;
1223    }
1224
1225  return $_SESSION['compose']['temp_dir'];
1226  }
1227
1228
1229// clear message composing settings
1230function rcmail_compose_cleanup()
1231  {
1232  if (!isset($_SESSION['compose']))
1233    return;
1234 
1235  // remove attachment files from temp dir
1236  if (is_array($_SESSION['compose']['attachments']))
1237    foreach ($_SESSION['compose']['attachments'] as $attachment)
1238      unlink($attachment['path']);
1239
1240  // kill temp dir
1241  if ($_SESSION['compose']['temp_dir'])
1242    rmdir($_SESSION['compose']['temp_dir']);
1243 
1244  unset($_SESSION['compose']);
1245  }
1246 
1247 
1248?>
Note: See TracBrowser for help on using the repository browser.