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 297 2006-08-06 15:55:11Z thomasb $
23 require_once('Mail/mimeDecode.php');
25 // remove an attachment
26 if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
29 if (is_array($_SESSION['compose']['attachments'][$id]))
31 @unlink($_SESSION['compose']['attachments'][$id]['path']);
32 $_SESSION['compose']['attachments'][$id] = NULL;
33 $commands = sprintf("parent.%s.remove_from_attachment_list('rcmfile%d');\n", $JS_OBJECT_NAME, $id);
34 rcube_remote_response($commands);
41 $REPLY_MESSAGE = NULL;
42 $FORWARD_MESSAGE = NULL;
43 $DRAFT_MESSAGE = NULL;
45 // nothing below is called during message composition, only at "new/forward/reply/draft" initialization
46 // since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
47 // compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
49 rcmail_compose_cleanup();
50 $_SESSION['compose'] = array('id' => uniqid(rand()));
52 // add some labels to client
53 rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved');
56 if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid'])
58 $msg_uid = ($_GET['_reply_uid'] ? $_GET['_reply_uid'] : ($_GET['_forward_uid'] ? $_GET['_forward_uid'] : $_GET['_draft_uid']));
60 // similar as in program/steps/mail/show.inc
62 $MESSAGE['headers'] = $IMAP->get_headers($msg_uid);
64 $MESSAGE['source'] = rcmail_message_source($msg_uid);
66 $mmd = new Mail_mimeDecode($MESSAGE['source']);
67 $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
68 'decode_headers' => TRUE,
69 'decode_bodies' => FALSE));
71 $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
72 $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']);
74 if ($_GET['_reply_uid'])
76 $REPLY_MESSAGE = &$MESSAGE;
77 $_SESSION['compose']['reply_uid'] = $_GET['_reply_uid'];
78 $_SESSION['compose']['reply_msgid'] = $REPLY_MESSAGE['headers']->messageID;
79 $_SESSION['compose']['references'] = $REPLY_MESSAGE['headers']->reference;
80 $_SESSION['compose']['references'] .= !empty($REPLY_MESSAGE['headers']->reference) ? ' ' : '';
81 $_SESSION['compose']['references'] .= $REPLY_MESSAGE['headers']->messageID;
84 $REPLY_MESSAGE['reply_all'] = 1;
87 else if ($_GET['_forward_uid'])
89 $FORWARD_MESSAGE = $MESSAGE;
90 $_SESSION['compose']['forward_uid'] = $_GET['_forward_uid'];
94 $DRAFT_MESSAGE = $MESSAGE;
95 $_SESSION['compose']['draft_uid'] = $_GET['_draft_uid'];
100 /****** compose mode functions ********/
103 function rcmail_compose_headers($attrib)
105 global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB;
106 static $sa_recipients = array();
108 list($form_start, $form_end) = get_form_tags($attrib);
111 $part = strtolower($attrib['part']);
116 return rcmail_compose_header_from($attrib);
122 // we have contact id's as get parameters
123 if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to']))
125 $a_recipients = array();
126 $sql_result = $DB->query("SELECT name, email
127 FROM ".get_table_name('contacts')."
130 AND contact_id IN (".$_GET['_to'].")",
131 $_SESSION['user_id']);
133 while ($sql_arr = $DB->fetch_assoc($sql_result))
134 $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
136 if (sizeof($a_recipients))
137 $fvalue = join(', ', $a_recipients);
139 else if (!empty($_GET['_to']))
140 $fvalue = $_GET['_to'];
152 $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex');
153 $field_type = 'textarea';
159 $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
160 $field_type = 'textfield';
165 if ($fname && !empty($_POST[$fname]))
166 $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
167 else if ($header && is_object($REPLY_MESSAGE['headers']))
169 // get recipent address(es) out of the message headers
170 if ($header=='to' && $REPLY_MESSAGE['headers']->replyto)
171 $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->replyto);
173 else if ($header=='to' && $REPLY_MESSAGE['headers']->from)
174 $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->from);
176 // add recipent of original message if reply to all
177 else if ($header=='cc' && $REPLY_MESSAGE['reply_all'])
179 if ($IMAP->decode_header($REPLY_MESSAGE['headers']->to))
180 $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->to);
182 if ($IMAP->decode_header($REPLY_MESSAGE['headers']->cc))
187 $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->cc);
191 // split recipients and put them back together in a unique way
194 $to_addresses = $IMAP->decode_address_list($fvalue);
196 foreach ($to_addresses as $addr_part)
198 if (!in_array($addr_part['mailto'], $sa_recipients) && (!$REPLY_MESSAGE['FROM'] || !in_array($addr_part['mailto'], $REPLY_MESSAGE['FROM'])))
200 $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
201 $sa_recipients[] = $addr_part['mailto'];
206 else if ($header && is_object($DRAFT_MESSAGE['headers']))
208 // get drafted headers
209 if ($header=='to' && $DRAFT_MESSAGE['headers']->to)
210 $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->to);
212 if ($header=='cc' && $DRAFT_MESSAGE['headers']->cc)
213 $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->cc);
215 if ($header=='bcc' && $DRAFT_MESSAGE['headers']->bcc)
216 $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->bcc);
221 if ($fname && $field_type)
223 // pass the following attributes to the form class
224 $field_attrib = array('name' => $fname);
225 foreach ($attrib as $attr => $value)
226 if (in_array($attr, $allow_attrib))
227 $field_attrib[$attr] = $value;
229 // create teaxtarea object
230 $input = new $field_type($field_attrib);
231 $out = $input->show($fvalue);
235 $out = $form_start.$out;
242 function rcmail_compose_header_from($attrib)
244 global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME;
246 // pass the following attributes to the form class
247 $field_attrib = array('name' => '_from');
248 foreach ($attrib as $attr => $value)
249 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
250 $field_attrib[$attr] = $value;
252 // extract all recipients of the reply-message
253 $a_recipients = array();
254 if ($REPLY_MESSAGE && is_object($REPLY_MESSAGE['headers']))
256 $REPLY_MESSAGE['FROM'] = array();
258 $a_to = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->to);
259 foreach ($a_to as $addr)
261 if (!empty($addr['mailto']))
262 $a_recipients[] = $addr['mailto'];
265 if (!empty($REPLY_MESSAGE['headers']->cc))
267 $a_cc = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->cc);
268 foreach ($a_cc as $addr)
270 if (!empty($addr['mailto']))
271 $a_recipients[] = $addr['mailto'];
276 // get this user's identities
277 $sql_result = $DB->query("SELECT identity_id, name, email, signature
278 FROM ".get_table_name('identities')."
281 ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC",
282 $_SESSION['user_id']);
284 if ($DB->num_rows($sql_result))
287 $a_signatures = array();
289 $field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)";
290 $select_from = new select($field_attrib);
292 while ($sql_arr = $DB->fetch_assoc($sql_result))
294 $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $sql_arr['identity_id']);
296 // add signature to array
297 if (!empty($sql_arr['signature']))
298 $a_signatures[$sql_arr['identity_id']] = $sql_arr['signature'];
300 // set identity if it's one of the reply-message recipients
301 if (in_array($sql_arr['email'], $a_recipients))
302 $from_id = $sql_arr['identity_id'];
304 if ($REPLY_MESSAGE && is_array($REPLY_MESSAGE['FROM']))
305 $REPLY_MESSAGE['FROM'][] = $sql_arr['email'];
307 if (strstr($DRAFT_MESSAGE['headers']->from,$sql_arr['email']))
308 $from_id = $sql_arr['identity_id'];
312 // overwrite identity selection with post parameter
313 if (isset($_POST['_from']))
314 $from_id = $_POST['_from'];
316 $out = $select_from->show($from_id);
319 // add signatures to client
320 $OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures)));
324 $input_from = new textfield($field_attrib);
325 $out = $input_from->show($_POST['_from']);
329 $out = $form_start.$out;
336 function rcmail_compose_body($attrib)
338 global $CONFIG, $OUTPUT, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE, $JS_OBJECT_NAME;
340 list($form_start, $form_end) = get_form_tags($attrib);
341 unset($attrib['form']);
343 if (empty($attrib['id']))
344 $attrib['id'] = 'rcmComposeMessage';
346 $attrib['name'] = '_message';
347 $textarea = new textarea($attrib);
351 // use posted message body
352 if (!empty($_POST['_message']))
353 $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE);
355 // compose reply-body
356 else if (is_array($REPLY_MESSAGE['parts']))
358 $body = rcmail_first_text_part($REPLY_MESSAGE['parts']);
360 $body = rcmail_create_reply_body($body);
363 // forward message body inline
364 else if (is_array($FORWARD_MESSAGE['parts']))
366 $body = rcmail_first_text_part($FORWARD_MESSAGE['parts']);
368 $body = rcmail_create_forward_body($body);
371 // forward message body inline
372 else if (is_array($DRAFT_MESSAGE['parts']))
374 $body = rcmail_first_text_part($DRAFT_MESSAGE['parts']);
376 $body = rcmail_create_draft_body($body);
379 $out = $form_start ? "$form_start\n" : '';
381 $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$DRAFT_MESSAGE['headers']->messageID) ));
382 $out .= $saveid->show();
384 $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes'));
385 $out .= $drafttoggle->show();
387 $out .= $textarea->show($body);
388 $out .= $form_end ? "\n$form_end" : '';
390 // include GoogieSpell
391 if (!empty($CONFIG['enable_spellcheck']))
393 $OUTPUT->include_script('googiespell.js');
394 $OUTPUT->add_script(sprintf("var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
395 "googie.lang_chck_spell = \"%s\";\n".
396 "googie.lang_rsm_edt = \"%s\";\n".
397 "googie.lang_close = \"%s\";\n".
398 "googie.lang_revert = \"%s\";\n".
399 "googie.lang_no_error_found = \"%s\";\n".
400 "googie.decorateTextarea('%s');\n".
401 "%s.set_env('spellcheck', googie);",
402 $GLOBALS['COMM_PATH'],
403 rep_specialchars_output(rcube_label('checkspelling')),
404 rep_specialchars_output(rcube_label('resumeediting')),
405 rep_specialchars_output(rcube_label('close')),
406 rep_specialchars_output(rcube_label('revertto')),
407 rep_specialchars_output(rcube_label('nospellerrors')),
409 $JS_OBJECT_NAME), 'foot');
411 rcube_add_label('checking');
414 $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
420 function rcmail_create_reply_body($body)
422 global $IMAP, $REPLY_MESSAGE;
424 // soft-wrap message first
425 $body = wordwrap($body, 75);
427 // split body into single lines
428 $a_lines = preg_split('/\r?\n/', $body);
430 // add > to each line
431 for($n=0; $n<sizeof($a_lines); $n++)
433 if (strpos($a_lines[$n], '>')===0)
434 $a_lines[$n] = '>'.$a_lines[$n];
436 $a_lines[$n] = '> '.$a_lines[$n];
439 $body = join("\n", $a_lines);
442 $pefix = sprintf("\n\n\nOn %s, %s wrote:\n",
443 $REPLY_MESSAGE['headers']->date,
444 $IMAP->decode_header($REPLY_MESSAGE['headers']->from));
447 // try to remove the signature
448 if ($sp = strrpos($body, '-- '))
450 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
451 $body = substr($body, 0, $sp-1);
458 function rcmail_create_forward_body($body)
460 global $IMAP, $FORWARD_MESSAGE;
462 // soft-wrap message first
463 $body = wordwrap($body, 80);
465 $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
466 $FORWARD_MESSAGE['subject'],
467 $FORWARD_MESSAGE['headers']->date,
468 $IMAP->decode_header($FORWARD_MESSAGE['headers']->from),
469 $IMAP->decode_header($FORWARD_MESSAGE['headers']->to));
472 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($FORWARD_MESSAGE['parts']) && sizeof($FORWARD_MESSAGE['parts'])>1)
474 $temp_dir = rcmail_create_compose_tempdir();
476 if (!is_array($_SESSION['compose']['attachments']))
477 $_SESSION['compose']['attachments'] = array();
479 foreach ($FORWARD_MESSAGE['parts'] as $part)
481 if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
482 (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))
484 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
485 if ($fp = fopen($tmp_path, 'w'))
487 fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
490 if ($part->d_parameters['filename'])
491 $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'],
492 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
493 'path' => $tmp_path);
495 else if ($part->ctype_parameters['name'])
496 $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'],
497 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
498 'path' => $tmp_path);
500 else if ($part->headers['content-description'])
501 $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'],
502 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
503 'path' => $tmp_path);
508 $_SESSION['compose']['forward_attachments'] = TRUE;
511 return $prefix.$body;
514 function rcmail_create_draft_body($body)
516 global $IMAP, $DRAFT_MESSAGE;
519 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($DRAFT_MESSAGE['parts']) && sizeof($DRAFT_MESSAGE['parts'])>1)
521 $temp_dir = rcmail_create_compose_tempdir();
523 if (!is_array($_SESSION['compose']['attachments']))
524 $_SESSION['compose']['attachments'] = array();
526 foreach ($DRAFT_MESSAGE['parts'] as $part)
528 if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
529 (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))
531 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
532 if ($fp = fopen($tmp_path, 'w'))
534 fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
537 if ($part->d_parameters['filename'])
538 $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'],
539 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
540 'path' => $tmp_path);
542 else if ($part->ctype_parameters['name'])
543 $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'],
544 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
545 'path' => $tmp_path);
547 else if ($part->headers['content-description'])
548 $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'],
549 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
550 'path' => $tmp_path);
555 $_SESSION['compose']['forward_attachments'] = TRUE;
562 function rcmail_compose_subject($attrib)
564 global $CONFIG, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE;
566 list($form_start, $form_end) = get_form_tags($attrib);
567 unset($attrib['form']);
569 $attrib['name'] = '_subject';
570 $textfield = new textfield($attrib);
574 // use subject from post
575 if (isset($_POST['_subject']))
576 $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
578 // create a reply-subject
579 else if (isset($REPLY_MESSAGE['subject']))
581 if (eregi('^re:', $REPLY_MESSAGE['subject']))
582 $subject = $REPLY_MESSAGE['subject'];
584 $subject = 'Re: '.$REPLY_MESSAGE['subject'];
587 // create a forward-subject
588 else if (isset($FORWARD_MESSAGE['subject']))
590 if (eregi('^fwd:', $REPLY_MESSAGE['subject']))
591 $subject = $FORWARD_MESSAGE['subject'];
593 $subject = 'Fwd: '.$FORWARD_MESSAGE['subject'];
596 // creeate a draft-subject
597 else if (isset($DRAFT_MESSAGE['subject']))
598 $subject = $DRAFT_MESSAGE['subject'];
600 $out = $form_start ? "$form_start\n" : '';
601 $out .= $textfield->show($subject);
602 $out .= $form_end ? "\n$form_end" : '';
608 function rcmail_compose_attachment_list($attrib)
610 global $OUTPUT, $JS_OBJECT_NAME;
612 // add ID if not given
614 $attrib['id'] = 'rcmAttachmentList';
616 // allow the following attributes to be added to the <ul> tag
617 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
619 $out = '<ul'. $attrib_str . ">\n";
621 if (is_array($_SESSION['compose']['attachments']))
623 if ($attrib['deleteicon'])
624 $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />',
625 $CONFIG['skin_path'],
626 $attrib['deleteicon'],
627 rcube_label('delete'));
629 $button = rcube_label('delete');
631 foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
632 $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>',
636 rcube_label('delete'),
638 rep_specialchars_output($a_prop['name']));
641 $OUTPUT->add_script(sprintf("%s.gui_object('attachmentlist', '%s');", $JS_OBJECT_NAME, $attrib['id']));
649 function rcmail_compose_attachment_form($attrib)
651 global $OUTPUT, $JS_OBJECT_NAME, $SESS_HIDDEN_FIELD;
653 // add ID if not given
655 $attrib['id'] = 'rcmUploadbox';
657 // allow the following attributes to be added to the <div> tag
658 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
659 $input_field = rcmail_compose_attachment_field(array());
660 $label_send = rcube_label('upload');
661 $label_close = rcube_label('close');
665 <form action="./" method="post" enctype="multipart/form-data">
668 <input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" />
669 <input type="button" value="$label_send" class="button" onclick="$JS_OBJECT_NAME.command('send-attachment', this.form)" />
675 $OUTPUT->add_script(sprintf("%s.gui_object('uploadbox', '%s');", $JS_OBJECT_NAME, $attrib['id']));
680 function rcmail_compose_attachment_field($attrib)
682 // allow the following attributes to be added to the <input> tag
683 $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
685 $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
690 function rcmail_priority_selector($attrib)
692 list($form_start, $form_end) = get_form_tags($attrib);
693 unset($attrib['form']);
695 $attrib['name'] = '_priority';
696 $selector = new select($attrib);
698 $selector->add(array(rcube_label('lowest'),
700 rcube_label('normal'),
702 rcube_label('highest')),
703 array(5, 4, 0, 2, 1));
705 $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0;
707 $out = $form_start ? "$form_start\n" : '';
708 $out .= $selector->show($sel);
709 $out .= $form_end ? "\n$form_end" : '';
715 function rcmail_receipt_checkbox($attrib)
717 list($form_start, $form_end) = get_form_tags($attrib);
718 unset($attrib['form']);
720 if (!isset($attrib['id']))
721 $attrib['id'] = 'receipt';
723 $attrib['name'] = '_receipt';
724 $attrib['value'] = '1';
725 $checkbox = new checkbox($attrib);
727 $out = $form_start ? "$form_start\n" : '';
728 $out .= $checkbox->show(0);
729 $out .= $form_end ? "\n$form_end" : '';
735 function get_form_tags($attrib)
737 global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;
740 if (!strlen($MESSAGE_FORM))
742 $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
743 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
745 $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
746 $form_start .= "\n$SESS_HIDDEN_FIELD\n";
747 $form_start .= $hiddenfields->show();
750 $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
751 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
753 if (!strlen($MESSAGE_FORM))
754 $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');");
756 $MESSAGE_FORM = $form_name;
758 return array($form_start, $form_end);
762 function format_email_recipient($email, $name='')
764 if ($name && $name != $email)
765 return sprintf('%s <%s>', strpos($name, ",") ? '"'.$name.'"' : $name, $email);
771 function rcmail_charset_pulldown($selected='ISO-8859-1')
773 $select = new select();
776 return $select->show($selected);
780 /****** get contacts for this user and add them to client scripts ********/
782 $sql_result = $DB->query("SELECT name, email
783 FROM ".get_table_name('contacts')." WHERE user_id=?
784 AND del<>1",$_SESSION['user_id']);
786 if ($DB->num_rows($sql_result))
788 $a_contacts = array();
789 while ($sql_arr = $DB->fetch_assoc($sql_result))
790 if ($sql_arr['email'])
791 $a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
793 $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
797 parse_template('compose');