4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005, 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 579 2007-05-18 13:11:22Z thomasb $
22 require_once('Mail/mimeDecode.php');
23 require_once('lib/html2text.inc');
25 // define constants for message compose mode
26 define('RCUBE_COMPOSE_REPLY', 0x0106);
27 define('RCUBE_COMPOSE_FORWARD', 0x0107);
28 define('RCUBE_COMPOSE_DRAFT', 0x0108);
31 // remove an attachment
32 if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
35 if (is_array($_SESSION['compose']['attachments'][$id]))
37 @unlink($_SESSION['compose']['attachments'][$id]['path']);
38 $_SESSION['compose']['attachments'][$id] = NULL;
39 $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
45 // this version does not support HTML mails
46 $CONFIG['htmleditor'] = false;
51 // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
52 // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
53 // Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
54 // compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
56 if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
58 rcmail_compose_cleanup();
59 $_SESSION['compose'] = array('id' => uniqid(rand()));
62 // add some labels to client
63 rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
65 // add config parameter to client script
66 $OUTPUT->set_env('draft_autosave', !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0);
69 // get reference message and set compose mode
70 if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET))
71 $compose_mode = RCUBE_COMPOSE_REPLY;
72 else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET))
73 $compose_mode = RCUBE_COMPOSE_FORWARD;
74 else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET))
75 $compose_mode = RCUBE_COMPOSE_DRAFT;
80 // similar as in program/steps/mail/show.inc
81 $MESSAGE = array('UID' => $msg_uid);
82 $MESSAGE['headers'] = &$IMAP->get_headers($msg_uid);
83 $MESSAGE['structure'] = &$IMAP->get_structure($msg_uid);
84 $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
85 $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']);
87 if ($compose_mode == RCUBE_COMPOSE_REPLY)
89 $_SESSION['compose']['reply_uid'] = $msg_uid;
90 $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID;
91 $_SESSION['compose']['references'] = $MESSAGE['headers']->reference;
92 $_SESSION['compose']['references'] .= !empty($MESSAGE['headers']->reference) ? ' ' : '';
93 $_SESSION['compose']['references'] .= $MESSAGE['headers']->messageID;
95 if (!empty($_GET['_all']))
96 $MESSAGE['reply_all'] = 1;
98 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
100 $_SESSION['compose']['forward_uid'] = $msg_uid;
102 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
104 $_SESSION['compose']['draft_uid'] = $msg_uid;
109 /****** compose mode functions ********/
112 function rcmail_compose_headers($attrib)
114 global $IMAP, $MESSAGE, $DB, $compose_mode;
115 static $sa_recipients = array();
117 list($form_start, $form_end) = get_form_tags($attrib);
120 $part = strtolower($attrib['part']);
125 return rcmail_compose_header_from($attrib);
131 // we have a set of recipients stored is session
132 if (($mailto_id = get_input_value('_mailto', RCUBE_INPUT_GET)) && $_SESSION['mailto'][$mailto_id])
133 $fvalue = $_SESSION['mailto'][$mailto_id];
134 else if (!empty($_GET['_to']))
135 $fvalue = get_input_value('_to', RCUBE_INPUT_GET);
150 $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex');
151 $field_type = 'textarea';
157 $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
158 $field_type = 'textfield';
163 if ($fname && !empty($_POST[$fname]))
164 $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
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);
190 foreach ($to_addresses as $addr_part)
192 if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM'])))
194 $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
195 $sa_recipients[] = $addr_part['mailto'];
200 else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT)
202 // get drafted headers
203 if ($header=='to' && !empty($MESSAGE['headers']->to))
204 $fvalue = $IMAP->decode_header($MESSAGE['headers']->to);
206 if ($header=='cc' && !empty($MESSAGE['headers']->cc))
207 $fvalue = $IMAP->decode_header($MESSAGE['headers']->cc);
209 if ($header=='bcc' && !empty($MESSAGE['headers']->bcc))
210 $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc);
214 if ($fname && $field_type)
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;
222 // create teaxtarea object
223 $input = new $field_type($field_attrib);
224 $out = $input->show($fvalue);
228 $out = $form_start.$out;
235 function rcmail_compose_header_from($attrib)
237 global $IMAP, $MESSAGE, $DB, $OUTPUT, $compose_mode;
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;
245 // extract all recipients of the reply-message
246 $a_recipients = array();
247 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers']))
249 $MESSAGE['FROM'] = array();
251 $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to);
252 foreach ($a_to as $addr)
254 if (!empty($addr['mailto']))
255 $a_recipients[] = $addr['mailto'];
258 if (!empty($MESSAGE['headers']->cc))
260 $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc);
261 foreach ($a_cc as $addr)
263 if (!empty($addr['mailto']))
264 $a_recipients[] = $addr['mailto'];
269 // get this user's identities
270 $sql_result = $DB->query("SELECT identity_id, name, email, signature, html_signature
271 FROM ".get_table_name('identities')."
274 ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC",
275 $_SESSION['user_id']);
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 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 $plainTextPart = $h2t->get_text();
299 $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart);
303 // set identity if it's one of the reply-message recipients
304 if (in_array($sql_arr['email'], $a_recipients))
305 $from_id = $sql_arr['identity_id'];
307 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE['FROM']))
308 $MESSAGE['FROM'][] = $sql_arr['email'];
310 if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email']))
311 $from_id = $sql_arr['identity_id'];
314 // overwrite identity selection with post parameter
315 if (isset($_POST['_from']))
316 $from_id = get_input_value('_from', RCUBE_INPUT_POST);
318 $out = $select_from->show($from_id);
320 // add signatures to client
321 $OUTPUT->set_env('signatures', $a_signatures);
325 $input_from = new textfield($field_attrib);
326 $out = $input_from->show($_POST['_from']);
330 $out = $form_start.$out;
337 function rcmail_compose_body($attrib)
339 global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
341 list($form_start, $form_end) = get_form_tags($attrib);
342 unset($attrib['form']);
344 if (empty($attrib['id']))
345 $attrib['id'] = 'rcmComposeMessage';
347 $attrib['name'] = '_message';
349 if ($CONFIG['htmleditor'])
356 // use posted message body
357 if (!empty($_POST['_message']))
359 $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE);
361 // compose reply-body
362 else if ($compose_mode == RCUBE_COMPOSE_REPLY)
364 $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
365 if ($hasHtml && $CONFIG['htmleditor'])
367 $body = rcmail_first_html_part($MESSAGE);
372 $body = rcmail_first_text_part($MESSAGE);
376 $body = rcmail_create_reply_body($body, $isHtml);
378 // forward message body inline
379 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
381 $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
382 if ($hasHtml && $CONFIG['htmleditor'])
384 $body = rcmail_first_html_part($MESSAGE);
389 $body = rcmail_first_text_part($MESSAGE);
393 $body = rcmail_create_forward_body($body, $isHtml);
395 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
397 $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
398 if ($hasHtml && $CONFIG['htmleditor'])
400 $body = rcmail_first_html_part($MESSAGE);
405 $body = rcmail_first_text_part($MESSAGE);
409 $body = rcmail_create_draft_body($body, $isHtml);
412 $out = $form_start ? "$form_start\n" : '';
414 $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE['headers']->messageID) : ''));
415 $out .= $saveid->show();
417 $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes'));
418 $out .= $drafttoggle->show();
420 $msgtype = new hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
421 $out .= $msgtype->show();
423 // If desired, set this text area to be editable by TinyMCE
425 $attrib['mce_editable'] = "true";
426 $textarea = new textarea($attrib);
427 $out .= $textarea->show($body);
428 $out .= $form_end ? "\n$form_end" : '';
430 // include GoogieSpell
431 if (!empty($CONFIG['enable_spellcheck']) && !$isHtml)
434 if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages']))
435 $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n";
437 $OUTPUT->include_script('googiespell.js');
438 $OUTPUT->add_script(sprintf(
439 "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
440 "googie.lang_chck_spell = \"%s\";\n".
441 "googie.lang_rsm_edt = \"%s\";\n".
442 "googie.lang_close = \"%s\";\n".
443 "googie.lang_revert = \"%s\";\n".
444 "googie.lang_no_error_found = \"%s\";\n%s".
445 "googie.setCurrentLanguage('%s');\n".
446 "googie.decorateTextarea('%s');\n".
447 "%s.set_env('spellcheck', googie);",
448 $GLOBALS['COMM_PATH'],
449 JQ(Q(rcube_label('checkspelling'))),
450 JQ(Q(rcube_label('resumeediting'))),
451 JQ(Q(rcube_label('close'))),
452 JQ(Q(rcube_label('revertto'))),
453 JQ(Q(rcube_label('nospellerrors'))),
455 substr($_SESSION['user_lang'], 0, 2),
457 JS_OBJECT_NAME), 'foot');
459 rcube_add_label('checking');
462 $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
468 function rcmail_create_reply_body($body, $bodyIsHtml)
470 global $IMAP, $MESSAGE;
474 // soft-wrap message first
475 $body = wordwrap($body, 75);
477 // split body into single lines
478 $a_lines = preg_split('/\r?\n/', $body);
480 // add > to each line
481 for($n=0; $n<sizeof($a_lines); $n++)
483 if (strpos($a_lines[$n], '>')===0)
484 $a_lines[$n] = '>'.$a_lines[$n];
486 $a_lines[$n] = '> '.$a_lines[$n];
489 $body = join("\n", $a_lines);
492 $prefix = sprintf("\n\n\nOn %s, %s wrote:\n",
493 $MESSAGE['headers']->date,
494 $IMAP->decode_header($MESSAGE['headers']->from));
496 // try to remove the signature
497 if ($sp = strrstr($body, '-- '))
499 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
500 $body = substr($body, 0, $sp-1);
506 $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " .
507 "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " .
508 "margin-left: 5px; width: 100%%\">",
509 $MESSAGE['headers']->date,
510 $IMAP->decode_header($MESSAGE['headers']->from));
512 $suffix = "</blockquote>";
515 return $prefix.$body.$suffix;
519 function rcmail_create_forward_body($body, $bodyIsHtml)
521 global $IMAP, $MESSAGE;
525 // soft-wrap message first
526 $body = wordwrap($body, 80);
528 $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
530 $MESSAGE['headers']->date,
531 $IMAP->decode_header($MESSAGE['headers']->from),
532 $IMAP->decode_header($MESSAGE['headers']->to));
537 "<br><br>-------- Original Message --------" .
538 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
539 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
540 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
541 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
542 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" .
543 "</tbody></table><br>",
544 Q($MESSAGE['subject']),
545 Q($MESSAGE['headers']->date),
546 Q($IMAP->decode_header($MESSAGE['headers']->from)),
547 Q($IMAP->decode_header($MESSAGE['headers']->to)));
551 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE['parts']))
552 rcmail_write_compose_attachments($MESSAGE);
554 return $prefix.$body;
558 function rcmail_create_draft_body($body, $bodyIsHtml)
560 global $IMAP, $MESSAGE;
563 if (!isset($_SESSION['compose']['forward_attachments']) &&
564 is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1)
565 rcmail_write_compose_attachments($MESSAGE);
571 function rcmail_write_compose_attachments(&$message)
573 global $IMAP, $CONFIG;
575 $temp_dir = unslashify($CONFIG['temp_dir']);
577 if (!is_array($_SESSION['compose']['attachments']))
578 $_SESSION['compose']['attachments'] = array();
580 foreach ($message['parts'] as $pid => $part)
582 if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' &&
583 ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
584 (empty($part->disposition) && $part->filename)))
586 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
587 if ($fp = fopen($tmp_path, 'w'))
589 fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding));
592 $_SESSION['compose']['attachments'][] = array(
593 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
594 'name' => $part->filename,
601 $_SESSION['compose']['forward_attachments'] = TRUE;
605 function rcmail_compose_subject($attrib)
607 global $CONFIG, $MESSAGE, $compose_mode;
609 list($form_start, $form_end) = get_form_tags($attrib);
610 unset($attrib['form']);
612 $attrib['name'] = '_subject';
613 $textfield = new textfield($attrib);
617 // use subject from post
618 if (isset($_POST['_subject']))
619 $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
621 // create a reply-subject
622 else if ($compose_mode == RCUBE_COMPOSE_REPLY)
624 if (eregi('^re:', $MESSAGE['subject']))
625 $subject = $MESSAGE['subject'];
627 $subject = 'Re: '.$MESSAGE['subject'];
630 // create a forward-subject
631 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
633 if (eregi('^fwd:', $MESSAGE['subject']))
634 $subject = $MESSAGE['subject'];
636 $subject = 'Fwd: '.$MESSAGE['subject'];
639 // creeate a draft-subject
640 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
641 $subject = $MESSAGE['subject'];
643 $out = $form_start ? "$form_start\n" : '';
644 $out .= $textfield->show($subject);
645 $out .= $form_end ? "\n$form_end" : '';
651 function rcmail_compose_attachment_list($attrib)
653 global $OUTPUT, $CONFIG;
655 // add ID if not given
657 $attrib['id'] = 'rcmAttachmentList';
659 // allow the following attributes to be added to the <ul> tag
660 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
662 $out = '<ul'. $attrib_str . ">\n";
664 if (is_array($_SESSION['compose']['attachments']))
666 if ($attrib['deleteicon'])
667 $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />',
668 $CONFIG['skin_path'],
669 $attrib['deleteicon'],
670 rcube_label('delete'));
672 $button = rcube_label('delete');
674 foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
675 $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>',
679 Q(rcube_label('delete')),
684 $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
692 function rcmail_compose_attachment_form($attrib)
694 global $OUTPUT, $SESS_HIDDEN_FIELD;
696 // add ID if not given
698 $attrib['id'] = 'rcmUploadbox';
700 // allow the following attributes to be added to the <div> tag
701 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
702 $input_field = rcmail_compose_attachment_field(array());
703 $label_send = rcube_label('upload');
704 $label_close = rcube_label('close');
705 $js_instance = JS_OBJECT_NAME;
709 <form action="./" method="post" enctype="multipart/form-data">
712 <input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" />
713 <input type="button" value="$label_send" class="button" onclick="$js_instance.command('send-attachment', this.form)" />
719 $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
724 function rcmail_compose_attachment_field($attrib)
726 // allow the following attributes to be added to the <input> tag
727 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
729 $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
734 function rcmail_priority_selector($attrib)
736 list($form_start, $form_end) = get_form_tags($attrib);
737 unset($attrib['form']);
739 $attrib['name'] = '_priority';
740 $selector = new select($attrib);
742 $selector->add(array(rcube_label('lowest'),
744 rcube_label('normal'),
746 rcube_label('highest')),
747 array(5, 4, 0, 2, 1));
749 $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0;
751 $out = $form_start ? "$form_start\n" : '';
752 $out .= $selector->show($sel);
753 $out .= $form_end ? "\n$form_end" : '';
759 function rcmail_receipt_checkbox($attrib)
761 list($form_start, $form_end) = get_form_tags($attrib);
762 unset($attrib['form']);
764 if (!isset($attrib['id']))
765 $attrib['id'] = 'receipt';
767 $attrib['name'] = '_receipt';
768 $attrib['value'] = '1';
769 $checkbox = new checkbox($attrib);
771 $out = $form_start ? "$form_start\n" : '';
772 $out .= $checkbox->show(0);
773 $out .= $form_end ? "\n$form_end" : '';
779 function rcmail_editor_selector($attrib)
781 global $CONFIG, $MESSAGE, $compose_mode;
784 'html' => 'htmltoggle',
785 'plain' => 'plaintoggle'
788 // determine whether HTML or plain text should be checked
789 if ($CONFIG['htmleditor'])
794 if ($compose_mode == RCUBE_COMPOSE_REPLY ||
795 $compose_mode == RCUBE_COMPOSE_FORWARD ||
796 $compose_mode == RCUBE_COMPOSE_DRAFT)
798 $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
799 $useHtml = ($hasHtml && $CONFIG['htmleditor']);
804 $attrib['name'] = '_editorSelect';
805 $attrib['onchange'] = 'return rcmail_toggle_editor(this)';
806 foreach ($choices as $value => $text)
809 if ((($value == 'html') && $useHtml) ||
810 (($value != 'html') && !$useHtml))
811 $attrib['checked'] = 'true';
813 unset($attrib['checked']);
815 $attrib['id'] = '_' . $value;
816 $rb = new radiobutton($attrib);
817 $selector .= sprintf("%s<label for=\"%s\">%s</label>",
827 function get_form_tags($attrib)
829 global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;
832 if (!strlen($MESSAGE_FORM))
834 $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
835 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
837 $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
838 $form_start .= "\n$SESS_HIDDEN_FIELD\n";
839 $form_start .= $hiddenfields->show();
842 $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
843 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
845 if (!strlen($MESSAGE_FORM))
846 $OUTPUT->add_gui_object('messageform', $form_name);
848 $MESSAGE_FORM = $form_name;
850 return array($form_start, $form_end);
854 // register UI objects
855 $OUTPUT->add_handlers(array(
856 'composeheaders' => 'rcmail_compose_headers',
857 'composesubject' => 'rcmail_compose_subject',
858 'composebody' => 'rcmail_compose_body',
859 'composeattachmentlist' => 'rcmail_compose_attachment_list',
860 'composeattachmentform' => 'rcmail_compose_attachment_form',
861 'composeattachment' => 'rcmail_compose_attachment_field',
862 'priorityselector' => 'rcmail_priority_selector',
863 'receiptcheckbox' => 'rcmail_receipt_checkbox',
867 /****** get contacts for this user and add them to client scripts ********/
869 require_once('include/rcube_contacts.inc');
871 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
872 $CONTACTS->set_pagesize(1000);
874 if ($result = $CONTACTS->list_records())
876 $a_contacts = array();
877 while ($sql_arr = $result->iterate())
878 if ($sql_arr['email'])
879 $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
881 $OUTPUT->set_env('contacts', $a_contacts);
885 parse_template('compose');