4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Compose a new mail message with all headers and attachments |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: compose.inc 2301 2009-02-18 19:15:36Z alec $
22 // define constants for message compose mode
23 define('RCUBE_COMPOSE_REPLY', 0x0106);
24 define('RCUBE_COMPOSE_FORWARD', 0x0107);
25 define('RCUBE_COMPOSE_DRAFT', 0x0108);
30 // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
31 // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
32 // Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
33 // compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
35 if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
37 rcmail_compose_cleanup();
38 $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET));
40 // process values like "mailto:foo@bar.com?subject=new+message&cc=another"
41 if ($_SESSION['compose']['param']['_to']) {
42 $mailto = explode('?', $_SESSION['compose']['param']['_to']);
43 if (count($mailto) > 1) {
44 $_SESSION['compose']['param']['_to'] = $mailto[0];
45 parse_str($mailto[1], $query);
46 foreach ($query as $f => $val)
47 $_SESSION['compose']['param']["_$f"] = $val;
51 // redirect to a unique URL with all parameters stored in session
52 $OUTPUT->redirect(array('_action' => 'compose', '_id' => $_SESSION['compose']['id']));
55 // add some labels to client
56 $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning',
57 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved',
58 'converting', 'editorwarning', 'searching');
60 // add config parameters to client script
61 if (!empty($CONFIG['drafts_mbox'])) {
62 $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
63 $OUTPUT->set_env('draft_autosave', $CONFIG['draft_autosave']);
65 // set current mailbox in client environment
66 $OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name());
68 // get reference message and set compose mode
69 if ($msg_uid = $_SESSION['compose']['param']['_reply_uid'])
70 $compose_mode = RCUBE_COMPOSE_REPLY;
71 else if ($msg_uid = $_SESSION['compose']['param']['_forward_uid'])
72 $compose_mode = RCUBE_COMPOSE_FORWARD;
73 else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid'])
74 $compose_mode = RCUBE_COMPOSE_DRAFT;
78 // similar as in program/steps/mail/show.inc
79 $MESSAGE = new rcube_message($msg_uid);
81 if (!empty($MESSAGE->headers->charset))
82 $IMAP->set_charset($MESSAGE->headers->charset);
84 if ($compose_mode == RCUBE_COMPOSE_REPLY)
86 $_SESSION['compose']['reply_uid'] = $msg_uid;
87 $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID;
88 $_SESSION['compose']['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
90 if (!empty($_SESSION['compose']['param']['_all']))
91 $MESSAGE->reply_all = 1;
93 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
95 if($MESSAGE->headers->in_reply_to)
97 // TODO: how to get reply_uid/forward_uid value, maybe we must set X-Reply-UID/X-Forward-UID
98 // $_SESSION['compose']['reply_uid'] = ?
99 // $_SESSION['compose']['forward_uid'] = ?
100 $_SESSION['compose']['reply_msgid'] = '<'.$MESSAGE->headers->in_reply_to.'>';
102 $_SESSION['compose']['references'] = $MESSAGE->headers->references;
104 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
106 $_SESSION['compose']['forward_uid'] = $msg_uid;
110 /****** compose mode functions ********/
113 function rcmail_compose_headers($attrib)
115 global $IMAP, $MESSAGE, $DB, $compose_mode;
116 static $sa_recipients = array();
118 list($form_start, $form_end) = get_form_tags($attrib);
121 $part = strtolower($attrib['part']);
126 return rcmail_compose_header_from($attrib);
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]);
149 $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex');
150 $field_type = 'html_textarea';
156 $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
157 $field_type = 'html_inputfield';
161 if ($fname && !empty($_POST[$fname]))
162 $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
163 else if ($fname && !$fvalue && !empty($_SESSION['compose']['param'][$fname]))
164 $fvalue = $_SESSION['compose']['param'][$fname];
166 else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY)
168 // get recipent address(es) out of the message headers
169 if ($header=='to' && !empty($MESSAGE->headers->replyto))
170 $fvalue = $MESSAGE->headers->replyto;
172 else if ($header=='to' && !empty($MESSAGE->headers->from))
173 $fvalue = $MESSAGE->headers->from;
175 // add recipent of original message if reply to all
176 else if ($header=='cc' && !empty($MESSAGE->reply_all))
178 if ($v = $MESSAGE->headers->to)
181 if ($v = $MESSAGE->headers->cc)
182 $fvalue .= (!empty($fvalue) ? ', ' : '') . $v;
185 // split recipients and put them back together in a unique way
188 $to_addresses = $IMAP->decode_address_list($fvalue);
191 foreach ($to_addresses as $addr_part)
193 if (!empty($addr_part['mailto'])
194 && !in_array($addr_part['mailto'], $sa_recipients)
195 && (!$MESSAGE->compose_from
196 || !in_array_nocase($addr_part['mailto'], $MESSAGE->compose_from)
197 || (count($to_addresses)==1 && $header=='to'))) // allow reply to yourself
199 $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
200 $sa_recipients[] = $addr_part['mailto'];
205 else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT)
207 // get drafted headers
208 if ($header=='to' && !empty($MESSAGE->headers->to))
209 $fvalue = $MESSAGE->get_header('to');
211 if ($header=='cc' && !empty($MESSAGE->headers->cc))
212 $fvalue = $MESSAGE->get_header('cc');
214 if ($header=='bcc' && !empty($MESSAGE->headers->bcc))
215 $fvalue = $MESSAGE->get_header('bcc');
219 if ($fname && $field_type)
221 // pass the following attributes to the form class
222 $field_attrib = array('name' => $fname, 'spellcheck' => 'false');
223 foreach ($attrib as $attr => $value)
224 if (in_array($attr, $allow_attrib))
225 $field_attrib[$attr] = $value;
227 // create teaxtarea object
228 $input = new $field_type($field_attrib);
229 $out = $input->show($fvalue);
233 $out = $form_start.$out;
240 function rcmail_compose_header_from($attrib)
242 global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode;
244 // pass the following attributes to the form class
245 $field_attrib = array('name' => '_from');
246 foreach ($attrib as $attr => $value)
247 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
248 $field_attrib[$attr] = $value;
250 // extract all recipients of the reply-message
251 $a_recipients = array();
252 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE->headers))
254 $MESSAGE->compose_from = array();
256 $a_to = $IMAP->decode_address_list($MESSAGE->headers->to);
257 foreach ($a_to as $addr)
259 if (!empty($addr['mailto']))
260 $a_recipients[] = rc_strtolower($addr['mailto']);
263 if (!empty($MESSAGE->headers->cc))
265 $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc);
266 foreach ($a_cc as $addr)
268 if (!empty($addr['mailto']))
269 $a_recipients[] = rc_strtolower($addr['mailto']);
274 // get this user's identities
275 $sql_result = $USER->list_identities();
277 if ($DB->num_rows($sql_result))
280 $a_signatures = array();
282 $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)";
283 $select_from = new html_select($field_attrib);
285 while ($sql_arr = $DB->fetch_assoc($sql_result))
287 $identity_id = $sql_arr['identity_id'];
288 $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
290 // add signature to array
291 if (!empty($sql_arr['signature']))
293 $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
294 $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
295 if ($a_signatures[$identity_id]['is_html'])
297 $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
298 $a_signatures[$identity_id]['plain_text'] = trim($h2t->get_text());
302 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE->compose_from))
303 $MESSAGE->compose_from[] = $sql_arr['email'];
305 if (empty($_POST['_from']))
307 // set draft's identity
308 if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email']))
309 $from_id = $sql_arr['identity_id'];
310 // set identity if it's one of the reply-message recipients (with prio for default identity)
311 else if (in_array(rc_strtolower($sql_arr['email']), $a_recipients) && (empty($from_id) || $sql_arr['standard']))
312 $from_id = $sql_arr['identity_id'];
316 // overwrite identity selection with post parameter
317 if (!empty($_POST['_from']))
318 $from_id = get_input_value('_from', RCUBE_INPUT_POST);
320 $out = $select_from->show($from_id);
322 // add signatures to client
323 $OUTPUT->set_env('signatures', $a_signatures);
327 $input_from = new html_inputfield($field_attrib);
328 $out = $input_from->show($_POST['_from']);
332 $out = $form_start.$out;
338 function rcmail_compose_body($attrib)
340 global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
342 list($form_start, $form_end) = get_form_tags($attrib);
343 unset($attrib['form']);
345 if (empty($attrib['id']))
346 $attrib['id'] = 'rcmComposeMessage';
348 $attrib['name'] = '_message';
350 if ($CONFIG['htmleditor'])
357 // use posted message body
358 if (!empty($_POST['_message']))
360 $body = get_input_value('_message', RCUBE_INPUT_POST, true);
362 else if ($compose_mode)
364 if ($isHtml && $MESSAGE->has_html_part())
366 $body = $MESSAGE->first_html_part();
371 $body = $MESSAGE->first_text_part();
375 // compose reply-body
376 if ($compose_mode == RCUBE_COMPOSE_REPLY)
377 $body = rcmail_create_reply_body($body, $isHtml);
378 // forward message body inline
379 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
380 $body = rcmail_create_forward_body($body, $isHtml);
381 // load draft message body
382 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
383 $body = rcmail_create_draft_body($body, $isHtml);
385 else if (!empty($_SESSION['compose']['param']['_body']))
387 $body = $_SESSION['compose']['param']['_body'];
390 $out = $form_start ? "$form_start\n" : '';
392 $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : ''));
393 $out .= $saveid->show();
395 $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes'));
396 $out .= $drafttoggle->show();
398 $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
399 $out .= $msgtype->show();
401 // If desired, set this textarea to be editable by TinyMCE
402 if ($isHtml) $attrib['class'] = 'mce_editor';
403 $textarea = new html_textarea($attrib);
404 $out .= $textarea->show($body);
405 $out .= $form_end ? "\n$form_end" : '';
407 // include HTML editor
410 // include GoogieSpell
411 if (!empty($CONFIG['enable_spellcheck'])) {
413 $lang = strtolower(substr($_SESSION['language'], 0, 2));
415 $spellcheck_langs = (array)$RCMAIL->config->get('spellcheck_languages', array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska'));
416 if (!$spellcheck_langs[$lang])
419 $editor_lang_set = array();
420 foreach ($spellcheck_langs as $key => $name) {
421 $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key);
424 $OUTPUT->include_script('googiespell.js');
425 $OUTPUT->add_script(sprintf(
426 "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
427 "googie.lang_chck_spell = \"%s\";\n".
428 "googie.lang_rsm_edt = \"%s\";\n".
429 "googie.lang_close = \"%s\";\n".
430 "googie.lang_revert = \"%s\";\n".
431 "googie.lang_no_error_found = \"%s\";\n".
432 "googie.setLanguages(%s);\n".
433 "googie.setCurrentLanguage('%s');\n".
434 "googie.decorateTextarea('%s');\n".
435 "%s.set_env('spellcheck', googie);",
437 JQ(Q(rcube_label('checkspelling'))),
438 JQ(Q(rcube_label('resumeediting'))),
439 JQ(Q(rcube_label('close'))),
440 JQ(Q(rcube_label('revertto'))),
441 JQ(Q(rcube_label('nospellerrors'))),
442 json_serialize($spellcheck_langs),
445 JS_OBJECT_NAME), 'foot');
447 $OUTPUT->add_label('checking');
448 $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
451 $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
457 function rcmail_create_reply_body($body, $bodyIsHtml)
459 global $IMAP, $MESSAGE, $OUTPUT;
463 // try to remove the signature
464 if (($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n"))
466 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
467 $body = substr($body, 0, max(0, $sp-1));
470 // soft-wrap message first
471 $body = rcmail_wrap_quoted($body, 75);
473 $body = rtrim($body, "\r\n");
476 // split body into single lines
477 $a_lines = preg_split('/\r?\n/', $body);
479 // add > to each line
480 for($n=0; $n<sizeof($a_lines); $n++) {
481 if (strpos($a_lines[$n], '>')===0)
482 $a_lines[$n] = '>'.$a_lines[$n];
484 $a_lines[$n] = '> '.$a_lines[$n];
487 $body = join("\n", $a_lines);
491 $prefix = wordwrap(sprintf("On %s, %s wrote:\n",
492 $MESSAGE->headers->date,
493 $MESSAGE->get_header('from')), 76);
499 // save inline images to files
500 $cid_map = rcmail_write_inline_attachments($MESSAGE);
501 // set is_safe flag (we need this for html body washing)
502 rcmail_check_safe($MESSAGE);
503 // clean up html tags
504 $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
506 // build reply (quote content)
507 $prefix = sprintf("On %s, %s wrote:<br />\n",
508 $MESSAGE->headers->date,
509 htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
510 $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
511 $suffix = "</blockquote><p></p>";
514 return $prefix.$body.$suffix;
518 function rcmail_create_forward_body($body, $bodyIsHtml)
520 global $IMAP, $MESSAGE, $OUTPUT;
523 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts))
524 $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
528 $prefix = "\n\n\n-------- Original Message --------\n";
529 $prefix .= 'Subject: ' . $MESSAGE->subject . "\n";
530 $prefix .= 'Date: ' . $MESSAGE->headers->date . "\n";
531 $prefix .= 'From: ' . $MESSAGE->get_header('from') . "\n";
532 $prefix .= 'To: ' . $MESSAGE->get_header('to') . "\n";
533 if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from)
534 $prefix .= 'Reply-To: ' . $MESSAGE->get_header('replyto') . "\n";
539 // set is_safe flag (we need this for html body washing)
540 rcmail_check_safe($MESSAGE);
541 // clean up html tags
542 $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
545 "<br><br>-------- Original Message --------" .
546 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
547 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
548 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
549 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
550 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>",
551 Q($MESSAGE->subject),
552 Q($MESSAGE->headers->date),
553 htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true),
554 htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
556 if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from)
557 $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Reply-To: </th><td>%s</td></tr>",
558 htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
560 $prefix .= "</tbody></table><br>";
563 return $prefix.$body;
567 function rcmail_create_draft_body($body, $bodyIsHtml)
569 global $MESSAGE, $OUTPUT;
573 * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text!
575 if (!isset($_SESSION['compose']['forward_attachments'])
576 && is_array($MESSAGE->mime_parts)
577 && count($MESSAGE->mime_parts) > 0)
579 $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
581 // replace cid with href in inline images links
583 $body = str_replace(array_keys($cid_map), array_values($cid_map), $body);
590 function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
597 foreach ((array)$message->mime_parts as $pid => $part)
599 if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
600 ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id']
601 || (empty($part->disposition) && $part->filename)))
603 if ($attachment = rcmail_save_attachment($message, $pid)) {
604 $_SESSION['compose']['attachments'][$id] = $attachment;
605 if ($bodyIsHtml && $part->filename && $part->content_id) {
606 $cid_map['cid:'.$part->content_id] =
607 $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
614 $_SESSION['compose']['forward_attachments'] = true;
620 function rcmail_write_inline_attachments(&$message)
627 foreach ((array)$message->mime_parts as $pid => $part) {
628 if ($part->content_id && $part->filename) {
629 if ($attachment = rcmail_save_attachment($message, $pid)) {
630 $_SESSION['compose']['attachments'][$id] = $attachment;
631 $cid_map['cid:'.$part->content_id] =
632 $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
641 function rcmail_save_attachment(&$message, $pid)
645 $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
646 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
647 $part = $message->mime_parts[$pid];
649 if ($fp = fopen($tmp_path, 'w'))
651 $message->get_part_content($pid, $fp);
655 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
656 'name' => $part->filename,
658 'content_id' => $part->content_id
664 function rcmail_compose_subject($attrib)
666 global $MESSAGE, $compose_mode;
668 list($form_start, $form_end) = get_form_tags($attrib);
669 unset($attrib['form']);
671 $attrib['name'] = '_subject';
672 $attrib['spellcheck'] = 'true';
673 $textfield = new html_inputfield($attrib);
677 // use subject from post
678 if (isset($_POST['_subject'])) {
679 $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
681 // create a reply-subject
682 else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
683 if (eregi('^re:', $MESSAGE->subject))
684 $subject = $MESSAGE->subject;
686 $subject = 'Re: '.$MESSAGE->subject;
688 // create a forward-subject
689 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
690 if (eregi('^fwd:', $MESSAGE->subject))
691 $subject = $MESSAGE->subject;
693 $subject = 'Fwd: '.$MESSAGE->subject;
695 // creeate a draft-subject
696 else if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
697 $subject = $MESSAGE->subject;
699 else if (!empty($_SESSION['compose']['param']['_subject'])) {
700 $subject = $_SESSION['compose']['param']['_subject'];
703 $out = $form_start ? "$form_start\n" : '';
704 $out .= $textfield->show($subject);
705 $out .= $form_end ? "\n$form_end" : '';
711 function rcmail_compose_attachment_list($attrib)
713 global $OUTPUT, $CONFIG;
715 // add ID if not given
717 $attrib['id'] = 'rcmAttachmentList';
721 if (is_array($_SESSION['compose']['attachments']))
723 if ($attrib['deleteicon'])
724 $button = html::img(array(
725 'src' => $CONFIG['skin_path'] . $attrib['deleteicon'],
726 'alt' => rcube_label('delete'),
727 'style' => "padding-right:2px;vertical-align:middle"));
729 $button = Q(rcube_label('delete'));
731 foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
736 $out .= html::tag('li', array('id' => "rcmfile".$id),
739 'title' => rcube_label('delete'),
740 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
741 $button) . Q($a_prop['name']));
745 $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
747 return html::tag('ul', $attrib, $out, html::$common_attrib);
751 function rcmail_compose_attachment_form($attrib)
755 // add ID if not given
757 $attrib['id'] = 'rcmUploadbox';
759 $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
761 $out = html::div($attrib,
762 $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data'),
763 html::div(null, rcmail_compose_attachment_field(array())) .
764 html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))))) .
766 $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . ' ' .
767 $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)"))
772 $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
777 function rcmail_compose_attachment_field($attrib)
779 $attrib['type'] = 'file';
780 $attrib['name'] = '_attachments[]';
781 $field = new html_inputfield($attrib);
782 return $field->show();
786 function rcmail_priority_selector($attrib)
790 list($form_start, $form_end) = get_form_tags($attrib);
791 unset($attrib['form']);
793 $attrib['name'] = '_priority';
794 $selector = new html_select($attrib);
796 $selector->add(array(rcube_label('lowest'),
798 rcube_label('normal'),
800 rcube_label('highest')),
801 array(5, 4, 0, 2, 1));
803 $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority);
805 $out = $form_start ? "$form_start\n" : '';
806 $out .= $selector->show($sel);
807 $out .= $form_end ? "\n$form_end" : '';
813 function rcmail_receipt_checkbox($attrib)
815 global $MESSAGE, $compose_mode;
817 list($form_start, $form_end) = get_form_tags($attrib);
818 unset($attrib['form']);
820 if (!isset($attrib['id']))
821 $attrib['id'] = 'receipt';
823 $attrib['name'] = '_receipt';
824 $attrib['value'] = '1';
825 $checkbox = new html_checkbox($attrib);
827 $out = $form_start ? "$form_start\n" : '';
828 $out .= $checkbox->show(
829 $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0);
830 $out .= $form_end ? "\n$form_end" : '';
836 function rcmail_editor_selector($attrib)
838 global $CONFIG, $MESSAGE, $compose_mode;
841 'html' => 'htmltoggle',
842 'plain' => 'plaintoggle'
845 // determine whether HTML or plain text should be checked
846 $useHtml = $CONFIG['htmleditor'] ? true : false;
849 $useHtml = ($useHtml && $MESSAGE->has_html_part());
851 $editorid = empty($attrib['editorid']) ? 'rcmComposeMessage' : $attrib['editorid'];
854 $chosenvalue = $useHtml ? 'html' : 'plain';
855 $radio = new html_radiobutton(array('name' => '_editorSelect',
856 'onclick' => "return rcmail_toggle_editor(this.value=='html', '$editorid', '_is_html')"));
858 foreach ($choices as $value => $text)
860 $attrib['id'] = '_' . $value;
861 $attrib['value'] = $value;
862 $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text)));
869 function rcmail_store_target_selection($attrib)
871 $attrib['name'] = '_store_target';
872 $select = rcmail_mailbox_select(array_merge($attrib, array('noselection' => '- '.rcube_label('dontsave').' -')));
873 return $select->show(rcmail::get_instance()->config->get('sent_mbox'), $attrib);
877 function get_form_tags($attrib)
879 global $RCMAIL, $MESSAGE_FORM;
882 if (!strlen($MESSAGE_FORM))
884 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
885 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
887 $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
888 $form_start .= $hiddenfields->show();
891 $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
892 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
894 if (!strlen($MESSAGE_FORM))
895 $RCMAIL->output->add_gui_object('messageform', $form_name);
897 $MESSAGE_FORM = $form_name;
899 return array($form_start, $form_end);
903 // register UI objects
904 $OUTPUT->add_handlers(array(
905 'composeheaders' => 'rcmail_compose_headers',
906 'composesubject' => 'rcmail_compose_subject',
907 'composebody' => 'rcmail_compose_body',
908 'composeattachmentlist' => 'rcmail_compose_attachment_list',
909 'composeattachmentform' => 'rcmail_compose_attachment_form',
910 'composeattachment' => 'rcmail_compose_attachment_field',
911 'priorityselector' => 'rcmail_priority_selector',
912 'editorselector' => 'rcmail_editor_selector',
913 'receiptcheckbox' => 'rcmail_receipt_checkbox',
914 'storetarget' => 'rcmail_store_target_selection',
917 $OUTPUT->send('compose');