source: github/program/steps/mail/compose.inc @ e7d37ae

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