| 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-2008, 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 | // define constants for message compose mode |
|---|
| 23 | define('RCUBE_COMPOSE_REPLY', 0x0106); |
|---|
| 24 | define('RCUBE_COMPOSE_FORWARD', 0x0107); |
|---|
| 25 | define('RCUBE_COMPOSE_DRAFT', 0x0108); |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | // remove an attachment |
|---|
| 29 | if ($RCMAIL->action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) |
|---|
| 30 | { |
|---|
| 31 | $id = $regs[1]; |
|---|
| 32 | if (is_array($_SESSION['compose']['attachments'][$id])) |
|---|
| 33 | { |
|---|
| 34 | @unlink($_SESSION['compose']['attachments'][$id]['path']); |
|---|
| 35 | unset($_SESSION['compose']['attachments'][$id]); |
|---|
| 36 | $OUTPUT->command('remove_from_attachment_list', "rcmfile$id"); |
|---|
| 37 | $OUTPUT->send(); |
|---|
| 38 | } |
|---|
| 39 | exit; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if ($RCMAIL->action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) |
|---|
| 43 | { |
|---|
| 44 | $id = $regs[1]; |
|---|
| 45 | if (is_array($_SESSION['compose']['attachments'][$id])) |
|---|
| 46 | { |
|---|
| 47 | $apath = $_SESSION['compose']['attachments'][$id]['path']; |
|---|
| 48 | header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']); |
|---|
| 49 | header('Content-Length: ' . filesize($apath)); |
|---|
| 50 | readfile($apath); |
|---|
| 51 | } |
|---|
| 52 | exit; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | $MESSAGE_FORM = NULL; |
|---|
| 56 | $MESSAGE = NULL; |
|---|
| 57 | |
|---|
| 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 |
|---|
| 62 | |
|---|
| 63 | if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET)) |
|---|
| 64 | { |
|---|
| 65 | rcmail_compose_cleanup(); |
|---|
| 66 | $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET)); |
|---|
| 67 | |
|---|
| 68 | // process values like "mailto:foo@bar.com?subject=new+message&cc=another" |
|---|
| 69 | if ($_SESSION['compose']['param']['_to']) { |
|---|
| 70 | $mailto = explode('?', $_SESSION['compose']['param']['_to']); |
|---|
| 71 | if (count($mailto) > 1) { |
|---|
| 72 | $_SESSION['compose']['param']['_to'] = $mailto[0]; |
|---|
| 73 | parse_str($mailto[1], $query); |
|---|
| 74 | foreach ($query as $f => $val) |
|---|
| 75 | $_SESSION['compose']['param']["_$f"] = $val; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | // redirect to a unique URL with all parameters stored in session |
|---|
| 80 | $OUTPUT->redirect(array('_action' => 'compose', '_id' => $_SESSION['compose']['id'])); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | // add some labels to client |
|---|
| 84 | $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', |
|---|
| 85 | 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', |
|---|
| 86 | 'converting', 'editorwarning'); |
|---|
| 87 | |
|---|
| 88 | // add config parameters to client script |
|---|
| 89 | if (!empty($CONFIG['drafts_mbox'])) { |
|---|
| 90 | $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); |
|---|
| 91 | $OUTPUT->set_env('draft_autosave', $CONFIG['draft_autosave']); |
|---|
| 92 | } |
|---|
| 93 | // set current mailbox in client environment |
|---|
| 94 | $OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name()); |
|---|
| 95 | |
|---|
| 96 | // get reference message and set compose mode |
|---|
| 97 | if ($msg_uid = $_SESSION['compose']['param']['_reply_uid']) |
|---|
| 98 | $compose_mode = RCUBE_COMPOSE_REPLY; |
|---|
| 99 | else if ($msg_uid = $_SESSION['compose']['param']['_forward_uid']) |
|---|
| 100 | $compose_mode = RCUBE_COMPOSE_FORWARD; |
|---|
| 101 | else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid']) |
|---|
| 102 | $compose_mode = RCUBE_COMPOSE_DRAFT; |
|---|
| 103 | |
|---|
| 104 | if (!empty($msg_uid)) |
|---|
| 105 | { |
|---|
| 106 | // similar as in program/steps/mail/show.inc |
|---|
| 107 | $MESSAGE = new rcube_message($msg_uid); |
|---|
| 108 | |
|---|
| 109 | if (!empty($MESSAGE->headers->charset)) |
|---|
| 110 | $IMAP->set_charset($MESSAGE->headers->charset); |
|---|
| 111 | |
|---|
| 112 | if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 113 | { |
|---|
| 114 | $_SESSION['compose']['reply_uid'] = $msg_uid; |
|---|
| 115 | $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID; |
|---|
| 116 | $_SESSION['compose']['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID); |
|---|
| 117 | |
|---|
| 118 | if (!empty($_SESSION['compose']['param']['_all'])) |
|---|
| 119 | $MESSAGE->reply_all = 1; |
|---|
| 120 | } |
|---|
| 121 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 122 | { |
|---|
| 123 | if($MESSAGE->headers->in_reply_to) |
|---|
| 124 | { |
|---|
| 125 | // TODO: how to get reply_uid/forward_uid value, maybe we must set X-Reply-UID/X-Forward-UID |
|---|
| 126 | // $_SESSION['compose']['reply_uid'] = ? |
|---|
| 127 | // $_SESSION['compose']['forward_uid'] = ? |
|---|
| 128 | $_SESSION['compose']['reply_msgid'] = '<'.$MESSAGE->headers->in_reply_to.'>'; |
|---|
| 129 | } |
|---|
| 130 | $_SESSION['compose']['references'] = $MESSAGE->headers->references; |
|---|
| 131 | } |
|---|
| 132 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 133 | { |
|---|
| 134 | $_SESSION['compose']['forward_uid'] = $msg_uid; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /****** compose mode functions ********/ |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | function rcmail_compose_headers($attrib) |
|---|
| 142 | { |
|---|
| 143 | global $IMAP, $MESSAGE, $DB, $compose_mode; |
|---|
| 144 | static $sa_recipients = array(); |
|---|
| 145 | |
|---|
| 146 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 147 | |
|---|
| 148 | $out = ''; |
|---|
| 149 | $part = strtolower($attrib['part']); |
|---|
| 150 | |
|---|
| 151 | switch ($part) |
|---|
| 152 | { |
|---|
| 153 | case 'from': |
|---|
| 154 | return rcmail_compose_header_from($attrib); |
|---|
| 155 | |
|---|
| 156 | case 'to': |
|---|
| 157 | $fname = '_to'; |
|---|
| 158 | $header = 'to'; |
|---|
| 159 | |
|---|
| 160 | // we have a set of recipients stored is session |
|---|
| 161 | if (($mailto_id = $_SESSION['compose']['param']['_mailto']) && $_SESSION['mailto'][$mailto_id]) |
|---|
| 162 | $fvalue = urldecode($_SESSION['mailto'][$mailto_id]); |
|---|
| 163 | |
|---|
| 164 | case 'cc': |
|---|
| 165 | if (!$fname) |
|---|
| 166 | { |
|---|
| 167 | $fname = '_cc'; |
|---|
| 168 | $header = 'cc'; |
|---|
| 169 | } |
|---|
| 170 | case 'bcc': |
|---|
| 171 | if (!$fname) |
|---|
| 172 | { |
|---|
| 173 | $fname = '_bcc'; |
|---|
| 174 | $header = 'bcc'; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex'); |
|---|
| 178 | $field_type = 'html_textarea'; |
|---|
| 179 | break; |
|---|
| 180 | |
|---|
| 181 | case 'replyto': |
|---|
| 182 | case 'reply-to': |
|---|
| 183 | $fname = '_replyto'; |
|---|
| 184 | $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex'); |
|---|
| 185 | $field_type = 'html_inputfield'; |
|---|
| 186 | break; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | if ($fname && !empty($_POST[$fname])) |
|---|
| 190 | $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE); |
|---|
| 191 | else if ($fname && !$fvalue && !empty($_SESSION['compose']['param'][$fname])) |
|---|
| 192 | $fvalue = $_SESSION['compose']['param'][$fname]; |
|---|
| 193 | |
|---|
| 194 | else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 195 | { |
|---|
| 196 | // get recipent address(es) out of the message headers |
|---|
| 197 | if ($header=='to' && !empty($MESSAGE->headers->replyto)) |
|---|
| 198 | $fvalue = $MESSAGE->headers->replyto; |
|---|
| 199 | |
|---|
| 200 | else if ($header=='to' && !empty($MESSAGE->headers->from)) |
|---|
| 201 | $fvalue = $MESSAGE->headers->from; |
|---|
| 202 | |
|---|
| 203 | // add recipent of original message if reply to all |
|---|
| 204 | else if ($header=='cc' && !empty($MESSAGE->reply_all)) |
|---|
| 205 | { |
|---|
| 206 | if ($v = $MESSAGE->headers->to) |
|---|
| 207 | $fvalue .= $v; |
|---|
| 208 | |
|---|
| 209 | if ($v = $MESSAGE->headers->cc) |
|---|
| 210 | $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | // split recipients and put them back together in a unique way |
|---|
| 214 | if (!empty($fvalue)) |
|---|
| 215 | { |
|---|
| 216 | $to_addresses = $IMAP->decode_address_list($fvalue); |
|---|
| 217 | $fvalue = ''; |
|---|
| 218 | |
|---|
| 219 | foreach ($to_addresses as $addr_part) |
|---|
| 220 | { |
|---|
| 221 | if (!empty($addr_part['mailto']) |
|---|
| 222 | && !in_array($addr_part['mailto'], $sa_recipients) |
|---|
| 223 | && (!$MESSAGE->compose_from |
|---|
| 224 | || !in_array_nocase($addr_part['mailto'], $MESSAGE->compose_from) |
|---|
| 225 | || count($to_addresses)==1)) // allow reply to yourself |
|---|
| 226 | { |
|---|
| 227 | $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; |
|---|
| 228 | $sa_recipients[] = $addr_part['mailto']; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 234 | { |
|---|
| 235 | // get drafted headers |
|---|
| 236 | if ($header=='to' && !empty($MESSAGE->headers->to)) |
|---|
| 237 | $fvalue = $MESSAGE->get_header('to'); |
|---|
| 238 | |
|---|
| 239 | if ($header=='cc' && !empty($MESSAGE->headers->cc)) |
|---|
| 240 | $fvalue = $MESSAGE->get_header('cc'); |
|---|
| 241 | |
|---|
| 242 | if ($header=='bcc' && !empty($MESSAGE->headers->bcc)) |
|---|
| 243 | $fvalue = $MESSAGE->get_header('bcc'); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | if ($fname && $field_type) |
|---|
| 248 | { |
|---|
| 249 | // pass the following attributes to the form class |
|---|
| 250 | $field_attrib = array('name' => $fname, 'spellcheck' => 'false'); |
|---|
| 251 | foreach ($attrib as $attr => $value) |
|---|
| 252 | if (in_array($attr, $allow_attrib)) |
|---|
| 253 | $field_attrib[$attr] = $value; |
|---|
| 254 | |
|---|
| 255 | // create teaxtarea object |
|---|
| 256 | $input = new $field_type($field_attrib); |
|---|
| 257 | $out = $input->show($fvalue); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | if ($form_start) |
|---|
| 261 | $out = $form_start.$out; |
|---|
| 262 | |
|---|
| 263 | return $out; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | function rcmail_compose_header_from($attrib) |
|---|
| 269 | { |
|---|
| 270 | global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode; |
|---|
| 271 | |
|---|
| 272 | // pass the following attributes to the form class |
|---|
| 273 | $field_attrib = array('name' => '_from'); |
|---|
| 274 | foreach ($attrib as $attr => $value) |
|---|
| 275 | if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) |
|---|
| 276 | $field_attrib[$attr] = $value; |
|---|
| 277 | |
|---|
| 278 | // extract all recipients of the reply-message |
|---|
| 279 | $a_recipients = array(); |
|---|
| 280 | if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE->headers)) |
|---|
| 281 | { |
|---|
| 282 | $MESSAGE->compose_from = array(); |
|---|
| 283 | |
|---|
| 284 | $a_to = $IMAP->decode_address_list($MESSAGE->headers->to); |
|---|
| 285 | foreach ($a_to as $addr) |
|---|
| 286 | { |
|---|
| 287 | if (!empty($addr['mailto'])) |
|---|
| 288 | $a_recipients[] = rc_strtolower($addr['mailto']); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | if (!empty($MESSAGE->headers->cc)) |
|---|
| 292 | { |
|---|
| 293 | $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc); |
|---|
| 294 | foreach ($a_cc as $addr) |
|---|
| 295 | { |
|---|
| 296 | if (!empty($addr['mailto'])) |
|---|
| 297 | $a_recipients[] = rc_strtolower($addr['mailto']); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | // get this user's identities |
|---|
| 303 | $sql_result = $USER->list_identities(); |
|---|
| 304 | |
|---|
| 305 | if ($DB->num_rows($sql_result)) |
|---|
| 306 | { |
|---|
| 307 | $from_id = 0; |
|---|
| 308 | $a_signatures = array(); |
|---|
| 309 | |
|---|
| 310 | $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)"; |
|---|
| 311 | $select_from = new html_select($field_attrib); |
|---|
| 312 | |
|---|
| 313 | while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|---|
| 314 | { |
|---|
| 315 | $identity_id = $sql_arr['identity_id']; |
|---|
| 316 | $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id); |
|---|
| 317 | |
|---|
| 318 | // add signature to array |
|---|
| 319 | if (!empty($sql_arr['signature'])) |
|---|
| 320 | { |
|---|
| 321 | $a_signatures[$identity_id]['text'] = $sql_arr['signature']; |
|---|
| 322 | $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false; |
|---|
| 323 | if ($a_signatures[$identity_id]['is_html']) |
|---|
| 324 | { |
|---|
| 325 | $h2t = new html2text($a_signatures[$identity_id]['text'], false, false); |
|---|
| 326 | $plainTextPart = $h2t->get_text(); |
|---|
| 327 | $a_signatures[$identity_id]['plain_text'] = trim(html_entity_decode($plainTextPart, ENT_NOQUOTES, 'UTF-8')); |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE->compose_from)) |
|---|
| 332 | $MESSAGE->compose_from[] = $sql_arr['email']; |
|---|
| 333 | |
|---|
| 334 | if (empty($_POST['_from'])) |
|---|
| 335 | { |
|---|
| 336 | // set draft's identity |
|---|
| 337 | if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email'])) |
|---|
| 338 | $from_id = $sql_arr['identity_id']; |
|---|
| 339 | // set identity if it's one of the reply-message recipients (with prio for default identity) |
|---|
| 340 | else if (in_array(rc_strtolower($sql_arr['email']), $a_recipients) && (empty($from_id) || $sql_arr['standard'])) |
|---|
| 341 | $from_id = $sql_arr['identity_id']; |
|---|
| 342 | } |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | // overwrite identity selection with post parameter |
|---|
| 346 | if (!empty($_POST['_from'])) |
|---|
| 347 | $from_id = get_input_value('_from', RCUBE_INPUT_POST); |
|---|
| 348 | |
|---|
| 349 | $out = $select_from->show($from_id); |
|---|
| 350 | |
|---|
| 351 | // add signatures to client |
|---|
| 352 | $OUTPUT->set_env('signatures', $a_signatures); |
|---|
| 353 | } |
|---|
| 354 | else |
|---|
| 355 | { |
|---|
| 356 | $input_from = new html_inputfield($field_attrib); |
|---|
| 357 | $out = $input_from->show($_POST['_from']); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | if ($form_start) |
|---|
| 361 | $out = $form_start.$out; |
|---|
| 362 | |
|---|
| 363 | return $out; |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | function rcmail_compose_body($attrib) |
|---|
| 368 | { |
|---|
| 369 | global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode; |
|---|
| 370 | |
|---|
| 371 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 372 | unset($attrib['form']); |
|---|
| 373 | |
|---|
| 374 | if (empty($attrib['id'])) |
|---|
| 375 | $attrib['id'] = 'rcmComposeMessage'; |
|---|
| 376 | |
|---|
| 377 | $attrib['name'] = '_message'; |
|---|
| 378 | |
|---|
| 379 | if ($CONFIG['htmleditor']) |
|---|
| 380 | $isHtml = true; |
|---|
| 381 | else |
|---|
| 382 | $isHtml = false; |
|---|
| 383 | |
|---|
| 384 | $body = ''; |
|---|
| 385 | |
|---|
| 386 | // use posted message body |
|---|
| 387 | if (!empty($_POST['_message'])) |
|---|
| 388 | { |
|---|
| 389 | $body = get_input_value('_message', RCUBE_INPUT_POST, true); |
|---|
| 390 | } |
|---|
| 391 | else if ($compose_mode) |
|---|
| 392 | { |
|---|
| 393 | if ($isHtml && $MESSAGE->has_html_part()) |
|---|
| 394 | { |
|---|
| 395 | $body = $MESSAGE->first_html_part(); |
|---|
| 396 | $isHtml = true; |
|---|
| 397 | } |
|---|
| 398 | else |
|---|
| 399 | { |
|---|
| 400 | $body = $MESSAGE->first_text_part(); |
|---|
| 401 | $isHtml = false; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | // compose reply-body |
|---|
| 405 | if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 406 | $body = rcmail_create_reply_body($body, $isHtml); |
|---|
| 407 | // forward message body inline |
|---|
| 408 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 409 | $body = rcmail_create_forward_body($body, $isHtml); |
|---|
| 410 | // load draft message body |
|---|
| 411 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 412 | $body = rcmail_create_draft_body($body, $isHtml); |
|---|
| 413 | |
|---|
| 414 | if ($isHtml) { |
|---|
| 415 | // replace cid with href in inline images links |
|---|
| 416 | foreach ((array)$_SESSION['compose']['attachments'] as $pid => $attachment) { |
|---|
| 417 | if ($attachment['content_id']) { |
|---|
| 418 | $body = str_replace('cid:'. $attachment['content_id'], |
|---|
| 419 | $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$pid, $body); |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | } |
|---|
| 424 | else if (!empty($_SESSION['compose']['param']['_body'])) |
|---|
| 425 | { |
|---|
| 426 | $body = $_SESSION['compose']['param']['_body']; |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 430 | |
|---|
| 431 | $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : '')); |
|---|
| 432 | $out .= $saveid->show(); |
|---|
| 433 | |
|---|
| 434 | $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes')); |
|---|
| 435 | $out .= $drafttoggle->show(); |
|---|
| 436 | |
|---|
| 437 | $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0"))); |
|---|
| 438 | $out .= $msgtype->show(); |
|---|
| 439 | |
|---|
| 440 | // If desired, set this textarea to be editable by TinyMCE |
|---|
| 441 | if ($isHtml) $attrib['class'] = 'mce_editor'; |
|---|
| 442 | $textarea = new html_textarea($attrib); |
|---|
| 443 | $out .= $textarea->show($body); |
|---|
| 444 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 445 | |
|---|
| 446 | // include HTML editor |
|---|
| 447 | rcube_html_editor(); |
|---|
| 448 | |
|---|
| 449 | // include GoogieSpell |
|---|
| 450 | if (!empty($CONFIG['enable_spellcheck'])) { |
|---|
| 451 | |
|---|
| 452 | $lang = strtolower(substr($_SESSION['language'], 0, 2)); |
|---|
| 453 | |
|---|
| 454 | $spellcheck_langs = (array)$RCMAIL->config->get('spellcheck_languages', array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska')); |
|---|
| 455 | if (!$spellcheck_langs[$lang]) |
|---|
| 456 | $lang = 'en'; |
|---|
| 457 | |
|---|
| 458 | $editor_lang_set = array(); |
|---|
| 459 | foreach ($spellcheck_langs as $key => $name) { |
|---|
| 460 | $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | $OUTPUT->include_script('googiespell.js'); |
|---|
| 464 | $OUTPUT->add_script(sprintf( |
|---|
| 465 | "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n". |
|---|
| 466 | "googie.lang_chck_spell = \"%s\";\n". |
|---|
| 467 | "googie.lang_rsm_edt = \"%s\";\n". |
|---|
| 468 | "googie.lang_close = \"%s\";\n". |
|---|
| 469 | "googie.lang_revert = \"%s\";\n". |
|---|
| 470 | "googie.lang_no_error_found = \"%s\";\n". |
|---|
| 471 | "googie.setLanguages(%s);\n". |
|---|
| 472 | "googie.setCurrentLanguage('%s');\n". |
|---|
| 473 | "googie.decorateTextarea('%s');\n". |
|---|
| 474 | "%s.set_env('spellcheck', googie);", |
|---|
| 475 | $RCMAIL->comm_path, |
|---|
| 476 | JQ(Q(rcube_label('checkspelling'))), |
|---|
| 477 | JQ(Q(rcube_label('resumeediting'))), |
|---|
| 478 | JQ(Q(rcube_label('close'))), |
|---|
| 479 | JQ(Q(rcube_label('revertto'))), |
|---|
| 480 | JQ(Q(rcube_label('nospellerrors'))), |
|---|
| 481 | json_serialize($spellcheck_langs), |
|---|
| 482 | $lang, |
|---|
| 483 | $attrib['id'], |
|---|
| 484 | JS_OBJECT_NAME), 'foot'); |
|---|
| 485 | |
|---|
| 486 | $OUTPUT->add_label('checking'); |
|---|
| 487 | $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set)); |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>'; |
|---|
| 491 | |
|---|
| 492 | return $out; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | function rcmail_create_reply_body($body, $bodyIsHtml) |
|---|
| 497 | { |
|---|
| 498 | global $IMAP, $MESSAGE, $OUTPUT; |
|---|
| 499 | |
|---|
| 500 | if (! $bodyIsHtml) |
|---|
| 501 | { |
|---|
| 502 | // try to remove the signature |
|---|
| 503 | if (($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n")) |
|---|
| 504 | { |
|---|
| 505 | if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") |
|---|
| 506 | $body = substr($body, 0, max(0, $sp-1)); |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | // soft-wrap message first |
|---|
| 510 | $body = rcmail_wrap_quoted($body, 75); |
|---|
| 511 | |
|---|
| 512 | $body = rtrim($body, "\r\n"); |
|---|
| 513 | |
|---|
| 514 | if ($body) { |
|---|
| 515 | // split body into single lines |
|---|
| 516 | $a_lines = preg_split('/\r?\n/', $body); |
|---|
| 517 | |
|---|
| 518 | // add > to each line |
|---|
| 519 | for($n=0; $n<sizeof($a_lines); $n++) { |
|---|
| 520 | if (strpos($a_lines[$n], '>')===0) |
|---|
| 521 | $a_lines[$n] = '>'.$a_lines[$n]; |
|---|
| 522 | else |
|---|
| 523 | $a_lines[$n] = '> '.$a_lines[$n]; |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | $body = join("\n", $a_lines); |
|---|
| 527 | } |
|---|
| 528 | |
|---|
| 529 | // add title line(s) |
|---|
| 530 | $prefix = wordwrap(sprintf("On %s, %s wrote:\n", |
|---|
| 531 | $MESSAGE->headers->date, |
|---|
| 532 | $MESSAGE->get_header('from')), 76); |
|---|
| 533 | |
|---|
| 534 | $suffix = ''; |
|---|
| 535 | } |
|---|
| 536 | else |
|---|
| 537 | { |
|---|
| 538 | $prefix = sprintf("On %s, %s wrote:<br />\n", |
|---|
| 539 | $MESSAGE->headers->date, |
|---|
| 540 | htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset())); |
|---|
| 541 | $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">'; |
|---|
| 542 | $suffix = "</blockquote>"; |
|---|
| 543 | |
|---|
| 544 | rcmail_write_inline_attachments($MESSAGE); |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | return $prefix.$body.$suffix; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | |
|---|
| 551 | function rcmail_create_forward_body($body, $bodyIsHtml) |
|---|
| 552 | { |
|---|
| 553 | global $IMAP, $MESSAGE, $OUTPUT; |
|---|
| 554 | |
|---|
| 555 | if (!$bodyIsHtml) |
|---|
| 556 | { |
|---|
| 557 | $prefix = "\n\n\n-------- Original Message --------\n"; |
|---|
| 558 | $prefix .= 'Subject: ' . $MESSAGE->subject . "\n"; |
|---|
| 559 | $prefix .= 'Date: ' . $MESSAGE->headers->date . "\n"; |
|---|
| 560 | $prefix .= 'From: ' . $MESSAGE->get_header('from') . "\n"; |
|---|
| 561 | $prefix .= 'To: ' . $MESSAGE->get_header('to') . "\n"; |
|---|
| 562 | if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from) |
|---|
| 563 | $prefix .= 'Reply-To: ' . $MESSAGE->get_header('replyto') . "\n"; |
|---|
| 564 | $prefix .= "\n"; |
|---|
| 565 | } |
|---|
| 566 | else |
|---|
| 567 | { |
|---|
| 568 | $prefix = sprintf( |
|---|
| 569 | "<br><br>-------- Original Message --------" . |
|---|
| 570 | "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . |
|---|
| 571 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" . |
|---|
| 572 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" . |
|---|
| 573 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" . |
|---|
| 574 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>", |
|---|
| 575 | Q($MESSAGE->subject), |
|---|
| 576 | Q($MESSAGE->headers->date), |
|---|
| 577 | htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true), |
|---|
| 578 | htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true)); |
|---|
| 579 | |
|---|
| 580 | if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from) |
|---|
| 581 | $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Reply-To: </th><td>%s</td></tr>", |
|---|
| 582 | htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true)); |
|---|
| 583 | |
|---|
| 584 | $prefix .= "</tbody></table><br>"; |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | // add attachments |
|---|
| 588 | if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts)) |
|---|
| 589 | rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
|---|
| 590 | |
|---|
| 591 | return $prefix.$body; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | function rcmail_create_draft_body($body, $bodyIsHtml) |
|---|
| 596 | { |
|---|
| 597 | global $MESSAGE; |
|---|
| 598 | |
|---|
| 599 | /** |
|---|
| 600 | * add attachments |
|---|
| 601 | * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text! |
|---|
| 602 | */ |
|---|
| 603 | if (!isset($_SESSION['compose']['forward_attachments']) |
|---|
| 604 | && is_array($MESSAGE->mime_parts) |
|---|
| 605 | && count($MESSAGE->mime_parts) > 0) |
|---|
| 606 | rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
|---|
| 607 | |
|---|
| 608 | return $body; |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | function rcmail_write_compose_attachments(&$message, $bodyIsHtml) |
|---|
| 613 | { |
|---|
| 614 | foreach ((array)$message->mime_parts as $pid => $part) |
|---|
| 615 | { |
|---|
| 616 | if (($part->ctype_primary != 'message' || !$bodyIsHtml) && |
|---|
| 617 | ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] |
|---|
| 618 | || (empty($part->disposition) && $part->filename))) |
|---|
| 619 | { |
|---|
| 620 | if ($attachment = rcmail_save_attachment($message, $pid)) |
|---|
| 621 | $_SESSION['compose']['attachments'][] = $attachment; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | $_SESSION['compose']['forward_attachments'] = true; |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | function rcmail_write_inline_attachments(&$message) |
|---|
| 630 | { |
|---|
| 631 | foreach ((array)$message->mime_parts as $pid => $part) |
|---|
| 632 | { |
|---|
| 633 | if ($part->content_id && $part->filename) |
|---|
| 634 | { |
|---|
| 635 | if ($attachment = rcmail_save_attachment($message, $pid)) |
|---|
| 636 | $_SESSION['compose']['attachments'][] = $attachment; |
|---|
| 637 | } |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | function rcmail_save_attachment(&$message, $pid) |
|---|
| 642 | { |
|---|
| 643 | global $RCMAIL; |
|---|
| 644 | |
|---|
| 645 | $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); |
|---|
| 646 | $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); |
|---|
| 647 | $part = $message->mime_parts[$pid]; |
|---|
| 648 | |
|---|
| 649 | if ($fp = fopen($tmp_path, 'w')) |
|---|
| 650 | { |
|---|
| 651 | $message->get_part_content($pid, $fp); |
|---|
| 652 | fclose($fp); |
|---|
| 653 | |
|---|
| 654 | return array( |
|---|
| 655 | 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|---|
| 656 | 'name' => $part->filename, |
|---|
| 657 | 'path' => $tmp_path, |
|---|
| 658 | 'content_id' => $part->content_id |
|---|
| 659 | ); |
|---|
| 660 | } |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | function rcmail_compose_subject($attrib) |
|---|
| 665 | { |
|---|
| 666 | global $MESSAGE, $compose_mode; |
|---|
| 667 | |
|---|
| 668 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 669 | unset($attrib['form']); |
|---|
| 670 | |
|---|
| 671 | $attrib['name'] = '_subject'; |
|---|
| 672 | $attrib['spellcheck'] = 'true'; |
|---|
| 673 | $textfield = new html_inputfield($attrib); |
|---|
| 674 | |
|---|
| 675 | $subject = ''; |
|---|
| 676 | |
|---|
| 677 | // use subject from post |
|---|
| 678 | if (isset($_POST['_subject'])) { |
|---|
| 679 | $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE); |
|---|
| 680 | } |
|---|
| 681 | // create a reply-subject |
|---|
| 682 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) { |
|---|
| 683 | if (eregi('^re:', $MESSAGE->subject)) |
|---|
| 684 | $subject = $MESSAGE->subject; |
|---|
| 685 | else |
|---|
| 686 | $subject = 'Re: '.$MESSAGE->subject; |
|---|
| 687 | } |
|---|
| 688 | // create a forward-subject |
|---|
| 689 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) { |
|---|
| 690 | if (eregi('^fwd:', $MESSAGE->subject)) |
|---|
| 691 | $subject = $MESSAGE->subject; |
|---|
| 692 | else |
|---|
| 693 | $subject = 'Fwd: '.$MESSAGE->subject; |
|---|
| 694 | } |
|---|
| 695 | // creeate a draft-subject |
|---|
| 696 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) { |
|---|
| 697 | $subject = $MESSAGE->subject; |
|---|
| 698 | } |
|---|
| 699 | else if (!empty($_SESSION['compose']['param']['_subject'])) { |
|---|
| 700 | $subject = $_SESSION['compose']['param']['_subject']; |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 704 | $out .= $textfield->show($subject); |
|---|
| 705 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 706 | |
|---|
| 707 | return $out; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | function rcmail_compose_attachment_list($attrib) |
|---|
| 712 | { |
|---|
| 713 | global $OUTPUT, $CONFIG; |
|---|
| 714 | |
|---|
| 715 | // add ID if not given |
|---|
| 716 | if (!$attrib['id']) |
|---|
| 717 | $attrib['id'] = 'rcmAttachmentList'; |
|---|
| 718 | |
|---|
| 719 | $out = "\n"; |
|---|
| 720 | |
|---|
| 721 | if (is_array($_SESSION['compose']['attachments'])) |
|---|
| 722 | { |
|---|
| 723 | if ($attrib['deleteicon']) |
|---|
| 724 | $button = html::img(array( |
|---|
| 725 | 'src' => $CONFIG['skin_path'] . $attrib['deleteicon'], |
|---|
| 726 | 'alt' => rcube_label('delete'), |
|---|
| 727 | 'style' => "padding-right:2px;vertical-align:middle")); |
|---|
| 728 | else |
|---|
| 729 | $button = Q(rcube_label('delete')); |
|---|
| 730 | |
|---|
| 731 | foreach ($_SESSION['compose']['attachments'] as $id => $a_prop) |
|---|
| 732 | { |
|---|
| 733 | if (empty($a_prop)) |
|---|
| 734 | continue; |
|---|
| 735 | |
|---|
| 736 | $out .= html::tag('li', array('id' => "rcmfile".$id), |
|---|
| 737 | html::a(array( |
|---|
| 738 | 'href' => "#delete", |
|---|
| 739 | 'title' => rcube_label('delete'), |
|---|
| 740 | 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)), |
|---|
| 741 | $button) . Q($a_prop['name'])); |
|---|
| 742 | } |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); |
|---|
| 746 | |
|---|
| 747 | return html::tag('ul', $attrib, $out, html::$common_attrib); |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | function rcmail_compose_attachment_form($attrib) |
|---|
| 752 | { |
|---|
| 753 | global $OUTPUT; |
|---|
| 754 | |
|---|
| 755 | // add ID if not given |
|---|
| 756 | if (!$attrib['id']) |
|---|
| 757 | $attrib['id'] = 'rcmUploadbox'; |
|---|
| 758 | |
|---|
| 759 | $button = new html_inputfield(array('type' => 'button', 'class' => 'button')); |
|---|
| 760 | |
|---|
| 761 | $out = html::div($attrib, |
|---|
| 762 | $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data'), |
|---|
| 763 | html::div(null, rcmail_compose_attachment_field(array())) . |
|---|
| 764 | html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))))) . |
|---|
| 765 | html::div('buttons', |
|---|
| 766 | $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . ' ' . |
|---|
| 767 | $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)")) |
|---|
| 768 | ) |
|---|
| 769 | ) |
|---|
| 770 | ); |
|---|
| 771 | |
|---|
| 772 | $OUTPUT->add_gui_object('uploadbox', $attrib['id']); |
|---|
| 773 | return $out; |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | function rcmail_compose_attachment_field($attrib) |
|---|
| 778 | { |
|---|
| 779 | $attrib['type'] = 'file'; |
|---|
| 780 | $attrib['name'] = '_attachments[]'; |
|---|
| 781 | $field = new html_inputfield($attrib); |
|---|
| 782 | return $field->show(); |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | function rcmail_priority_selector($attrib) |
|---|
| 787 | { |
|---|
| 788 | global $MESSAGE; |
|---|
| 789 | |
|---|
| 790 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 791 | unset($attrib['form']); |
|---|
| 792 | |
|---|
| 793 | $attrib['name'] = '_priority'; |
|---|
| 794 | $selector = new html_select($attrib); |
|---|
| 795 | |
|---|
| 796 | $selector->add(array(rcube_label('lowest'), |
|---|
| 797 | rcube_label('low'), |
|---|
| 798 | rcube_label('normal'), |
|---|
| 799 | rcube_label('high'), |
|---|
| 800 | rcube_label('highest')), |
|---|
| 801 | array(5, 4, 0, 2, 1)); |
|---|
| 802 | |
|---|
| 803 | $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority); |
|---|
| 804 | |
|---|
| 805 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 806 | $out .= $selector->show($sel); |
|---|
| 807 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 808 | |
|---|
| 809 | return $out; |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | function rcmail_receipt_checkbox($attrib) |
|---|
| 814 | { |
|---|
| 815 | global $MESSAGE, $compose_mode; |
|---|
| 816 | |
|---|
| 817 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 818 | unset($attrib['form']); |
|---|
| 819 | |
|---|
| 820 | if (!isset($attrib['id'])) |
|---|
| 821 | $attrib['id'] = 'receipt'; |
|---|
| 822 | |
|---|
| 823 | $attrib['name'] = '_receipt'; |
|---|
| 824 | $attrib['value'] = '1'; |
|---|
| 825 | $checkbox = new html_checkbox($attrib); |
|---|
| 826 | |
|---|
| 827 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 828 | $out .= $checkbox->show( |
|---|
| 829 | $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0); |
|---|
| 830 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 831 | |
|---|
| 832 | return $out; |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | function rcmail_editor_selector($attrib) |
|---|
| 837 | { |
|---|
| 838 | global $CONFIG, $MESSAGE, $compose_mode; |
|---|
| 839 | |
|---|
| 840 | $choices = array( |
|---|
| 841 | 'html' => 'htmltoggle', |
|---|
| 842 | 'plain' => 'plaintoggle' |
|---|
| 843 | ); |
|---|
| 844 | |
|---|
| 845 | // determine whether HTML or plain text should be checked |
|---|
| 846 | $useHtml = $CONFIG['htmleditor'] ? true : false; |
|---|
| 847 | |
|---|
| 848 | if ($compose_mode) |
|---|
| 849 | $useHtml = ($useHtml && $MESSAGE->has_html_part()); |
|---|
| 850 | |
|---|
| 851 | $editorid = empty($attrib['editorid']) ? 'rcmComposeMessage' : $attrib['editorid']; |
|---|
| 852 | |
|---|
| 853 | $selector = ''; |
|---|
| 854 | $chosenvalue = $useHtml ? 'html' : 'plain'; |
|---|
| 855 | $radio = new html_radiobutton(array('name' => '_editorSelect', |
|---|
| 856 | 'onclick' => "return rcmail_toggle_editor(this.value=='html', '$editorid', '_is_html')")); |
|---|
| 857 | |
|---|
| 858 | foreach ($choices as $value => $text) |
|---|
| 859 | { |
|---|
| 860 | $attrib['id'] = '_' . $value; |
|---|
| 861 | $attrib['value'] = $value; |
|---|
| 862 | $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text))); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | return $selector; |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | function rcmail_store_target_selection($attrib) |
|---|
| 870 | { |
|---|
| 871 | $attrib['name'] = '_store_target'; |
|---|
| 872 | $select = rcmail_mailbox_select(array_merge($attrib, array('noselection' => '- '.rcube_label('dontsave').' -'))); |
|---|
| 873 | return $select->show(rcmail::get_instance()->config->get('sent_mbox'), $attrib); |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | function get_form_tags($attrib) |
|---|
| 878 | { |
|---|
| 879 | global $RCMAIL, $MESSAGE_FORM; |
|---|
| 880 | |
|---|
| 881 | $form_start = ''; |
|---|
| 882 | if (!strlen($MESSAGE_FORM)) |
|---|
| 883 | { |
|---|
| 884 | $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); |
|---|
| 885 | $hiddenfields->add(array('name' => '_action', 'value' => 'send')); |
|---|
| 886 | |
|---|
| 887 | $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; |
|---|
| 888 | $form_start .= $hiddenfields->show(); |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : ''; |
|---|
| 892 | $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
|---|
| 893 | |
|---|
| 894 | if (!strlen($MESSAGE_FORM)) |
|---|
| 895 | $RCMAIL->output->add_gui_object('messageform', $form_name); |
|---|
| 896 | |
|---|
| 897 | $MESSAGE_FORM = $form_name; |
|---|
| 898 | |
|---|
| 899 | return array($form_start, $form_end); |
|---|
| 900 | } |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | // register UI objects |
|---|
| 904 | $OUTPUT->add_handlers(array( |
|---|
| 905 | 'composeheaders' => 'rcmail_compose_headers', |
|---|
| 906 | 'composesubject' => 'rcmail_compose_subject', |
|---|
| 907 | 'composebody' => 'rcmail_compose_body', |
|---|
| 908 | 'composeattachmentlist' => 'rcmail_compose_attachment_list', |
|---|
| 909 | 'composeattachmentform' => 'rcmail_compose_attachment_form', |
|---|
| 910 | 'composeattachment' => 'rcmail_compose_attachment_field', |
|---|
| 911 | 'priorityselector' => 'rcmail_priority_selector', |
|---|
| 912 | 'editorselector' => 'rcmail_editor_selector', |
|---|
| 913 | 'receiptcheckbox' => 'rcmail_receipt_checkbox', |
|---|
| 914 | 'storetarget' => 'rcmail_store_target_selection', |
|---|
| 915 | )); |
|---|
| 916 | |
|---|
| 917 | /****** get contacts for this user and add them to client scripts ********/ |
|---|
| 918 | |
|---|
| 919 | $CONTACTS = new rcube_contacts($DB, $USER->ID); |
|---|
| 920 | $CONTACTS->set_pagesize(1000); |
|---|
| 921 | |
|---|
| 922 | $a_contacts = array(); |
|---|
| 923 | |
|---|
| 924 | if ($result = $CONTACTS->list_records()) |
|---|
| 925 | { |
|---|
| 926 | while ($sql_arr = $result->iterate()) |
|---|
| 927 | if ($sql_arr['email']) |
|---|
| 928 | $a_contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); |
|---|
| 929 | } |
|---|
| 930 | if (!empty($CONFIG['ldap_public']) && is_array($CONFIG['ldap_public'])) |
|---|
| 931 | { |
|---|
| 932 | /* LDAP autocompletion */ |
|---|
| 933 | foreach ($CONFIG['ldap_public'] as $ldapserv_config) |
|---|
| 934 | { |
|---|
| 935 | if ($ldapserv_config['fuzzy_search'] != 1 || |
|---|
| 936 | $ldapserv_config['global_search'] != 1) |
|---|
| 937 | { |
|---|
| 938 | continue; |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | $LDAP = new rcube_ldap($ldapserv_config); |
|---|
| 942 | $LDAP->connect(); |
|---|
| 943 | $LDAP->set_pagesize(1000); |
|---|
| 944 | |
|---|
| 945 | $results = $LDAP->search($ldapserv_config['mail_field'], ""); |
|---|
| 946 | |
|---|
| 947 | for ($i = 0; $i < $results->count; $i++) |
|---|
| 948 | { |
|---|
| 949 | if ($results->records[$i]['email'] != '') |
|---|
| 950 | { |
|---|
| 951 | $email = $results->records[$i]['email']; |
|---|
| 952 | $name = $results->records[$i]['name']; |
|---|
| 953 | |
|---|
| 954 | $a_contacts[] = format_email_recipient($email, $name); |
|---|
| 955 | } |
|---|
| 956 | } |
|---|
| 957 | $LDAP->close(); |
|---|
| 958 | } |
|---|
| 959 | } |
|---|
| 960 | if ($a_contacts) |
|---|
| 961 | { |
|---|
| 962 | $OUTPUT->set_env('contacts', $a_contacts); |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | $OUTPUT->send('compose'); |
|---|
| 966 | |
|---|
| 967 | ?> |
|---|