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 1493 2008-06-08 18:17:09Z 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);
28 // remove an attachment
29 if ($RCMAIL->action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
32 if (is_array($_SESSION['compose']['attachments'][$id]))
34 @unlink($_SESSION['compose']['attachments'][$id]['path']);
35 $_SESSION['compose']['attachments'][$id] = NULL;
36 $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
42 if ($RCMAIL->action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
45 if (is_array($_SESSION['compose']['attachments'][$id]))
47 $apath = $_SESSION['compose']['attachments'][$id]['path'];
48 header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']);
49 header('Content-Length: ' . filesize($apath));
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
63 if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
65 rcmail_compose_cleanup();
66 $_SESSION['compose'] = array('id' => uniqid(rand()));
69 // add some labels to client
70 rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
72 // add config parameter to client script
73 $OUTPUT->set_env('draft_autosave', !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0);
76 // get reference message and set compose mode
77 if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET))
78 $compose_mode = RCUBE_COMPOSE_REPLY;
79 else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET))
80 $compose_mode = RCUBE_COMPOSE_FORWARD;
81 else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET))
82 $compose_mode = RCUBE_COMPOSE_DRAFT;
86 // similar as in program/steps/mail/show.inc
87 $MESSAGE = new rcube_message($msg_uid);
89 if (!empty($MESSAGE->headers->charset))
90 $IMAP->set_charset($MESSAGE->headers->charset);
92 if ($compose_mode == RCUBE_COMPOSE_REPLY)
94 $_SESSION['compose']['reply_uid'] = $msg_uid;
95 $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID;
96 $_SESSION['compose']['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
98 if (!empty($_GET['_all']))
99 $MESSAGE->reply_all = 1;
101 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
103 $_SESSION['compose']['forward_uid'] = $msg_uid;
105 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
107 $_SESSION['compose']['draft_uid'] = $msg_uid;
111 /****** compose mode functions ********/
114 function rcmail_compose_headers($attrib)
116 global $IMAP, $MESSAGE, $DB, $compose_mode;
117 static $sa_recipients = array();
119 list($form_start, $form_end) = get_form_tags($attrib);
122 $part = strtolower($attrib['part']);
127 return rcmail_compose_header_from($attrib);
133 // we have a set of recipients stored is session
134 if (($mailto_id = get_input_value('_mailto', RCUBE_INPUT_GET)) && $_SESSION['mailto'][$mailto_id])
135 $fvalue = $_SESSION['mailto'][$mailto_id];
136 else if (!empty($_GET['_to']))
137 $fvalue = get_input_value('_to', RCUBE_INPUT_GET);
152 $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex');
153 $field_type = 'html_textarea';
159 $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
160 $field_type = 'html_inputfield';
164 if ($fname && !empty($_POST[$fname]))
165 $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
167 else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY)
169 // get recipent address(es) out of the message headers
170 if ($header=='to' && !empty($MESSAGE->headers->replyto))
171 $fvalue = $MESSAGE->headers->replyto;
173 else if ($header=='to' && !empty($MESSAGE->headers->from))
174 $fvalue = $MESSAGE->headers->from;
176 // add recipent of original message if reply to all
177 else if ($header=='cc' && !empty($MESSAGE->reply_all))
179 if ($v = $MESSAGE->headers->to)
182 if ($v = $MESSAGE->headers->cc)
183 $fvalue .= (!empty($fvalue) ? ', ' : '') . $v;
186 // split recipients and put them back together in a unique way
189 $to_addresses = $IMAP->decode_address_list($fvalue);
191 foreach ($to_addresses as $addr_part)
193 if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE->compose_from || !in_array($addr_part['mailto'], $MESSAGE->compose_from)))
195 $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
196 $sa_recipients[] = $addr_part['mailto'];
201 else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT)
203 // get drafted headers
204 if ($header=='to' && !empty($MESSAGE->headers->to))
205 $fvalue = $MESSAGE->get_header('to');
207 if ($header=='cc' && !empty($MESSAGE->headers->cc))
208 $fvalue = $MESSAGE->get_header('cc');
210 if ($header=='bcc' && !empty($MESSAGE->headers->bcc))
211 $fvalue = $MESSAGE->get_header('bcc');
215 if ($fname && $field_type)
217 // pass the following attributes to the form class
218 $field_attrib = array('name' => $fname);
219 foreach ($attrib as $attr => $value)
220 if (in_array($attr, $allow_attrib))
221 $field_attrib[$attr] = $value;
223 // create teaxtarea object
224 $input = new $field_type($field_attrib);
225 $out = $input->show($fvalue);
229 $out = $form_start.$out;
236 function rcmail_compose_header_from($attrib)
238 global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode;
240 // pass the following attributes to the form class
241 $field_attrib = array('name' => '_from');
242 foreach ($attrib as $attr => $value)
243 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
244 $field_attrib[$attr] = $value;
246 // extract all recipients of the reply-message
247 $a_recipients = array();
248 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE->headers))
250 $MESSAGE->compose_from = array();
252 $a_to = $IMAP->decode_address_list($MESSAGE->headers->to);
253 foreach ($a_to as $addr)
255 if (!empty($addr['mailto']))
256 $a_recipients[] = $addr['mailto'];
259 if (!empty($MESSAGE->headers->cc))
261 $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc);
262 foreach ($a_cc as $addr)
264 if (!empty($addr['mailto']))
265 $a_recipients[] = $addr['mailto'];
270 // get this user's identities
271 $sql_result = $USER->list_identities();
273 if ($DB->num_rows($sql_result))
276 $a_signatures = array();
278 $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)";
279 $select_from = new html_select($field_attrib);
281 while ($sql_arr = $DB->fetch_assoc($sql_result))
283 $identity_id = $sql_arr['identity_id'];
284 $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
286 // add signature to array
287 if (!empty($sql_arr['signature']))
289 $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
290 $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
291 if ($a_signatures[$identity_id]['is_html'])
293 $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
294 $plainTextPart = $h2t->get_text();
295 $a_signatures[$identity_id]['plain_text'] = trim(html_entity_decode($plainTextPart, ENT_NOQUOTES, 'UTF-8'));
299 // set identity if it's one of the reply-message recipients
300 if (in_array($sql_arr['email'], $a_recipients))
301 $from_id = $sql_arr['identity_id'];
303 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE->compose_from))
304 $MESSAGE->compose_from[] = $sql_arr['email'];
306 if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email']))
307 $from_id = $sql_arr['identity_id'];
310 // overwrite identity selection with post parameter
311 if (isset($_POST['_from']))
312 $from_id = get_input_value('_from', RCUBE_INPUT_POST);
314 $out = $select_from->show($from_id);
316 // add signatures to client
317 $OUTPUT->set_env('signatures', $a_signatures);
321 $input_from = new html_inputfield($field_attrib);
322 $out = $input_from->show($_POST['_from']);
326 $out = $form_start.$out;
332 function rcmail_compose_body($attrib)
334 global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
336 list($form_start, $form_end) = get_form_tags($attrib);
337 unset($attrib['form']);
339 if (empty($attrib['id']))
340 $attrib['id'] = 'rcmComposeMessage';
342 $attrib['name'] = '_message';
344 if ($CONFIG['htmleditor'])
351 // use posted message body
352 if (!empty($_POST['_message']))
354 $body = get_input_value('_message', RCUBE_INPUT_POST, true);
356 else if ($compose_mode)
358 if ($isHtml && $MESSAGE->has_html_part())
360 $body = $MESSAGE->first_html_part();
365 $body = $MESSAGE->first_text_part();
369 // compose reply-body
370 if ($compose_mode == RCUBE_COMPOSE_REPLY)
371 $body = rcmail_create_reply_body($body, $isHtml);
372 // forward message body inline
373 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
374 $body = rcmail_create_forward_body($body, $isHtml);
375 // load draft message body
376 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
377 $body = rcmail_create_draft_body($body, $isHtml);
380 $tinylang = substr($_SESSION['language'], 0, 2);
381 if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js'))
384 $OUTPUT->include_script('tiny_mce/tiny_mce.js');
385 $OUTPUT->include_script("editor.js");
386 $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.$tinylang.'");');
388 $out = $form_start ? "$form_start\n" : '';
390 $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : ''));
391 $out .= $saveid->show();
393 $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes'));
394 $out .= $drafttoggle->show();
396 $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
397 $out .= $msgtype->show();
399 // If desired, set this text area to be editable by TinyMCE
400 if ($isHtml) $attrib['class'] = "mce_editor";
401 $textarea = new html_textarea($attrib);
402 $out .= $textarea->show($body);
403 $out .= $form_end ? "\n$form_end" : '';
405 // include GoogieSpell
406 if (!empty($CONFIG['enable_spellcheck']) && !$isHtml)
409 if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages']))
410 $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n";
412 $OUTPUT->include_script('googiespell.js');
413 $OUTPUT->add_script(sprintf(
414 "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
415 "googie.lang_chck_spell = \"%s\";\n".
416 "googie.lang_rsm_edt = \"%s\";\n".
417 "googie.lang_close = \"%s\";\n".
418 "googie.lang_revert = \"%s\";\n".
419 "googie.lang_no_error_found = \"%s\";\n%s".
420 "googie.setCurrentLanguage('%s');\n".
421 "googie.decorateTextarea('%s');\n".
422 "%s.set_env('spellcheck', googie);",
424 JQ(Q(rcube_label('checkspelling'))),
425 JQ(Q(rcube_label('resumeediting'))),
426 JQ(Q(rcube_label('close'))),
427 JQ(Q(rcube_label('revertto'))),
428 JQ(Q(rcube_label('nospellerrors'))),
430 substr($_SESSION['language'], 0, 2),
432 JS_OBJECT_NAME), 'foot');
434 rcube_add_label('checking');
437 $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
443 function rcmail_create_reply_body($body, $bodyIsHtml)
445 global $IMAP, $MESSAGE;
449 // soft-wrap message first
450 $body = wordwrap($body, 75);
452 // split body into single lines
453 $a_lines = preg_split('/\r?\n/', $body);
455 // add > to each line
456 for($n=0; $n<sizeof($a_lines); $n++)
458 if (strpos($a_lines[$n], '>')===0)
459 $a_lines[$n] = '>'.$a_lines[$n];
461 $a_lines[$n] = '> '.$a_lines[$n];
464 $body = join("\n", $a_lines);
467 $prefix = sprintf("\n\n\nOn %s, %s wrote:\n",
468 $MESSAGE->headers->date,
469 $MESSAGE->get_header('from'));
471 // try to remove the signature
472 if ($sp = strrpos($body, '-- '))
474 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
475 $body = substr($body, 0, $sp-1);
481 $prefix = sprintf("<br /><br />On %s, %s wrote:<br />\n",
482 $MESSAGE->headers->date,
483 Q($MESSAGE->get_header('from')));
484 $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
485 $suffix = "</blockquote>";
488 return $prefix.$body.$suffix;
492 function rcmail_create_forward_body($body, $bodyIsHtml)
494 global $IMAP, $MESSAGE;
498 // soft-wrap message first
499 $body = wordwrap($body, 80);
501 $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
503 $MESSAGE->headers->date,
504 $MESSAGE->get_header('from'),
505 $MESSAGE->get_header('to'));
510 "<br><br>-------- Original Message --------" .
511 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
512 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
513 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
514 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
515 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" .
516 "</tbody></table><br>",
517 Q($MESSAGE->subject),
518 Q($MESSAGE->headers->date),
519 Q($MESSAGE->get_header('from')),
520 Q($MESSAGE->get_header('to')));
524 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts))
525 rcmail_write_compose_attachments($MESSAGE);
527 return $prefix.$body;
531 function rcmail_create_draft_body($body, $bodyIsHtml)
537 * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text!
539 if (!isset($_SESSION['compose']['forward_attachments'])
540 && is_array($MESSAGE->mime_parts)
541 && count($MESSAGE->mime_parts) > 0)
542 rcmail_write_compose_attachments($MESSAGE);
548 function rcmail_write_compose_attachments(&$message)
550 global $RCMAIL, $IMAP;
552 $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
554 if (!is_array($_SESSION['compose']['attachments']))
555 $_SESSION['compose']['attachments'] = array();
557 foreach ((array)$message->mime_parts as $pid => $part)
559 if ($part->ctype_primary != 'message' &&
560 ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
561 (empty($part->disposition) && $part->filename)))
563 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
564 if ($fp = fopen($tmp_path, 'w'))
566 fwrite($fp, $message->get_part_content($pid));
569 $_SESSION['compose']['attachments'][] = array(
570 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
571 'name' => $part->filename,
578 $_SESSION['compose']['forward_attachments'] = true;
582 function rcmail_compose_subject($attrib)
584 global $MESSAGE, $compose_mode;
586 list($form_start, $form_end) = get_form_tags($attrib);
587 unset($attrib['form']);
589 $attrib['name'] = '_subject';
590 $textfield = new html_inputfield($attrib);
594 // use subject from post
595 if (isset($_POST['_subject']))
596 $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
598 // create a reply-subject
599 else if ($compose_mode == RCUBE_COMPOSE_REPLY)
601 if (eregi('^re:', $MESSAGE->subject))
602 $subject = $MESSAGE->subject;
604 $subject = 'Re: '.$MESSAGE->subject;
607 // create a forward-subject
608 else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
610 if (eregi('^fwd:', $MESSAGE->subject))
611 $subject = $MESSAGE->subject;
613 $subject = 'Fwd: '.$MESSAGE->subject;
616 // creeate a draft-subject
617 else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
618 $subject = $MESSAGE->subject;
620 $out = $form_start ? "$form_start\n" : '';
621 $out .= $textfield->show($subject);
622 $out .= $form_end ? "\n$form_end" : '';
628 function rcmail_compose_attachment_list($attrib)
630 global $OUTPUT, $CONFIG;
632 // add ID if not given
634 $attrib['id'] = 'rcmAttachmentList';
638 if (is_array($_SESSION['compose']['attachments']))
640 if ($attrib['deleteicon'])
641 $button = html::img(array(
642 'src' => $CONFIG['skin_path'] . $attrib['deleteicon'],
643 'alt' => rcube_label('delete'),
644 'style' => "border:0;padding-right:2px;vertical-align:middle"));
646 $button = Q(rcube_label('delete'));
648 foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
649 $out .= html::tag('li', array('id' => "rcmfile".$id),
652 'title' => rcube_label('delete'),
653 'onclick' => sprintf("return %s.command(\'remove-attachment\',\'rcmfile%d\', this)", JS_OBJECT_NAME, $id)),
654 $button) . Q($a_prop['name']));
657 $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
659 return html::tag('ul', $attrib, $out, html::$common_attrib);
663 function rcmail_compose_attachment_form($attrib)
667 // add ID if not given
669 $attrib['id'] = 'rcmUploadbox';
671 $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
673 $out = html::div($attrib,
674 $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data')) .
675 rcmail_compose_attachment_field(array()) . html::br() .
676 $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) .
677 $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)"))
681 $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
686 function rcmail_compose_attachment_field($attrib)
688 // allow the following attributes to be added to the <input> tag
689 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
691 $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
696 function rcmail_priority_selector($attrib)
700 list($form_start, $form_end) = get_form_tags($attrib);
701 unset($attrib['form']);
703 $attrib['name'] = '_priority';
704 $selector = new html_select($attrib);
706 $selector->add(array(rcube_label('lowest'),
708 rcube_label('normal'),
710 rcube_label('highest')),
711 array(5, 4, 0, 2, 1));
713 $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority);
715 $out = $form_start ? "$form_start\n" : '';
716 $out .= $selector->show($sel);
717 $out .= $form_end ? "\n$form_end" : '';
723 function rcmail_receipt_checkbox($attrib)
725 global $MESSAGE, $compose_mode;
727 list($form_start, $form_end) = get_form_tags($attrib);
728 unset($attrib['form']);
730 if (!isset($attrib['id']))
731 $attrib['id'] = 'receipt';
733 $attrib['name'] = '_receipt';
734 $attrib['value'] = '1';
735 $checkbox = new html_checkbox($attrib);
737 $out = $form_start ? "$form_start\n" : '';
738 $out .= $checkbox->show(
739 $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0);
740 $out .= $form_end ? "\n$form_end" : '';
746 function rcmail_editor_selector($attrib)
748 global $CONFIG, $MESSAGE, $compose_mode;
751 'html' => 'htmltoggle',
752 'plain' => 'plaintoggle'
755 // determine whether HTML or plain text should be checked
756 $useHtml = $CONFIG['htmleditor'] ? true : false;
759 $useHtml = ($useHtml && $MESSAGE->has_html_part());
762 $chosenvalue = $useHtml ? 'html' : 'plain';
763 $radio = new html_radiobutton(array('name' => '_editorSelect', 'onclick' => 'return rcmail_toggle_editor(this)'));
764 foreach ($choices as $value => $text)
766 $attrib['id'] = '_' . $value;
767 $attrib['value'] = $value;
768 $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text)));
775 function get_form_tags($attrib)
777 global $RCMAIL, $MESSAGE_FORM;
780 if (!strlen($MESSAGE_FORM))
782 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
783 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
785 $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
786 $form_start .= $hiddenfields->show();
789 $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
790 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
792 if (!strlen($MESSAGE_FORM))
793 $RCMAIL->output->add_gui_object('messageform', $form_name);
795 $MESSAGE_FORM = $form_name;
797 return array($form_start, $form_end);
801 // register UI objects
802 $OUTPUT->add_handlers(array(
803 'composeheaders' => 'rcmail_compose_headers',
804 'composesubject' => 'rcmail_compose_subject',
805 'composebody' => 'rcmail_compose_body',
806 'composeattachmentlist' => 'rcmail_compose_attachment_list',
807 'composeattachmentform' => 'rcmail_compose_attachment_form',
808 'composeattachment' => 'rcmail_compose_attachment_field',
809 'priorityselector' => 'rcmail_priority_selector',
810 'editorselector' => 'rcmail_editor_selector',
811 'receiptcheckbox' => 'rcmail_receipt_checkbox',
814 /****** get contacts for this user and add them to client scripts ********/
816 $CONTACTS = new rcube_contacts($DB, $USER->ID);
817 $CONTACTS->set_pagesize(1000);
819 $a_contacts = array();
821 if ($result = $CONTACTS->list_records())
823 while ($sql_arr = $result->iterate())
824 if ($sql_arr['email'])
825 $a_contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
827 if (isset($CONFIG['ldap_public']))
829 /* LDAP autocompletion */
830 foreach ($CONFIG['ldap_public'] as $ldapserv_config)
832 if ($ldapserv_config['fuzzy_search'] != 1 ||
833 $ldapserv_config['global_search'] != 1)
838 $LDAP = new rcube_ldap($ldapserv_config);
840 $LDAP->set_pagesize(1000);
842 $results = $LDAP->search($ldapserv_config['mail_field'], "");
844 for ($i = 0; $i < $results->count; $i++)
846 if ($results->records[$i]['email'] != '')
848 $email = $results->records[$i]['email'];
849 $name = $results->records[$i]['name'];
851 $a_contacts[] = format_email_recipient($email, $name);
859 $OUTPUT->set_env('contacts', $a_contacts);
862 $OUTPUT->send('compose');