| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/compose.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2005, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Compose a new mail message with all headers and attachments | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | require_once('Mail/mimeDecode.php'); |
|---|
| 23 | require_once('lib/html2text.inc'); |
|---|
| 24 | |
|---|
| 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); |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | // remove an attachment |
|---|
| 32 | if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) |
|---|
| 33 | { |
|---|
| 34 | $id = $regs[1]; |
|---|
| 35 | if (is_array($_SESSION['compose']['attachments'][$id])) |
|---|
| 36 | { |
|---|
| 37 | @unlink($_SESSION['compose']['attachments'][$id]['path']); |
|---|
| 38 | $_SESSION['compose']['attachments'][$id] = NULL; |
|---|
| 39 | $commands = sprintf("parent.%s.remove_from_attachment_list('rcmfile%d');\n", $JS_OBJECT_NAME, $id); |
|---|
| 40 | rcube_remote_response($commands); |
|---|
| 41 | exit; |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | $MESSAGE_FORM = NULL; |
|---|
| 47 | $MESSAGE = NULL; |
|---|
| 48 | |
|---|
| 49 | // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or |
|---|
| 50 | // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab). |
|---|
| 51 | // Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old |
|---|
| 52 | // compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear |
|---|
| 53 | |
|---|
| 54 | if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET)) |
|---|
| 55 | { |
|---|
| 56 | rcmail_compose_cleanup(); |
|---|
| 57 | $_SESSION['compose'] = array('id' => uniqid(rand())); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | // add some labels to client |
|---|
| 61 | rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting'); |
|---|
| 62 | |
|---|
| 63 | // add config parameter to client script |
|---|
| 64 | $OUTPUT->add_script(sprintf("%s.set_env('draft_autosave', %d);", $JS_OBJECT_NAME, !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0)); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | // get reference message and set compose mode |
|---|
| 68 | if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET)) |
|---|
| 69 | $compose_mode = RCUBE_COMPOSE_REPLY; |
|---|
| 70 | else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET)) |
|---|
| 71 | $compose_mode = RCUBE_COMPOSE_FORWARD; |
|---|
| 72 | else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET)) |
|---|
| 73 | $compose_mode = RCUBE_COMPOSE_DRAFT; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | if (!empty($msg_uid)) |
|---|
| 77 | { |
|---|
| 78 | // similar as in program/steps/mail/show.inc |
|---|
| 79 | $MESSAGE = array('UID' => $msg_uid); |
|---|
| 80 | $MESSAGE['headers'] = &$IMAP->get_headers($msg_uid); |
|---|
| 81 | $MESSAGE['structure'] = &$IMAP->get_structure($msg_uid); |
|---|
| 82 | $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject); |
|---|
| 83 | $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']); |
|---|
| 84 | |
|---|
| 85 | if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 86 | { |
|---|
| 87 | $_SESSION['compose']['reply_uid'] = $msg_uid; |
|---|
| 88 | $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID; |
|---|
| 89 | $_SESSION['compose']['references'] = $MESSAGE['headers']->reference; |
|---|
| 90 | $_SESSION['compose']['references'] .= !empty($MESSAGE['headers']->reference) ? ' ' : ''; |
|---|
| 91 | $_SESSION['compose']['references'] .= $MESSAGE['headers']->messageID; |
|---|
| 92 | |
|---|
| 93 | if (!empty($_GET['_all'])) |
|---|
| 94 | $MESSAGE['reply_all'] = 1; |
|---|
| 95 | } |
|---|
| 96 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 97 | { |
|---|
| 98 | $_SESSION['compose']['forward_uid'] = $msg_uid; |
|---|
| 99 | } |
|---|
| 100 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 101 | { |
|---|
| 102 | $_SESSION['compose']['draft_uid'] = $msg_uid; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /****** compose mode functions ********/ |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | function rcmail_compose_headers($attrib) |
|---|
| 111 | { |
|---|
| 112 | global $IMAP, $MESSAGE, $DB, $compose_mode; |
|---|
| 113 | static $sa_recipients = array(); |
|---|
| 114 | |
|---|
| 115 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 116 | |
|---|
| 117 | $out = ''; |
|---|
| 118 | $part = strtolower($attrib['part']); |
|---|
| 119 | |
|---|
| 120 | switch ($part) |
|---|
| 121 | { |
|---|
| 122 | case 'from': |
|---|
| 123 | return rcmail_compose_header_from($attrib); |
|---|
| 124 | |
|---|
| 125 | case 'to': |
|---|
| 126 | $fname = '_to'; |
|---|
| 127 | $header = 'to'; |
|---|
| 128 | |
|---|
| 129 | // we have contact id's as get parameters |
|---|
| 130 | if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to'])) |
|---|
| 131 | { |
|---|
| 132 | $a_recipients = array(); |
|---|
| 133 | $sql_result = $DB->query("SELECT name, email |
|---|
| 134 | FROM ".get_table_name('contacts')." |
|---|
| 135 | WHERE user_id=? |
|---|
| 136 | AND del<>1 |
|---|
| 137 | AND contact_id IN (".$_GET['_to'].")", |
|---|
| 138 | $_SESSION['user_id']); |
|---|
| 139 | |
|---|
| 140 | while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|---|
| 141 | $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); |
|---|
| 142 | |
|---|
| 143 | if (sizeof($a_recipients)) |
|---|
| 144 | $fvalue = join(', ', $a_recipients); |
|---|
| 145 | } |
|---|
| 146 | else if (!empty($_GET['_to'])) |
|---|
| 147 | $fvalue = get_input_value('_to', RCUBE_INPUT_GET); |
|---|
| 148 | |
|---|
| 149 | case 'cc': |
|---|
| 150 | if (!$fname) |
|---|
| 151 | { |
|---|
| 152 | $fname = '_cc'; |
|---|
| 153 | $header = 'cc'; |
|---|
| 154 | } |
|---|
| 155 | case 'bcc': |
|---|
| 156 | if (!$fname) |
|---|
| 157 | { |
|---|
| 158 | $fname = '_bcc'; |
|---|
| 159 | $header = 'bcc'; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex'); |
|---|
| 163 | $field_type = 'textarea'; |
|---|
| 164 | break; |
|---|
| 165 | |
|---|
| 166 | case 'replyto': |
|---|
| 167 | case 'reply-to': |
|---|
| 168 | $fname = '_replyto'; |
|---|
| 169 | $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex'); |
|---|
| 170 | $field_type = 'textfield'; |
|---|
| 171 | break; |
|---|
| 172 | |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | if ($fname && !empty($_POST[$fname])) |
|---|
| 176 | $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE); |
|---|
| 177 | |
|---|
| 178 | else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 179 | { |
|---|
| 180 | // get recipent address(es) out of the message headers |
|---|
| 181 | if ($header=='to' && !empty($MESSAGE['headers']->replyto)) |
|---|
| 182 | $fvalue = $MESSAGE['headers']->replyto; |
|---|
| 183 | |
|---|
| 184 | else if ($header=='to' && !empty($MESSAGE['headers']->from)) |
|---|
| 185 | $fvalue = $MESSAGE['headers']->from; |
|---|
| 186 | |
|---|
| 187 | // add recipent of original message if reply to all |
|---|
| 188 | else if ($header=='cc' && !empty($MESSAGE['reply_all'])) |
|---|
| 189 | { |
|---|
| 190 | if ($v = $MESSAGE['headers']->to) |
|---|
| 191 | $fvalue .= $v; |
|---|
| 192 | |
|---|
| 193 | if ($v = $MESSAGE['headers']->cc) |
|---|
| 194 | $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | // split recipients and put them back together in a unique way |
|---|
| 198 | if (!empty($fvalue)) |
|---|
| 199 | { |
|---|
| 200 | $to_addresses = $IMAP->decode_address_list($fvalue); |
|---|
| 201 | $fvalue = ''; |
|---|
| 202 | foreach ($to_addresses as $addr_part) |
|---|
| 203 | { |
|---|
| 204 | if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM']))) |
|---|
| 205 | { |
|---|
| 206 | $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; |
|---|
| 207 | $sa_recipients[] = $addr_part['mailto']; |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | } |
|---|
| 212 | else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 213 | { |
|---|
| 214 | // get drafted headers |
|---|
| 215 | if ($header=='to' && !empty($MESSAGE['headers']->to)) |
|---|
| 216 | $fvalue = $IMAP->decode_header($MESSAGE['headers']->to); |
|---|
| 217 | |
|---|
| 218 | if ($header=='cc' && !empty($MESSAGE['headers']->cc)) |
|---|
| 219 | $fvalue = $IMAP->decode_header($MESSAGE['headers']->cc); |
|---|
| 220 | |
|---|
| 221 | if ($header=='bcc' && !empty($MESSAGE['headers']->bcc)) |
|---|
| 222 | $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | if ($fname && $field_type) |
|---|
| 227 | { |
|---|
| 228 | // pass the following attributes to the form class |
|---|
| 229 | $field_attrib = array('name' => $fname); |
|---|
| 230 | foreach ($attrib as $attr => $value) |
|---|
| 231 | if (in_array($attr, $allow_attrib)) |
|---|
| 232 | $field_attrib[$attr] = $value; |
|---|
| 233 | |
|---|
| 234 | // create teaxtarea object |
|---|
| 235 | $input = new $field_type($field_attrib); |
|---|
| 236 | $out = $input->show($fvalue); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | if ($form_start) |
|---|
| 240 | $out = $form_start.$out; |
|---|
| 241 | |
|---|
| 242 | return $out; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | function rcmail_compose_header_from($attrib) |
|---|
| 248 | { |
|---|
| 249 | global $IMAP, $MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME, $compose_mode; |
|---|
| 250 | |
|---|
| 251 | // pass the following attributes to the form class |
|---|
| 252 | $field_attrib = array('name' => '_from'); |
|---|
| 253 | foreach ($attrib as $attr => $value) |
|---|
| 254 | if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) |
|---|
| 255 | $field_attrib[$attr] = $value; |
|---|
| 256 | |
|---|
| 257 | // extract all recipients of the reply-message |
|---|
| 258 | $a_recipients = array(); |
|---|
| 259 | if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers'])) |
|---|
| 260 | { |
|---|
| 261 | $MESSAGE['FROM'] = array(); |
|---|
| 262 | |
|---|
| 263 | $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to); |
|---|
| 264 | foreach ($a_to as $addr) |
|---|
| 265 | { |
|---|
| 266 | if (!empty($addr['mailto'])) |
|---|
| 267 | $a_recipients[] = $addr['mailto']; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | if (!empty($MESSAGE['headers']->cc)) |
|---|
| 271 | { |
|---|
| 272 | $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc); |
|---|
| 273 | foreach ($a_cc as $addr) |
|---|
| 274 | { |
|---|
| 275 | if (!empty($addr['mailto'])) |
|---|
| 276 | $a_recipients[] = $addr['mailto']; |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | // get this user's identities |
|---|
| 282 | $sql_result = $DB->query("SELECT identity_id, name, email, signature, html_signature |
|---|
| 283 | FROM ".get_table_name('identities')." |
|---|
| 284 | WHERE user_id=? |
|---|
| 285 | AND del<>1 |
|---|
| 286 | ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC", |
|---|
| 287 | $_SESSION['user_id']); |
|---|
| 288 | |
|---|
| 289 | if ($DB->num_rows($sql_result)) |
|---|
| 290 | { |
|---|
| 291 | $from_id = 0; |
|---|
| 292 | $a_signatures = array(); |
|---|
| 293 | |
|---|
| 294 | $field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)"; |
|---|
| 295 | $select_from = new select($field_attrib); |
|---|
| 296 | |
|---|
| 297 | while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|---|
| 298 | { |
|---|
| 299 | $identity_id = $sql_arr['identity_id']; |
|---|
| 300 | $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id); |
|---|
| 301 | |
|---|
| 302 | // add signature to array |
|---|
| 303 | if (!empty($sql_arr['signature'])) |
|---|
| 304 | { |
|---|
| 305 | $a_signatures[$identity_id]['text'] = $sql_arr['signature']; |
|---|
| 306 | $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false; |
|---|
| 307 | if ($a_signatures[$identity_id]['is_html']) |
|---|
| 308 | { |
|---|
| 309 | $h2t = new html2text($a_signatures[$identity_id]['text'], false, false); |
|---|
| 310 | $plainTextPart = $h2t->get_text(); |
|---|
| 311 | $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart); |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | // set identity if it's one of the reply-message recipients |
|---|
| 316 | if (in_array($sql_arr['email'], $a_recipients)) |
|---|
| 317 | $from_id = $sql_arr['identity_id']; |
|---|
| 318 | |
|---|
| 319 | if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE['FROM'])) |
|---|
| 320 | $MESSAGE['FROM'][] = $sql_arr['email']; |
|---|
| 321 | |
|---|
| 322 | if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email'])) |
|---|
| 323 | $from_id = $sql_arr['identity_id']; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | // overwrite identity selection with post parameter |
|---|
| 327 | if (isset($_POST['_from'])) |
|---|
| 328 | $from_id = get_input_value('_from', RCUBE_INPUT_POST); |
|---|
| 329 | |
|---|
| 330 | $out = $select_from->show($from_id); |
|---|
| 331 | |
|---|
| 332 | // add signatures to client |
|---|
| 333 | $OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures))); |
|---|
| 334 | } |
|---|
| 335 | else |
|---|
| 336 | { |
|---|
| 337 | $input_from = new textfield($field_attrib); |
|---|
| 338 | $out = $input_from->show($_POST['_from']); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | if ($form_start) |
|---|
| 342 | $out = $form_start.$out; |
|---|
| 343 | |
|---|
| 344 | return $out; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | function rcmail_compose_body($attrib) |
|---|
| 350 | { |
|---|
| 351 | global $CONFIG, $OUTPUT, $MESSAGE, $JS_OBJECT_NAME, $compose_mode; |
|---|
| 352 | |
|---|
| 353 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 354 | unset($attrib['form']); |
|---|
| 355 | |
|---|
| 356 | if (empty($attrib['id'])) |
|---|
| 357 | $attrib['id'] = 'rcmComposeMessage'; |
|---|
| 358 | |
|---|
| 359 | $attrib['name'] = '_message'; |
|---|
| 360 | |
|---|
| 361 | if ($CONFIG['htmleditor']) |
|---|
| 362 | $isHtml = true; |
|---|
| 363 | else |
|---|
| 364 | $isHtml = false; |
|---|
| 365 | |
|---|
| 366 | $body = ''; |
|---|
| 367 | |
|---|
| 368 | // use posted message body |
|---|
| 369 | if (!empty($_POST['_message'])) |
|---|
| 370 | { |
|---|
| 371 | $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE); |
|---|
| 372 | } |
|---|
| 373 | // compose reply-body |
|---|
| 374 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 375 | { |
|---|
| 376 | $hasHtml = rcmail_has_html_part($MESSAGE['parts']); |
|---|
| 377 | if ($hasHtml && $CONFIG['htmleditor']) |
|---|
| 378 | { |
|---|
| 379 | $body = rcmail_first_html_part($MESSAGE); |
|---|
| 380 | $isHtml = true; |
|---|
| 381 | } |
|---|
| 382 | else |
|---|
| 383 | { |
|---|
| 384 | $body = rcmail_first_text_part($MESSAGE); |
|---|
| 385 | $isHtml = false; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | $body = rcmail_create_reply_body($body, $isHtml); |
|---|
| 389 | } |
|---|
| 390 | // forward message body inline |
|---|
| 391 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 392 | { |
|---|
| 393 | $hasHtml = rcmail_has_html_part($MESSAGE['parts']); |
|---|
| 394 | if ($hasHtml && $CONFIG['htmleditor']) |
|---|
| 395 | { |
|---|
| 396 | $body = rcmail_first_html_part($MESSAGE); |
|---|
| 397 | $isHtml = true; |
|---|
| 398 | } |
|---|
| 399 | else |
|---|
| 400 | { |
|---|
| 401 | $body = rcmail_first_text_part($MESSAGE); |
|---|
| 402 | $isHtml = false; |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | $body = rcmail_create_forward_body($body, $isHtml); |
|---|
| 406 | } |
|---|
| 407 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 408 | { |
|---|
| 409 | $hasHtml = rcmail_has_html_part($MESSAGE['parts']); |
|---|
| 410 | if ($hasHtml && $CONFIG['htmleditor']) |
|---|
| 411 | { |
|---|
| 412 | $body = rcmail_first_html_part($MESSAGE); |
|---|
| 413 | $isHtml = true; |
|---|
| 414 | } |
|---|
| 415 | else |
|---|
| 416 | { |
|---|
| 417 | $body = rcmail_first_text_part($MESSAGE); |
|---|
| 418 | $isHtml = false; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | $body = rcmail_create_draft_body($body, $isHtml); |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | $OUTPUT->include_script('tiny_mce/tiny_mce.js'); |
|---|
| 425 | $OUTPUT->include_script("editor.js"); |
|---|
| 426 | $OUTPUT->add_script('rcmail_editor_init("$__skin_path");'); |
|---|
| 427 | |
|---|
| 428 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 429 | |
|---|
| 430 | $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE['headers']->messageID) : '')); |
|---|
| 431 | $out .= $saveid->show(); |
|---|
| 432 | |
|---|
| 433 | $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes')); |
|---|
| 434 | $out .= $drafttoggle->show(); |
|---|
| 435 | |
|---|
| 436 | $msgtype = new hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0"))); |
|---|
| 437 | $out .= $msgtype->show(); |
|---|
| 438 | |
|---|
| 439 | // If desired, set this text area to be editable by TinyMCE |
|---|
| 440 | if ($isHtml) |
|---|
| 441 | $attrib['mce_editable'] = "true"; |
|---|
| 442 | $textarea = new textarea($attrib); |
|---|
| 443 | $out .= $textarea->show($body); |
|---|
| 444 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 445 | |
|---|
| 446 | // include GoogieSpell |
|---|
| 447 | if (!empty($CONFIG['enable_spellcheck']) && !$isHtml) |
|---|
| 448 | { |
|---|
| 449 | $lang_set = ''; |
|---|
| 450 | if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages'])) |
|---|
| 451 | $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n"; |
|---|
| 452 | |
|---|
| 453 | $OUTPUT->include_script('googiespell.js'); |
|---|
| 454 | $OUTPUT->add_script(sprintf( |
|---|
| 455 | "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n". |
|---|
| 456 | "googie.lang_chck_spell = \"%s\";\n". |
|---|
| 457 | "googie.lang_rsm_edt = \"%s\";\n". |
|---|
| 458 | "googie.lang_close = \"%s\";\n". |
|---|
| 459 | "googie.lang_revert = \"%s\";\n". |
|---|
| 460 | "googie.lang_no_error_found = \"%s\";\n%s". |
|---|
| 461 | "googie.setCurrentLanguage('%s');\n". |
|---|
| 462 | "googie.decorateTextarea('%s');\n". |
|---|
| 463 | "%s.set_env('spellcheck', googie);", |
|---|
| 464 | $GLOBALS['COMM_PATH'], |
|---|
| 465 | JQ(Q(rcube_label('checkspelling'))), |
|---|
| 466 | JQ(Q(rcube_label('resumeediting'))), |
|---|
| 467 | JQ(Q(rcube_label('close'))), |
|---|
| 468 | JQ(Q(rcube_label('revertto'))), |
|---|
| 469 | JQ(Q(rcube_label('nospellerrors'))), |
|---|
| 470 | $lang_set, |
|---|
| 471 | substr($_SESSION['user_lang'], 0, 2), |
|---|
| 472 | $attrib['id'], |
|---|
| 473 | $JS_OBJECT_NAME), 'foot'); |
|---|
| 474 | |
|---|
| 475 | rcube_add_label('checking'); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>'; |
|---|
| 479 | |
|---|
| 480 | return $out; |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | function rcmail_create_reply_body($body, $bodyIsHtml) |
|---|
| 485 | { |
|---|
| 486 | global $IMAP, $MESSAGE; |
|---|
| 487 | |
|---|
| 488 | if (! $bodyIsHtml) |
|---|
| 489 | { |
|---|
| 490 | // soft-wrap message first |
|---|
| 491 | $body = wordwrap($body, 75); |
|---|
| 492 | |
|---|
| 493 | // split body into single lines |
|---|
| 494 | $a_lines = preg_split('/\r?\n/', $body); |
|---|
| 495 | |
|---|
| 496 | // add > to each line |
|---|
| 497 | for($n=0; $n<sizeof($a_lines); $n++) |
|---|
| 498 | { |
|---|
| 499 | if (strpos($a_lines[$n], '>')===0) |
|---|
| 500 | $a_lines[$n] = '>'.$a_lines[$n]; |
|---|
| 501 | else |
|---|
| 502 | $a_lines[$n] = '> '.$a_lines[$n]; |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | $body = join("\n", $a_lines); |
|---|
| 506 | |
|---|
| 507 | // add title line |
|---|
| 508 | $prefix = sprintf("\n\n\nOn %s, %s wrote:\n", |
|---|
| 509 | $MESSAGE['headers']->date, |
|---|
| 510 | $IMAP->decode_header($MESSAGE['headers']->from)); |
|---|
| 511 | |
|---|
| 512 | // try to remove the signature |
|---|
| 513 | if ($sp = strrstr($body, '-- ')) |
|---|
| 514 | { |
|---|
| 515 | if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") |
|---|
| 516 | $body = substr($body, 0, $sp-1); |
|---|
| 517 | } |
|---|
| 518 | $suffix = ''; |
|---|
| 519 | } |
|---|
| 520 | else |
|---|
| 521 | { |
|---|
| 522 | $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " . |
|---|
| 523 | "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " . |
|---|
| 524 | "margin-left: 5px; width: 100%%\">", |
|---|
| 525 | $MESSAGE['headers']->date, |
|---|
| 526 | $IMAP->decode_header($MESSAGE['headers']->from)); |
|---|
| 527 | |
|---|
| 528 | $suffix = "</blockquote>"; |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | return $prefix.$body.$suffix; |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | function rcmail_create_forward_body($body, $bodyIsHtml) |
|---|
| 536 | { |
|---|
| 537 | global $IMAP, $MESSAGE; |
|---|
| 538 | |
|---|
| 539 | if (! $bodyIsHtml) |
|---|
| 540 | { |
|---|
| 541 | // soft-wrap message first |
|---|
| 542 | $body = wordwrap($body, 80); |
|---|
| 543 | |
|---|
| 544 | $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n", |
|---|
| 545 | $MESSAGE['subject'], |
|---|
| 546 | $MESSAGE['headers']->date, |
|---|
| 547 | $IMAP->decode_header($MESSAGE['headers']->from), |
|---|
| 548 | $IMAP->decode_header($MESSAGE['headers']->to)); |
|---|
| 549 | } |
|---|
| 550 | else |
|---|
| 551 | { |
|---|
| 552 | $prefix = sprintf( |
|---|
| 553 | "<br><br>-------- Original Message --------" . |
|---|
| 554 | "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . |
|---|
| 555 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" . |
|---|
| 556 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" . |
|---|
| 557 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" . |
|---|
| 558 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" . |
|---|
| 559 | "</tbody></table><br>", |
|---|
| 560 | Q($MESSAGE['subject']), |
|---|
| 561 | Q($MESSAGE['headers']->date), |
|---|
| 562 | Q($IMAP->decode_header($MESSAGE['headers']->from)), |
|---|
| 563 | Q($IMAP->decode_header($MESSAGE['headers']->to))); |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | // add attachments |
|---|
| 567 | if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE['parts'])) |
|---|
| 568 | rcmail_write_compose_attachments($MESSAGE); |
|---|
| 569 | |
|---|
| 570 | return $prefix.$body; |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | function rcmail_create_draft_body($body, $bodyIsHtml) |
|---|
| 575 | { |
|---|
| 576 | global $IMAP, $MESSAGE; |
|---|
| 577 | |
|---|
| 578 | // add attachments |
|---|
| 579 | if (!isset($_SESSION['compose']['forward_attachments']) && |
|---|
| 580 | is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1) |
|---|
| 581 | rcmail_write_compose_attachments($MESSAGE); |
|---|
| 582 | |
|---|
| 583 | return $body; |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | function rcmail_write_compose_attachments(&$message) |
|---|
| 588 | { |
|---|
| 589 | global $IMAP, $CONFIG; |
|---|
| 590 | |
|---|
| 591 | $temp_dir = unslashify($CONFIG['temp_dir']); |
|---|
| 592 | |
|---|
| 593 | if (!is_array($_SESSION['compose']['attachments'])) |
|---|
| 594 | $_SESSION['compose']['attachments'] = array(); |
|---|
| 595 | |
|---|
| 596 | foreach ($message['parts'] as $pid => $part) |
|---|
| 597 | { |
|---|
| 598 | if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' && |
|---|
| 599 | ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || |
|---|
| 600 | (empty($part->disposition) && $part->filename))) |
|---|
| 601 | { |
|---|
| 602 | $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); |
|---|
| 603 | if ($fp = fopen($tmp_path, 'w')) |
|---|
| 604 | { |
|---|
| 605 | fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding)); |
|---|
| 606 | fclose($fp); |
|---|
| 607 | |
|---|
| 608 | $_SESSION['compose']['attachments'][] = array( |
|---|
| 609 | 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|---|
| 610 | 'name' => $part->filename, |
|---|
| 611 | 'path' => $tmp_path |
|---|
| 612 | ); |
|---|
| 613 | } |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | $_SESSION['compose']['forward_attachments'] = TRUE; |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | function rcmail_compose_subject($attrib) |
|---|
| 622 | { |
|---|
| 623 | global $CONFIG, $MESSAGE, $compose_mode; |
|---|
| 624 | |
|---|
| 625 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 626 | unset($attrib['form']); |
|---|
| 627 | |
|---|
| 628 | $attrib['name'] = '_subject'; |
|---|
| 629 | $textfield = new textfield($attrib); |
|---|
| 630 | |
|---|
| 631 | $subject = ''; |
|---|
| 632 | |
|---|
| 633 | // use subject from post |
|---|
| 634 | if (isset($_POST['_subject'])) |
|---|
| 635 | $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE); |
|---|
| 636 | |
|---|
| 637 | // create a reply-subject |
|---|
| 638 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 639 | { |
|---|
| 640 | if (eregi('^re:', $MESSAGE['subject'])) |
|---|
| 641 | $subject = $MESSAGE['subject']; |
|---|
| 642 | else |
|---|
| 643 | $subject = 'Re: '.$MESSAGE['subject']; |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | // create a forward-subject |
|---|
| 647 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 648 | { |
|---|
| 649 | if (eregi('^fwd:', $MESSAGE['subject'])) |
|---|
| 650 | $subject = $MESSAGE['subject']; |
|---|
| 651 | else |
|---|
| 652 | $subject = 'Fwd: '.$MESSAGE['subject']; |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | // creeate a draft-subject |
|---|
| 656 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 657 | $subject = $MESSAGE['subject']; |
|---|
| 658 | |
|---|
| 659 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 660 | $out .= $textfield->show($subject); |
|---|
| 661 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 662 | |
|---|
| 663 | return $out; |
|---|
| 664 | } |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | function rcmail_compose_attachment_list($attrib) |
|---|
| 668 | { |
|---|
| 669 | global $OUTPUT, $JS_OBJECT_NAME, $CONFIG; |
|---|
| 670 | |
|---|
| 671 | // add ID if not given |
|---|
| 672 | if (!$attrib['id']) |
|---|
| 673 | $attrib['id'] = 'rcmAttachmentList'; |
|---|
| 674 | |
|---|
| 675 | // allow the following attributes to be added to the <ul> tag |
|---|
| 676 | $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); |
|---|
| 677 | |
|---|
| 678 | $out = '<ul'. $attrib_str . ">\n"; |
|---|
| 679 | |
|---|
| 680 | if (is_array($_SESSION['compose']['attachments'])) |
|---|
| 681 | { |
|---|
| 682 | if ($attrib['deleteicon']) |
|---|
| 683 | $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', |
|---|
| 684 | $CONFIG['skin_path'], |
|---|
| 685 | $attrib['deleteicon'], |
|---|
| 686 | rcube_label('delete')); |
|---|
| 687 | else |
|---|
| 688 | $button = rcube_label('delete'); |
|---|
| 689 | |
|---|
| 690 | foreach ($_SESSION['compose']['attachments'] as $id => $a_prop) |
|---|
| 691 | $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>', |
|---|
| 692 | $id, |
|---|
| 693 | $JS_OBJECT_NAME, |
|---|
| 694 | $id, |
|---|
| 695 | Q(rcube_label('delete')), |
|---|
| 696 | $button, |
|---|
| 697 | Q($a_prop['name'])); |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | $OUTPUT->add_script(sprintf("%s.gui_object('attachmentlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); |
|---|
| 701 | |
|---|
| 702 | $out .= '</ul>'; |
|---|
| 703 | return $out; |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | function rcmail_compose_attachment_form($attrib) |
|---|
| 709 | { |
|---|
| 710 | global $OUTPUT, $JS_OBJECT_NAME, $SESS_HIDDEN_FIELD; |
|---|
| 711 | |
|---|
| 712 | // add ID if not given |
|---|
| 713 | if (!$attrib['id']) |
|---|
| 714 | $attrib['id'] = 'rcmUploadbox'; |
|---|
| 715 | |
|---|
| 716 | // allow the following attributes to be added to the <div> tag |
|---|
| 717 | $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); |
|---|
| 718 | $input_field = rcmail_compose_attachment_field(array()); |
|---|
| 719 | $label_send = rcube_label('upload'); |
|---|
| 720 | $label_close = rcube_label('close'); |
|---|
| 721 | |
|---|
| 722 | $out = <<<EOF |
|---|
| 723 | <div$attrib_str> |
|---|
| 724 | <form action="./" method="post" enctype="multipart/form-data"> |
|---|
| 725 | $SESS_HIDDEN_FIELD |
|---|
| 726 | $input_field<br /> |
|---|
| 727 | <input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" /> |
|---|
| 728 | <input type="button" value="$label_send" class="button" onclick="$JS_OBJECT_NAME.command('send-attachment', this.form)" /> |
|---|
| 729 | </form> |
|---|
| 730 | </div> |
|---|
| 731 | EOF; |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | $OUTPUT->add_script(sprintf("%s.gui_object('uploadbox', '%s');", $JS_OBJECT_NAME, $attrib['id'])); |
|---|
| 735 | return $out; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | function rcmail_compose_attachment_field($attrib) |
|---|
| 740 | { |
|---|
| 741 | // allow the following attributes to be added to the <input> tag |
|---|
| 742 | $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size')); |
|---|
| 743 | |
|---|
| 744 | $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />"; |
|---|
| 745 | return $out; |
|---|
| 746 | } |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | function rcmail_priority_selector($attrib) |
|---|
| 750 | { |
|---|
| 751 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 752 | unset($attrib['form']); |
|---|
| 753 | |
|---|
| 754 | $attrib['name'] = '_priority'; |
|---|
| 755 | $selector = new select($attrib); |
|---|
| 756 | |
|---|
| 757 | $selector->add(array(rcube_label('lowest'), |
|---|
| 758 | rcube_label('low'), |
|---|
| 759 | rcube_label('normal'), |
|---|
| 760 | rcube_label('high'), |
|---|
| 761 | rcube_label('highest')), |
|---|
| 762 | array(5, 4, 0, 2, 1)); |
|---|
| 763 | |
|---|
| 764 | $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0; |
|---|
| 765 | |
|---|
| 766 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 767 | $out .= $selector->show($sel); |
|---|
| 768 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 769 | |
|---|
| 770 | return $out; |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | function rcmail_receipt_checkbox($attrib) |
|---|
| 775 | { |
|---|
| 776 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 777 | unset($attrib['form']); |
|---|
| 778 | |
|---|
| 779 | if (!isset($attrib['id'])) |
|---|
| 780 | $attrib['id'] = 'receipt'; |
|---|
| 781 | |
|---|
| 782 | $attrib['name'] = '_receipt'; |
|---|
| 783 | $attrib['value'] = '1'; |
|---|
| 784 | $checkbox = new checkbox($attrib); |
|---|
| 785 | |
|---|
| 786 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 787 | $out .= $checkbox->show(0); |
|---|
| 788 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 789 | |
|---|
| 790 | return $out; |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | function rcmail_editor_selector($attrib) |
|---|
| 795 | { |
|---|
| 796 | global $CONFIG, $MESSAGE, $compose_mode; |
|---|
| 797 | |
|---|
| 798 | $choices = array( |
|---|
| 799 | 'html' => 'htmltoggle', |
|---|
| 800 | 'plain' => 'plaintoggle' |
|---|
| 801 | ); |
|---|
| 802 | |
|---|
| 803 | // determine whether HTML or plain text should be checked |
|---|
| 804 | if ($CONFIG['htmleditor']) |
|---|
| 805 | $useHtml = true; |
|---|
| 806 | else |
|---|
| 807 | $useHtml = false; |
|---|
| 808 | |
|---|
| 809 | if ($compose_mode == RCUBE_COMPOSE_REPLY || |
|---|
| 810 | $compose_mode == RCUBE_COMPOSE_FORWARD || |
|---|
| 811 | $compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 812 | { |
|---|
| 813 | $hasHtml = rcmail_has_html_part($MESSAGE['parts']); |
|---|
| 814 | $useHtml = ($hasHtml && $CONFIG['htmleditor']); |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | $selector = ''; |
|---|
| 818 | |
|---|
| 819 | $attrib['name'] = '_editorSelect'; |
|---|
| 820 | $attrib['onchange'] = 'return rcmail_toggle_editor(this)'; |
|---|
| 821 | foreach ($choices as $value => $text) |
|---|
| 822 | { |
|---|
| 823 | $checked = ''; |
|---|
| 824 | if ((($value == 'html') && $useHtml) || |
|---|
| 825 | (($value != 'html') && !$useHtml)) |
|---|
| 826 | $attrib['checked'] = 'true'; |
|---|
| 827 | else |
|---|
| 828 | unset($attrib['checked']); |
|---|
| 829 | |
|---|
| 830 | $attrib['id'] = '_' . $value; |
|---|
| 831 | $rb = new radiobutton($attrib); |
|---|
| 832 | $selector .= sprintf("<td>%s</td><td class=\"title\"><label for=\"%s\">%s</label></td>", |
|---|
| 833 | $rb->show($value), |
|---|
| 834 | $attrib['id'], |
|---|
| 835 | rcube_label($text)); |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | return $selector; |
|---|
| 839 | } |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | function get_form_tags($attrib) |
|---|
| 843 | { |
|---|
| 844 | global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; |
|---|
| 845 | |
|---|
| 846 | $form_start = ''; |
|---|
| 847 | if (!strlen($MESSAGE_FORM)) |
|---|
| 848 | { |
|---|
| 849 | $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); |
|---|
| 850 | $hiddenfields->add(array('name' => '_action', 'value' => 'send')); |
|---|
| 851 | |
|---|
| 852 | $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; |
|---|
| 853 | $form_start .= "\n$SESS_HIDDEN_FIELD\n"; |
|---|
| 854 | $form_start .= $hiddenfields->show(); |
|---|
| 855 | } |
|---|
| 856 | |
|---|
| 857 | $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : ''; |
|---|
| 858 | $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
|---|
| 859 | |
|---|
| 860 | if (!strlen($MESSAGE_FORM)) |
|---|
| 861 | $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');"); |
|---|
| 862 | |
|---|
| 863 | $MESSAGE_FORM = $form_name; |
|---|
| 864 | |
|---|
| 865 | return array($form_start, $form_end); |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | function format_email_recipient($email, $name='') |
|---|
| 870 | { |
|---|
| 871 | if ($name && $name != $email) |
|---|
| 872 | return sprintf('%s <%s>', strpos($name, ",") ? '"'.$name.'"' : $name, $email); |
|---|
| 873 | else |
|---|
| 874 | return $email; |
|---|
| 875 | } |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | function rcmail_charset_pulldown($selected='ISO-8859-1') |
|---|
| 879 | { |
|---|
| 880 | $select = new select(); |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | return $select->show($selected); |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | /****** get contacts for this user and add them to client scripts ********/ |
|---|
| 888 | |
|---|
| 889 | $sql_result = $DB->query("SELECT name, email |
|---|
| 890 | FROM ".get_table_name('contacts')." WHERE user_id=? |
|---|
| 891 | AND del<>1",$_SESSION['user_id']); |
|---|
| 892 | |
|---|
| 893 | if ($DB->num_rows($sql_result)) |
|---|
| 894 | { |
|---|
| 895 | $a_contacts = array(); |
|---|
| 896 | while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|---|
| 897 | if ($sql_arr['email']) |
|---|
| 898 | $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name'])); |
|---|
| 899 | |
|---|
| 900 | $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts))); |
|---|
| 901 | } |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | parse_template('compose'); |
|---|
| 905 | ?> |
|---|