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

Last change on this file since 1562 was 1562, checked in by thomasb, 5 years ago

Store compose parameters in session and redirect to a unique URL

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