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

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