4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2008, 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 2161 2008-12-16 17:01:50Z thomasb $
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);
386 // replace cid with href in inline images links
387 foreach ((array)$_SESSION['compose']['attachments'] as $pid => $attachment) {
388 if ($attachment['content_id']) {
389 $body = str_replace('cid:'. $attachment['content_id'],
390 $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$pid, $body);
395 else if (!empty($_SESSION['compose']['param']['_body']))
397 $body = $_SESSION['compose']['param']['_body'];
400 $out = $form_start ? "$form_start\n" : '';
402 $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : ''));
403 $out .= $saveid->show();
405 $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes'));
406 $out .= $drafttoggle->show();
408 $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
409 $out .= $msgtype->show();
411 // If desired, set this textarea to be editable by TinyMCE
412 if ($isHtml) $attrib['class'] = 'mce_editor';
413 $textarea = new html_textarea($attrib);
414 $out .= $textarea->show($body);
415 $out .= $form_end ? "\n$form_end" : '';
417 // include HTML editor
420 // include GoogieSpell
421 if (!empty($CONFIG['enable_spellcheck'])) {
423 $lang = strtolower(substr($_SESSION['language'], 0, 2));
425 $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'));
426 if (!$spellcheck_langs[$lang])
429 $editor_lang_set = array();
430 foreach ($spellcheck_langs as $key => $name) {
431 $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key);
434 $OUTPUT->include_script('googiespell.js');
435 $OUTPUT->add_script(sprintf(
436 "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
437 "googie.lang_chck_spell = \"%s\";\n".
438 "googie.lang_rsm_edt = \"%s\";\n".
439 "googie.lang_close = \"%s\";\n".
440 "googie.lang_revert = \"%s\";\n".
441 "googie.lang_no_error_found = \"%s\";\n".
442 "googie.setLanguages(%s);\n".
443 "googie.setCurrentLanguage('%s');\n".
444 "googie.decorateTextarea('%s');\n".
445 "%s.set_env('spellcheck', googie);",
447 JQ(Q(rcube_label('checkspelling'))),
448 JQ(Q(rcube_label('resumeediting'))),
449 JQ(Q(rcube_label('close'))),
450 JQ(Q(rcube_label('revertto'))),
451 JQ(Q(rcube_label('nospellerrors'))),
452 json_serialize($spellcheck_langs),
455 JS_OBJECT_NAME), 'foot');
457 $OUTPUT->add_label('checking');
458 $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
461 $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
467 function rcmail_create_reply_body($body, $bodyIsHtml)
469 global $IMAP, $MESSAGE, $OUTPUT;
473 // try to remove the signature
474 if (($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n"))
476 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
477 $body = substr($body, 0, max(0, $sp-1));
480 // soft-wrap message first
481 $body = rcmail_wrap_quoted($body, 75);
483 $body = rtrim($body, "\r\n");
486 // split body into single lines
487 $a_lines = preg_split('/\r?\n/', $body);
489 // add > to each line
490 for($n=0; $n<sizeof($a_lines); $n++) {
491 if (strpos($a_lines[$n], '>')===0)
492 $a_lines[$n] = '>'.$a_lines[$n];
494 $a_lines[$n] = '> '.$a_lines[$n];
497 $body = join("\n", $a_lines);
501 $prefix = wordwrap(sprintf("On %s, %s wrote:\n",
502 $MESSAGE->headers->date,
503 $MESSAGE->get_header('from')), 76);
509 $prefix = sprintf("On %s, %s wrote:<br />\n",
510 $MESSAGE->headers->date,
511 htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
512 $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
513 $suffix = "</blockquote><p></p>";
515 rcmail_write_inline_attachments($MESSAGE);
518 return $prefix.$body.$suffix;
522 function rcmail_create_forward_body($body, $bodyIsHtml)
524 global $IMAP, $MESSAGE, $OUTPUT;
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";
540 "<br><br>-------- Original Message --------" .
541 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
542 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
543 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
544 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
545 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>",
546 Q($MESSAGE->subject),
547 Q($MESSAGE->headers->date),
548 htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true),
549 htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
551 if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from)
552 $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Reply-To: </th><td>%s</td></tr>",
553 htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
555 $prefix .= "</tbody></table><br>";
559 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts))
560 rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
562 return $prefix.$body;
566 function rcmail_create_draft_body($body, $bodyIsHtml)
572 * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text!
574 if (!isset($_SESSION['compose']['forward_attachments'])
575 && is_array($MESSAGE->mime_parts)
576 && count($MESSAGE->mime_parts) > 0)
577 rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
583 function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
585 foreach ((array)$message->mime_parts as $pid => $part)
587 if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
588 ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id']
589 || (empty($part->disposition) && $part->filename)))
591 if ($attachment = rcmail_save_attachment($message, $pid))
592 $_SESSION['compose']['attachments'][] = $attachment;
596 $_SESSION['compose']['forward_attachments'] = true;
600 function rcmail_write_inline_attachments(&$message)
602 foreach ((array)$message->mime_parts as $pid => $part)
604 if ($part->content_id && $part->filename)
606 if ($attachment = rcmail_save_attachment($message, $pid))
607 $_SESSION['compose']['attachments'][] = $attachment;
612 function rcmail_save_attachment(&$message, $pid)
616 $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
617 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
618 $part = $message->mime_parts[$pid];
620 if ($fp = fopen($tmp_path, 'w'))
622 $message->get_part_content($pid, $fp);
626 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
627 'name' => $part->filename,
629 'content_id' => $part->content_id
635 function rcmail_compose_subject($attrib)
637 global $MESSAGE, $compose_mode;
639 list($form_start, $form_end) = get_form_tags($attrib);
640 unset($attrib['form']);
642 $attrib['name'] = '_subject';
643 $attrib['spellcheck'] = 'true';
644 $textfield = new html_inputfield($attrib);
648 // use subject from post
649 if (isset($_POST['_subject'])) {
650 $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
652 // create a reply-subject
653 else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
654 if (eregi('^re:', $MESSAGE->subject))
655 $subject = $MESSAGE->subject;
657 $subject = 'Re: '.$MESSAGE->subject;
659 // create a forward-subject
660 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
661 if (eregi('^fwd:', $MESSAGE->subject))
662 $subject = $MESSAGE->subject;
664 $subject = 'Fwd: '.$MESSAGE->subject;
666 // creeate a draft-subject
667 else if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
668 $subject = $MESSAGE->subject;
670 else if (!empty($_SESSION['compose']['param']['_subject'])) {
671 $subject = $_SESSION['compose']['param']['_subject'];
674 $out = $form_start ? "$form_start\n" : '';
675 $out .= $textfield->show($subject);
676 $out .= $form_end ? "\n$form_end" : '';
682 function rcmail_compose_attachment_list($attrib)
684 global $OUTPUT, $CONFIG;
686 // add ID if not given
688 $attrib['id'] = 'rcmAttachmentList';
692 if (is_array($_SESSION['compose']['attachments']))
694 if ($attrib['deleteicon'])
695 $button = html::img(array(
696 'src' => $CONFIG['skin_path'] . $attrib['deleteicon'],
697 'alt' => rcube_label('delete'),
698 'style' => "padding-right:2px;vertical-align:middle"));
700 $button = Q(rcube_label('delete'));
702 foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
707 $out .= html::tag('li', array('id' => "rcmfile".$id),
710 'title' => rcube_label('delete'),
711 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
712 $button) . Q($a_prop['name']));
716 $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
718 return html::tag('ul', $attrib, $out, html::$common_attrib);
722 function rcmail_compose_attachment_form($attrib)
726 // add ID if not given
728 $attrib['id'] = 'rcmUploadbox';
730 $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
732 $out = html::div($attrib,
733 $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data'),
734 html::div(null, rcmail_compose_attachment_field(array())) .
735 html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))))) .
737 $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . ' ' .
738 $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)"))
743 $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
748 function rcmail_compose_attachment_field($attrib)
750 $attrib['type'] = 'file';
751 $attrib['name'] = '_attachments[]';
752 $field = new html_inputfield($attrib);
753 return $field->show();
757 function rcmail_priority_selector($attrib)
761 list($form_start, $form_end) = get_form_tags($attrib);
762 unset($attrib['form']);
764 $attrib['name'] = '_priority';
765 $selector = new html_select($attrib);
767 $selector->add(array(rcube_label('lowest'),
769 rcube_label('normal'),
771 rcube_label('highest')),
772 array(5, 4, 0, 2, 1));
774 $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority);
776 $out = $form_start ? "$form_start\n" : '';
777 $out .= $selector->show($sel);
778 $out .= $form_end ? "\n$form_end" : '';
784 function rcmail_receipt_checkbox($attrib)
786 global $MESSAGE, $compose_mode;
788 list($form_start, $form_end) = get_form_tags($attrib);
789 unset($attrib['form']);
791 if (!isset($attrib['id']))
792 $attrib['id'] = 'receipt';
794 $attrib['name'] = '_receipt';
795 $attrib['value'] = '1';
796 $checkbox = new html_checkbox($attrib);
798 $out = $form_start ? "$form_start\n" : '';
799 $out .= $checkbox->show(
800 $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0);
801 $out .= $form_end ? "\n$form_end" : '';
807 function rcmail_editor_selector($attrib)
809 global $CONFIG, $MESSAGE, $compose_mode;
812 'html' => 'htmltoggle',
813 'plain' => 'plaintoggle'
816 // determine whether HTML or plain text should be checked
817 $useHtml = $CONFIG['htmleditor'] ? true : false;
820 $useHtml = ($useHtml && $MESSAGE->has_html_part());
822 $editorid = empty($attrib['editorid']) ? 'rcmComposeMessage' : $attrib['editorid'];
825 $chosenvalue = $useHtml ? 'html' : 'plain';
826 $radio = new html_radiobutton(array('name' => '_editorSelect',
827 'onclick' => "return rcmail_toggle_editor(this.value=='html', '$editorid', '_is_html')"));
829 foreach ($choices as $value => $text)
831 $attrib['id'] = '_' . $value;
832 $attrib['value'] = $value;
833 $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text)));
840 function rcmail_store_target_selection($attrib)
842 $attrib['name'] = '_store_target';
843 $select = rcmail_mailbox_select(array_merge($attrib, array('noselection' => '- '.rcube_label('dontsave').' -')));
844 return $select->show(rcmail::get_instance()->config->get('sent_mbox'), $attrib);
848 function get_form_tags($attrib)
850 global $RCMAIL, $MESSAGE_FORM;
853 if (!strlen($MESSAGE_FORM))
855 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
856 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
858 $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
859 $form_start .= $hiddenfields->show();
862 $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
863 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
865 if (!strlen($MESSAGE_FORM))
866 $RCMAIL->output->add_gui_object('messageform', $form_name);
868 $MESSAGE_FORM = $form_name;
870 return array($form_start, $form_end);
874 // register UI objects
875 $OUTPUT->add_handlers(array(
876 'composeheaders' => 'rcmail_compose_headers',
877 'composesubject' => 'rcmail_compose_subject',
878 'composebody' => 'rcmail_compose_body',
879 'composeattachmentlist' => 'rcmail_compose_attachment_list',
880 'composeattachmentform' => 'rcmail_compose_attachment_form',
881 'composeattachment' => 'rcmail_compose_attachment_field',
882 'priorityselector' => 'rcmail_priority_selector',
883 'editorselector' => 'rcmail_editor_selector',
884 'receiptcheckbox' => 'rcmail_receipt_checkbox',
885 'storetarget' => 'rcmail_store_target_selection',
888 $OUTPUT->send('compose');