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