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