source: github/program/steps/mail/compose.inc @ 8fa58e7

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

New class rcube_message representing a mail message; changed global $MESSAGE from array to object

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