source: subversion/trunk/roundcubemail/program/steps/mail/compose.inc @ 1800

Last change on this file since 1800 was 1800, checked in by alec, 5 years ago
  • Reduced memory footprint when forwarding attachments (#1485345)
  • Fixed endless loop in iil_C_HandlePartBody()
  • rcube_message::get_part_content() speed up using 3rd argument of rcube_imap::get_message_part()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.1 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc                                        |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Compose a new mail message with all headers and attachments         |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22// define constants for message compose mode
23define('RCUBE_COMPOSE_REPLY', 0x0106);
24define('RCUBE_COMPOSE_FORWARD', 0x0107);
25define('RCUBE_COMPOSE_DRAFT', 0x0108);
26
27
28// remove an attachment
29if ($RCMAIL->action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
30{
31  $id = $regs[1];
32  if (is_array($_SESSION['compose']['attachments'][$id]))
33  {
34    @unlink($_SESSION['compose']['attachments'][$id]['path']);
35    unset($_SESSION['compose']['attachments'][$id]);
36    $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
37    $OUTPUT->send();
38    exit;
39  }
40}
41
42if ($RCMAIL->action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
43{
44  $id = $regs[1];
45  if (is_array($_SESSION['compose']['attachments'][$id]))
46  {
47    $apath = $_SESSION['compose']['attachments'][$id]['path'];
48    header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']);
49    header('Content-Length: ' . filesize($apath));
50    readfile($apath);
51  }
52  exit;
53}
54
55$MESSAGE_FORM = NULL;
56$MESSAGE = NULL;
57
58// Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
59// if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
60// Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
61// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
62
63if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
64{
65  rcmail_compose_cleanup();
66  $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET));
67 
68  // process values like "mailto:foo@bar.com?subject=new+message&cc=another"
69  if ($_SESSION['compose']['param']['_to']) {
70    $mailto = explode('?', $_SESSION['compose']['param']['_to']);
71    if (count($mailto) > 1) {
72      $_SESSION['compose']['param']['_to'] = $mailto[0];
73      parse_str($mailto[1], $query);
74      foreach ($query as $f => $val)
75        $_SESSION['compose']['param']["_$f"] = $val;
76    }
77  }
78
79  // redirect to a unique URL with all parameters stored in session
80  $OUTPUT->redirect(array('_action' => 'compose', '_id' => $_SESSION['compose']['id']));
81}
82
83// add some labels to client
84rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
85
86// add config parameter to client script
87$OUTPUT->set_env('draft_autosave', !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0);
88
89
90// get reference message and set compose mode
91if ($msg_uid = $_SESSION['compose']['param']['_reply_uid'])
92  $compose_mode = RCUBE_COMPOSE_REPLY;
93else if ($msg_uid = $_SESSION['compose']['param']['_forward_uid'])
94  $compose_mode = RCUBE_COMPOSE_FORWARD;
95else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid'])
96  $compose_mode = RCUBE_COMPOSE_DRAFT;
97
98if (!empty($msg_uid))
99{
100  // similar as in program/steps/mail/show.inc
101  $MESSAGE = new rcube_message($msg_uid);
102 
103  if (!empty($MESSAGE->headers->charset))
104    $IMAP->set_charset($MESSAGE->headers->charset);
105   
106  if ($compose_mode == RCUBE_COMPOSE_REPLY)
107  {
108    $_SESSION['compose']['reply_uid'] = $msg_uid;
109    $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID;
110    $_SESSION['compose']['references']  = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
111
112    if (!empty($_SESSION['compose']['param']['_all']))
113      $MESSAGE->reply_all = 1;
114  }
115  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
116  {
117    if($MESSAGE->headers->in_reply_to)
118    {
119      // TODO: how to get reply_uid/forward_uid value, maybe we must set X-Reply-UID/X-Forward-UID
120      // $_SESSION['compose']['reply_uid'] = ?
121      // $_SESSION['compose']['forward_uid'] = ?
122      $_SESSION['compose']['reply_msgid'] = '<'.$MESSAGE->headers->in_reply_to.'>';
123    }
124    $_SESSION['compose']['references']  = $MESSAGE->headers->references;
125  }
126  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
127  {
128    $_SESSION['compose']['forward_uid'] = $msg_uid;
129  }
130}
131
132/****** compose mode functions ********/
133
134
135function rcmail_compose_headers($attrib)
136{
137  global $IMAP, $MESSAGE, $DB, $compose_mode;
138  static $sa_recipients = array();
139
140  list($form_start, $form_end) = get_form_tags($attrib);
141 
142  $out = '';
143  $part = strtolower($attrib['part']);
144 
145  switch ($part)
146  {
147    case 'from':
148      return rcmail_compose_header_from($attrib);
149
150    case 'to':
151      $fname = '_to';
152      $header = 'to';
153     
154      // we have a set of recipients stored is session
155      if (($mailto_id = $_SESSION['compose']['param']['_mailto']) && $_SESSION['mailto'][$mailto_id])
156        $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
157     
158    case 'cc':
159      if (!$fname)
160      {
161        $fname = '_cc';
162        $header = 'cc';
163      }
164    case 'bcc':
165      if (!$fname)
166      {
167        $fname = '_bcc';
168        $header = 'bcc';
169      }
170       
171      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex');
172      $field_type = 'html_textarea';
173      break;
174
175    case 'replyto':
176    case 'reply-to':
177      $fname = '_replyto';
178      $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
179      $field_type = 'html_inputfield';
180      break;
181  }
182 
183  if ($fname && !empty($_POST[$fname]))
184    $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
185  else if ($fname && !$fvalue && !empty($_SESSION['compose']['param'][$fname]))
186    $fvalue = $_SESSION['compose']['param'][$fname];
187
188  else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY)
189  {
190    // get recipent address(es) out of the message headers
191    if ($header=='to' && !empty($MESSAGE->headers->replyto))
192      $fvalue = $MESSAGE->headers->replyto;
193
194    else if ($header=='to' && !empty($MESSAGE->headers->from))
195      $fvalue = $MESSAGE->headers->from;
196
197    // add recipent of original message if reply to all
198    else if ($header=='cc' && !empty($MESSAGE->reply_all))
199    {
200      if ($v = $MESSAGE->headers->to)
201        $fvalue .= $v;
202
203      if ($v = $MESSAGE->headers->cc)
204        $fvalue .= (!empty($fvalue) ? ', ' : '') . $v;
205    }
206
207    // split recipients and put them back together in a unique way
208    if (!empty($fvalue))
209    {
210      $to_addresses = $IMAP->decode_address_list($fvalue);
211      $fvalue = '';
212
213      foreach ($to_addresses as $addr_part)
214      {
215        if (!empty($addr_part['mailto'])
216            && !in_array($addr_part['mailto'], $sa_recipients)
217            && (!$MESSAGE->compose_from
218                || !in_array($addr_part['mailto'], $MESSAGE->compose_from)
219                || count($to_addresses)==1)) // allow reply to yourself
220        {
221          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
222          $sa_recipients[] = $addr_part['mailto'];
223        }
224      }
225    }
226  }
227  else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT)
228  {
229    // get drafted headers
230    if ($header=='to' && !empty($MESSAGE->headers->to))
231      $fvalue = $MESSAGE->get_header('to');
232
233    if ($header=='cc' && !empty($MESSAGE->headers->cc))
234      $fvalue = $MESSAGE->get_header('cc');
235
236    if ($header=='bcc' && !empty($MESSAGE->headers->bcc))
237      $fvalue = $MESSAGE->get_header('bcc');
238  }
239
240       
241  if ($fname && $field_type)
242  {
243    // pass the following attributes to the form class
244    $field_attrib = array('name' => $fname);
245    foreach ($attrib as $attr => $value)
246      if (in_array($attr, $allow_attrib))
247        $field_attrib[$attr] = $value;
248
249    // create teaxtarea object
250    $input = new $field_type($field_attrib);
251    $out = $input->show($fvalue);
252  }
253 
254  if ($form_start)
255    $out = $form_start.$out;
256
257  return $out; 
258}
259
260
261
262function rcmail_compose_header_from($attrib)
263{
264  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode;
265   
266  // pass the following attributes to the form class
267  $field_attrib = array('name' => '_from');
268  foreach ($attrib as $attr => $value)
269    if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
270      $field_attrib[$attr] = $value;
271
272  // extract all recipients of the reply-message
273  $a_recipients = array();
274  if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE->headers))
275  {
276    $MESSAGE->compose_from = array();
277
278    $a_to = $IMAP->decode_address_list($MESSAGE->headers->to);
279    foreach ($a_to as $addr)
280    {
281      if (!empty($addr['mailto']))
282        $a_recipients[] = $addr['mailto'];
283    }
284
285    if (!empty($MESSAGE->headers->cc))
286    {
287      $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc);
288      foreach ($a_cc as $addr)
289      {
290        if (!empty($addr['mailto']))
291          $a_recipients[] = $addr['mailto'];
292      }
293    }
294  }
295
296  // get this user's identities
297  $sql_result = $USER->list_identities();
298
299  if ($DB->num_rows($sql_result))
300  {
301    $from_id = 0;
302    $a_signatures = array();
303
304    $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)";
305    $select_from = new html_select($field_attrib);
306
307    while ($sql_arr = $DB->fetch_assoc($sql_result))
308    {
309      $identity_id = $sql_arr['identity_id'];
310      $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
311
312      // add signature to array
313      if (!empty($sql_arr['signature']))
314      {
315        $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
316        $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
317        if ($a_signatures[$identity_id]['is_html'])
318        {
319            $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
320            $plainTextPart = $h2t->get_text();
321            $a_signatures[$identity_id]['plain_text'] = trim(html_entity_decode($plainTextPart, ENT_NOQUOTES, 'UTF-8'));
322        }
323      }
324
325      // set identity if it's one of the reply-message recipients
326      if (in_array($sql_arr['email'], $a_recipients))
327        $from_id = $sql_arr['identity_id'];
328
329      if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE->compose_from))
330        $MESSAGE->compose_from[] = $sql_arr['email'];
331
332      if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email']))
333        $from_id = $sql_arr['identity_id'];
334    }
335
336    // overwrite identity selection with post parameter
337    if (isset($_POST['_from']))
338      $from_id = get_input_value('_from', RCUBE_INPUT_POST);
339
340    $out = $select_from->show($from_id);
341
342    // add signatures to client
343    $OUTPUT->set_env('signatures', $a_signatures);
344  }
345  else
346  {
347    $input_from = new html_inputfield($field_attrib);
348    $out = $input_from->show($_POST['_from']);
349  }
350 
351  if ($form_start)
352    $out = $form_start.$out;
353
354  return $out;
355}
356
357
358function rcmail_compose_body($attrib)
359{
360  global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
361 
362  list($form_start, $form_end) = get_form_tags($attrib);
363  unset($attrib['form']);
364 
365  if (empty($attrib['id']))
366    $attrib['id'] = 'rcmComposeMessage';
367
368  $attrib['name'] = '_message';
369
370  if ($CONFIG['htmleditor'])
371    $isHtml = true;
372  else
373    $isHtml = false;
374
375  $body = '';
376
377  // use posted message body
378  if (!empty($_POST['_message']))
379  {
380    $body = get_input_value('_message', RCUBE_INPUT_POST, true);
381  }
382  else if ($compose_mode)
383  {
384    if ($isHtml && $MESSAGE->has_html_part())
385    {
386      $body = $MESSAGE->first_html_part();
387      $isHtml = true;
388    }
389    else
390    {
391      $body = $MESSAGE->first_text_part();
392      $isHtml = false;
393    }
394   
395    // compose reply-body
396    if ($compose_mode == RCUBE_COMPOSE_REPLY)
397      $body = rcmail_create_reply_body($body, $isHtml);
398    // forward message body inline
399    else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
400      $body = rcmail_create_forward_body($body, $isHtml);
401    // load draft message body
402    else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
403      $body = rcmail_create_draft_body($body, $isHtml);
404  }
405  else if (!empty($_SESSION['compose']['param']['_body']))
406  {
407    $body = $_SESSION['compose']['param']['_body'];
408  }
409
410  $lang = $tinylang = strtolower(substr($_SESSION['language'], 0, 2));
411  if (!file_exists(INSTALL_PATH . 'program/js/tiny_mce/langs/'.$tinylang.'.js'))
412    $tinylang = 'en';
413
414  $OUTPUT->include_script('tiny_mce/tiny_mce.js');
415  $OUTPUT->include_script("editor.js");
416  $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.JQ($tinylang).'", '.intval($CONFIG['enable_spellcheck']).');');
417
418  $out = $form_start ? "$form_start\n" : '';
419
420  $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : ''));
421  $out .= $saveid->show();
422
423  $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes'));
424  $out .= $drafttoggle->show();
425
426  $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
427  $out .= $msgtype->show();
428
429  // If desired, set this text area to be editable by TinyMCE
430  if ($isHtml) $attrib['class'] = "mce_editor";
431  $textarea = new html_textarea($attrib);
432  $out .= $textarea->show($body);
433  $out .= $form_end ? "\n$form_end" : '';
434
435  // include GoogieSpell
436  if (!empty($CONFIG['enable_spellcheck'])) {
437    $spellcheck_langs = (array)$RCMAIL->config->get('spellcheck_languages', array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska'));
438    if (!$spellcheck_langs[$lang])
439      $lang = 'en';
440   
441    $editor_lang_set = array();
442    foreach ($spellcheck_langs as $key => $name) {
443      $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key);
444    }
445   
446    $OUTPUT->include_script('googiespell.js');
447    $OUTPUT->add_script(sprintf(
448      "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
449      "googie.lang_chck_spell = \"%s\";\n".
450      "googie.lang_rsm_edt = \"%s\";\n".
451      "googie.lang_close = \"%s\";\n".
452      "googie.lang_revert = \"%s\";\n".
453      "googie.lang_no_error_found = \"%s\";\n".
454      "googie.setLanguages(%s);\n".
455      "googie.setCurrentLanguage('%s');\n".
456      "googie.decorateTextarea('%s');\n".
457      "%s.set_env('spellcheck', googie);",
458      $RCMAIL->comm_path,
459      JQ(Q(rcube_label('checkspelling'))),
460      JQ(Q(rcube_label('resumeediting'))),
461      JQ(Q(rcube_label('close'))),
462      JQ(Q(rcube_label('revertto'))),
463      JQ(Q(rcube_label('nospellerrors'))),
464      json_serialize($spellcheck_langs),
465      $lang,
466      $attrib['id'],
467      JS_OBJECT_NAME), 'foot');
468
469    rcube_add_label('checking');
470    $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
471  }
472 
473  $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
474
475  return $out;
476}
477
478
479function rcmail_create_reply_body($body, $bodyIsHtml)
480{
481  global $IMAP, $MESSAGE, $OUTPUT;
482
483  if (! $bodyIsHtml)
484  {
485    // soft-wrap message first
486    $body = rcmail_wrap_quoted($body, 75);
487 
488    // split body into single lines
489    $a_lines = preg_split('/\r?\n/', $body);
490 
491    // add > to each line
492    for($n=0; $n<sizeof($a_lines); $n++)
493    {
494      if (strpos($a_lines[$n], '>')===0)
495        $a_lines[$n] = '>'.$a_lines[$n];
496      else
497        $a_lines[$n] = '> '.$a_lines[$n];
498    }
499 
500    $body = join("\n", $a_lines);
501
502    // add title line
503    $prefix = sprintf("\n\n\nOn %s, %s wrote:\n",
504      $MESSAGE->headers->date,
505      $MESSAGE->get_header('from'));
506
507    // try to remove the signature
508    if ($sp = strrpos($body, '-- '))
509      {
510      if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
511        $body = substr($body, 0, $sp-1);
512      }
513    $suffix = '';
514  }
515  else
516  {
517    $prefix = sprintf("<br /><br />On %s, %s wrote:<br />\n",
518      $MESSAGE->headers->date,
519      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
520    $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
521    $suffix = "</blockquote>";
522  }
523
524  return $prefix.$body.$suffix;
525}
526
527
528function rcmail_create_forward_body($body, $bodyIsHtml)
529{
530  global $IMAP, $MESSAGE, $OUTPUT;
531
532  if (!$bodyIsHtml)
533  {
534    $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
535      $MESSAGE->subject,
536      $MESSAGE->headers->date,
537      $MESSAGE->get_header('from'),
538      $MESSAGE->get_header('to'));
539  }
540  else
541  {
542    $prefix = sprintf(
543      "<br><br>-------- Original Message --------" .
544        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
545        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
546        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
547        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
548        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" .
549        "</tbody></table><br>",
550      Q($MESSAGE->subject),
551      Q($MESSAGE->headers->date),
552      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true),
553      htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
554  }
555
556  // add attachments
557  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts))
558    rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
559   
560  return $prefix.$body;
561}
562
563
564function rcmail_create_draft_body($body, $bodyIsHtml)
565{
566  global $MESSAGE;
567 
568  /**
569   * add attachments
570   * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text!
571   */
572  if (!isset($_SESSION['compose']['forward_attachments'])
573      && is_array($MESSAGE->mime_parts)
574      && count($MESSAGE->mime_parts) > 0)
575    rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
576
577  return $body;
578}
579 
580 
581function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
582{
583  global $RCMAIL, $IMAP;
584
585  $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
586
587  if (!is_array($_SESSION['compose']['attachments']))
588    $_SESSION['compose']['attachments'] = array();
589 
590  foreach ((array)$message->mime_parts as $pid => $part)
591  {
592    if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
593        ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
594         (empty($part->disposition) && $part->filename)))
595    {
596      $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
597      if ($fp = fopen($tmp_path, 'w'))
598      {
599        $message->get_part_content($pid, $fp);
600        fclose($fp);
601       
602        $_SESSION['compose']['attachments'][] = array(
603          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
604          'name' => $part->filename,
605          'path' => $tmp_path
606          );
607      }
608    }
609  }
610       
611  $_SESSION['compose']['forward_attachments'] = true;
612}
613
614
615function rcmail_compose_subject($attrib)
616{
617  global $MESSAGE, $compose_mode;
618 
619  list($form_start, $form_end) = get_form_tags($attrib);
620  unset($attrib['form']);
621 
622  $attrib['name'] = '_subject';
623  $textfield = new html_inputfield($attrib);
624
625  $subject = '';
626
627  // use subject from post
628  if (isset($_POST['_subject'])) {
629    $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
630  }
631  // create a reply-subject
632  else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
633    if (eregi('^re:', $MESSAGE->subject))
634      $subject = $MESSAGE->subject;
635    else
636      $subject = 'Re: '.$MESSAGE->subject;
637  }
638  // create a forward-subject
639  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
640    if (eregi('^fwd:', $MESSAGE->subject))
641      $subject = $MESSAGE->subject;
642    else
643      $subject = 'Fwd: '.$MESSAGE->subject;
644  }
645  // creeate a draft-subject
646  else if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
647    $subject = $MESSAGE->subject;
648  }
649  else if (!empty($_SESSION['compose']['param']['_subject'])) {
650    $subject = $_SESSION['compose']['param']['_subject'];
651  }
652 
653  $out = $form_start ? "$form_start\n" : '';
654  $out .= $textfield->show($subject);
655  $out .= $form_end ? "\n$form_end" : '';
656         
657  return $out;
658}
659
660
661function rcmail_compose_attachment_list($attrib)
662{
663  global $OUTPUT, $CONFIG;
664 
665  // add ID if not given
666  if (!$attrib['id'])
667    $attrib['id'] = 'rcmAttachmentList';
668 
669  $out = "\n";
670 
671  if (is_array($_SESSION['compose']['attachments']))
672  {
673    if ($attrib['deleteicon'])
674      $button = html::img(array(
675        'src' => $CONFIG['skin_path'] . $attrib['deleteicon'],
676        'alt' => rcube_label('delete'),
677        'style' => "border:0;padding-right:2px;vertical-align:middle"));
678    else
679      $button = Q(rcube_label('delete'));
680
681    foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
682    {
683      if (empty($a_prop))
684        continue;
685     
686      $out .= html::tag('li', array('id' => "rcmfile".$id),
687        html::a(array(
688            'href' => "#delete",
689            'title' => rcube_label('delete'),
690            'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
691          $button) . Q($a_prop['name']));
692    }
693  }
694
695  $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
696   
697  return html::tag('ul', $attrib, $out, html::$common_attrib);
698}
699
700
701function rcmail_compose_attachment_form($attrib)
702{
703  global $OUTPUT;
704
705  // add ID if not given
706  if (!$attrib['id'])
707    $attrib['id'] = 'rcmUploadbox';
708 
709  $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
710 
711  $out = html::div($attrib,
712    $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data')) .
713    html::div(null, rcmail_compose_attachment_field(array())) .
714    html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))))) .
715    html::div('buttons',
716      $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . ' ' .
717      $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)")))
718  );
719 
720 
721  $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
722  return $out;
723}
724
725
726function rcmail_compose_attachment_field($attrib)
727{
728  // allow the following attributes to be added to the <input> tag
729  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
730 
731  $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
732  return $out;
733}
734
735
736function rcmail_priority_selector($attrib)
737{
738  global $MESSAGE;
739 
740  list($form_start, $form_end) = get_form_tags($attrib);
741  unset($attrib['form']);
742 
743  $attrib['name'] = '_priority';
744  $selector = new html_select($attrib);
745
746  $selector->add(array(rcube_label('lowest'),
747                       rcube_label('low'),
748                       rcube_label('normal'),
749                       rcube_label('high'),
750                       rcube_label('highest')),
751                 array(5, 4, 0, 2, 1));
752                 
753  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority);
754
755  $out = $form_start ? "$form_start\n" : '';
756  $out .= $selector->show($sel);
757  $out .= $form_end ? "\n$form_end" : '';
758         
759  return $out;
760}
761
762
763function rcmail_receipt_checkbox($attrib)
764{
765  global $MESSAGE, $compose_mode;
766 
767  list($form_start, $form_end) = get_form_tags($attrib);
768  unset($attrib['form']);
769 
770  if (!isset($attrib['id']))
771    $attrib['id'] = 'receipt'; 
772
773  $attrib['name'] = '_receipt';
774  $attrib['value'] = '1';
775  $checkbox = new html_checkbox($attrib);
776
777  $out = $form_start ? "$form_start\n" : '';
778  $out .= $checkbox->show(
779    $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0);
780  $out .= $form_end ? "\n$form_end" : '';
781
782  return $out;
783}
784
785
786function rcmail_editor_selector($attrib)
787{
788  global $CONFIG, $MESSAGE, $compose_mode;
789
790  $choices = array(
791    'html'  => 'htmltoggle',
792    'plain' => 'plaintoggle'
793  );
794
795  // determine whether HTML or plain text should be checked
796  $useHtml = $CONFIG['htmleditor'] ? true : false;
797
798  if ($compose_mode)
799    $useHtml = ($useHtml && $MESSAGE->has_html_part());
800
801  $selector = '';
802  $chosenvalue = $useHtml ? 'html' : 'plain';
803  $radio = new html_radiobutton(array('name' => '_editorSelect', 'onclick' => 'return rcmail_toggle_editor(this)'));
804  foreach ($choices as $value => $text)
805  {
806    $attrib['id'] = '_' . $value;
807    $attrib['value'] = $value;
808    $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text)));
809  }
810
811  return $selector;
812}
813
814
815function rcmail_store_target_selection($attrib)
816{
817  $attrib['name'] = '_store_target';
818  $select = rcmail_mailbox_select(array_merge($attrib, array('noselection' => '- '.rcube_label('dontsave').' -')));
819  return $select->show(rcmail::get_instance()->config->get('sent_mbox'), $attrib);
820}
821
822
823function get_form_tags($attrib)
824{
825  global $RCMAIL, $MESSAGE_FORM;
826
827  $form_start = '';
828  if (!strlen($MESSAGE_FORM))
829  {
830    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
831    $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
832
833    $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
834    $form_start .= $hiddenfields->show();
835  }
836   
837  $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
838  $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
839 
840  if (!strlen($MESSAGE_FORM))
841    $RCMAIL->output->add_gui_object('messageform', $form_name);
842 
843  $MESSAGE_FORM = $form_name;
844
845  return array($form_start, $form_end);
846}
847
848
849// register UI objects
850$OUTPUT->add_handlers(array(
851  'composeheaders' => 'rcmail_compose_headers',
852  'composesubject' => 'rcmail_compose_subject',
853  'composebody' => 'rcmail_compose_body',
854  'composeattachmentlist' => 'rcmail_compose_attachment_list',
855  'composeattachmentform' => 'rcmail_compose_attachment_form',
856  'composeattachment' => 'rcmail_compose_attachment_field',
857  'priorityselector' => 'rcmail_priority_selector',
858  'editorselector' => 'rcmail_editor_selector',
859  'receiptcheckbox' => 'rcmail_receipt_checkbox',
860  'storetarget' => 'rcmail_store_target_selection',
861));
862
863/****** get contacts for this user and add them to client scripts ********/
864
865$CONTACTS = new rcube_contacts($DB, $USER->ID);
866$CONTACTS->set_pagesize(1000);
867
868$a_contacts = array();
869                                   
870if ($result = $CONTACTS->list_records())
871  {
872  while ($sql_arr = $result->iterate())
873    if ($sql_arr['email'])
874      $a_contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
875  }
876if (!empty($CONFIG['ldap_public']) && is_array($CONFIG['ldap_public']))
877  {
878  /* LDAP autocompletion */
879  foreach ($CONFIG['ldap_public'] as $ldapserv_config)
880    {
881    if ($ldapserv_config['fuzzy_search'] != 1 ||
882        $ldapserv_config['global_search'] != 1)
883      {
884      continue;
885      }
886         
887    $LDAP = new rcube_ldap($ldapserv_config);
888    $LDAP->connect();
889    $LDAP->set_pagesize(1000);
890 
891    $results = $LDAP->search($ldapserv_config['mail_field'], "");
892 
893    for ($i = 0; $i < $results->count; $i++)
894          {
895          if ($results->records[$i]['email'] != '')
896            {
897            $email = $results->records[$i]['email'];
898            $name = $results->records[$i]['name'];
899                 
900            $a_contacts[] = format_email_recipient($email, $name);
901            }
902          }
903    $LDAP->close();
904    }
905  }
906if ($a_contacts)
907  {
908        $OUTPUT->set_env('contacts', $a_contacts);
909  }
910
911$OUTPUT->send('compose');
912
913?>
Note: See TracBrowser for help on using the repository browser.