| 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-2011, The Roundcube Dev Team | |
|---|
| 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 | $COMPOSE_ID = get_input_value('_id', RCUBE_INPUT_GET); |
|---|
| 31 | $COMPOSE = null; |
|---|
| 32 | |
|---|
| 33 | if ($COMPOSE_ID && $_SESSION['compose_data_'.$COMPOSE_ID]) |
|---|
| 34 | $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID]; |
|---|
| 35 | |
|---|
| 36 | // give replicated session storage some time to synchronize |
|---|
| 37 | $retries = 0; |
|---|
| 38 | while ($COMPOSE_ID && !is_array($COMPOSE) && $RCMAIL->db->is_replicated() && $retries++ < 5) { |
|---|
| 39 | usleep(500000); |
|---|
| 40 | $RCMAIL->session->reload(); |
|---|
| 41 | if ($_SESSION['compose_data_'.$COMPOSE_ID]) |
|---|
| 42 | $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID]; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or |
|---|
| 46 | // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab). |
|---|
| 47 | if (!is_array($COMPOSE)) |
|---|
| 48 | { |
|---|
| 49 | // Infinite redirect prevention in case of broken session (#1487028) |
|---|
| 50 | if ($COMPOSE_ID) |
|---|
| 51 | raise_error(array('code' => 500, 'type' => 'php', |
|---|
| 52 | 'file' => __FILE__, 'line' => __LINE__, |
|---|
| 53 | 'message' => "Invalid compose ID"), true, true); |
|---|
| 54 | |
|---|
| 55 | $COMPOSE_ID = uniqid(mt_rand()); |
|---|
| 56 | $_SESSION['compose_data_'.$COMPOSE_ID] = array( |
|---|
| 57 | 'id' => $COMPOSE_ID, |
|---|
| 58 | 'param' => request2param(RCUBE_INPUT_GET), |
|---|
| 59 | 'mailbox' => $IMAP->get_mailbox_name(), |
|---|
| 60 | ); |
|---|
| 61 | $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID]; |
|---|
| 62 | |
|---|
| 63 | // process values like "mailto:foo@bar.com?subject=new+message&cc=another" |
|---|
| 64 | if ($COMPOSE['param']['to']) { |
|---|
| 65 | // #1486037: remove "mailto:" prefix |
|---|
| 66 | $COMPOSE['param']['to'] = preg_replace('/^mailto:/i', '', $COMPOSE['param']['to']); |
|---|
| 67 | $mailto = explode('?', $COMPOSE['param']['to']); |
|---|
| 68 | if (count($mailto) > 1) { |
|---|
| 69 | $COMPOSE['param']['to'] = $mailto[0]; |
|---|
| 70 | parse_str($mailto[1], $query); |
|---|
| 71 | foreach ($query as $f => $val) |
|---|
| 72 | $COMPOSE['param'][$f] = $val; |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | // select folder where to save the sent message |
|---|
| 77 | $COMPOSE['param']['sent_mbox'] = $RCMAIL->config->get('sent_mbox'); |
|---|
| 78 | |
|---|
| 79 | // pipe compose parameters thru plugins |
|---|
| 80 | $plugin = $RCMAIL->plugins->exec_hook('message_compose', $COMPOSE); |
|---|
| 81 | $COMPOSE['param'] = array_merge($COMPOSE['param'], $plugin['param']); |
|---|
| 82 | |
|---|
| 83 | // add attachments listed by message_compose hook |
|---|
| 84 | if (is_array($plugin['attachments'])) { |
|---|
| 85 | foreach ($plugin['attachments'] as $attach) { |
|---|
| 86 | // we have structured data |
|---|
| 87 | if (is_array($attach)) { |
|---|
| 88 | $attachment = $attach; |
|---|
| 89 | } |
|---|
| 90 | // only a file path is given |
|---|
| 91 | else { |
|---|
| 92 | $filename = basename($attach); |
|---|
| 93 | $attachment = array( |
|---|
| 94 | 'group' => $COMPOSE_ID, |
|---|
| 95 | 'name' => $filename, |
|---|
| 96 | 'mimetype' => rc_mime_content_type($attach, $filename), |
|---|
| 97 | 'path' => $attach, |
|---|
| 98 | ); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | // save attachment if valid |
|---|
| 102 | if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) { |
|---|
| 103 | $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | if ($attachment['status'] && !$attachment['abort']) { |
|---|
| 107 | unset($attachment['data'], $attachment['status'], $attachment['abort']); |
|---|
| 108 | $COMPOSE['attachments'][$attachment['id']] = $attachment; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | // check if folder for saving sent messages exists and is subscribed (#1486802) |
|---|
| 114 | if ($sent_folder = $COMPOSE['param']['sent_mbox']) { |
|---|
| 115 | rcmail_check_sent_folder($sent_folder, true); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | // redirect to a unique URL with all parameters stored in session |
|---|
| 119 | $OUTPUT->redirect(array('_action' => 'compose', '_id' => $COMPOSE['id'])); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | // add some labels to client |
|---|
| 124 | $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', 'cancel', |
|---|
| 125 | 'nobodywarning', 'notsentwarning', 'notuploadedwarning', 'savingmessage', 'sendingmessage', |
|---|
| 126 | 'messagesaved', 'converting', 'editorwarning', 'searching', 'uploading', 'uploadingmany', |
|---|
| 127 | 'fileuploaderror'); |
|---|
| 128 | |
|---|
| 129 | $OUTPUT->set_env('compose_id', $COMPOSE['id']); |
|---|
| 130 | |
|---|
| 131 | // add config parameters to client script |
|---|
| 132 | if (!empty($CONFIG['drafts_mbox'])) { |
|---|
| 133 | $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); |
|---|
| 134 | $OUTPUT->set_env('draft_autosave', $CONFIG['draft_autosave']); |
|---|
| 135 | } |
|---|
| 136 | // set current mailbox in client environment |
|---|
| 137 | $OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name()); |
|---|
| 138 | $OUTPUT->set_env('sig_above', $RCMAIL->config->get('sig_above', false)); |
|---|
| 139 | $OUTPUT->set_env('top_posting', $RCMAIL->config->get('top_posting', false)); |
|---|
| 140 | $OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ','))); |
|---|
| 141 | |
|---|
| 142 | // get reference message and set compose mode |
|---|
| 143 | if ($msg_uid = $COMPOSE['param']['draft_uid']) { |
|---|
| 144 | $RCMAIL->imap->set_mailbox($CONFIG['drafts_mbox']); |
|---|
| 145 | $compose_mode = RCUBE_COMPOSE_DRAFT; |
|---|
| 146 | } |
|---|
| 147 | else if ($msg_uid = $COMPOSE['param']['reply_uid']) |
|---|
| 148 | $compose_mode = RCUBE_COMPOSE_REPLY; |
|---|
| 149 | else if ($msg_uid = $COMPOSE['param']['forward_uid']) |
|---|
| 150 | $compose_mode = RCUBE_COMPOSE_FORWARD; |
|---|
| 151 | else if ($msg_uid = $COMPOSE['param']['uid']) |
|---|
| 152 | $compose_mode = RCUBE_COMPOSE_EDIT; |
|---|
| 153 | |
|---|
| 154 | $config_show_sig = $RCMAIL->config->get('show_sig', 1); |
|---|
| 155 | if ($config_show_sig == 1) |
|---|
| 156 | $OUTPUT->set_env('show_sig', true); |
|---|
| 157 | else if ($config_show_sig == 2 && (empty($compose_mode) || $compose_mode == RCUBE_COMPOSE_EDIT || $compose_mode == RCUBE_COMPOSE_DRAFT)) |
|---|
| 158 | $OUTPUT->set_env('show_sig', true); |
|---|
| 159 | else if ($config_show_sig == 3 && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD)) |
|---|
| 160 | $OUTPUT->set_env('show_sig', true); |
|---|
| 161 | else |
|---|
| 162 | $OUTPUT->set_env('show_sig', false); |
|---|
| 163 | |
|---|
| 164 | // set line length for body wrapping |
|---|
| 165 | $LINE_LENGTH = $RCMAIL->config->get('line_length', 72); |
|---|
| 166 | |
|---|
| 167 | if (!empty($msg_uid)) |
|---|
| 168 | { |
|---|
| 169 | // similar as in program/steps/mail/show.inc |
|---|
| 170 | // re-set 'prefer_html' to have possibility to use html part for compose |
|---|
| 171 | $CONFIG['prefer_html'] = $CONFIG['prefer_html'] || $CONFIG['htmleditor'] || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT; |
|---|
| 172 | $MESSAGE = new rcube_message($msg_uid); |
|---|
| 173 | |
|---|
| 174 | // make sure message is marked as read |
|---|
| 175 | if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN'])) |
|---|
| 176 | $IMAP->set_flag($msg_uid, 'SEEN'); |
|---|
| 177 | |
|---|
| 178 | if (!empty($MESSAGE->headers->charset)) |
|---|
| 179 | $IMAP->set_charset($MESSAGE->headers->charset); |
|---|
| 180 | |
|---|
| 181 | if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 182 | { |
|---|
| 183 | $COMPOSE['reply_uid'] = $msg_uid; |
|---|
| 184 | $COMPOSE['reply_msgid'] = $MESSAGE->headers->messageID; |
|---|
| 185 | $COMPOSE['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID); |
|---|
| 186 | |
|---|
| 187 | if (!empty($COMPOSE['param']['all'])) |
|---|
| 188 | $MESSAGE->reply_all = $COMPOSE['param']['all']; |
|---|
| 189 | |
|---|
| 190 | $OUTPUT->set_env('compose_mode', 'reply'); |
|---|
| 191 | |
|---|
| 192 | // Save the sent message in the same folder of the message being replied to |
|---|
| 193 | if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $COMPOSE['mailbox']) |
|---|
| 194 | && rcmail_check_sent_folder($sent_folder, false) |
|---|
| 195 | ) { |
|---|
| 196 | $COMPOSE['param']['sent_mbox'] = $sent_folder; |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
|---|
| 200 | { |
|---|
| 201 | if ($MESSAGE->headers->others['x-draft-info']) |
|---|
| 202 | { |
|---|
| 203 | // get reply_uid/forward_uid to flag the original message when sending |
|---|
| 204 | $info = rcmail_draftinfo_decode($MESSAGE->headers->others['x-draft-info']); |
|---|
| 205 | |
|---|
| 206 | if ($info['type'] == 'reply') |
|---|
| 207 | $COMPOSE['reply_uid'] = $info['uid']; |
|---|
| 208 | else if ($info['type'] == 'forward') |
|---|
| 209 | $COMPOSE['forward_uid'] = $info['uid']; |
|---|
| 210 | |
|---|
| 211 | $COMPOSE['mailbox'] = $info['folder']; |
|---|
| 212 | |
|---|
| 213 | // Save the sent message in the same folder of the message being replied to |
|---|
| 214 | if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $info['folder']) |
|---|
| 215 | && rcmail_check_sent_folder($sent_folder, false) |
|---|
| 216 | ) { |
|---|
| 217 | $COMPOSE['param']['sent_mbox'] = $sent_folder; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | if ($MESSAGE->headers->in_reply_to) |
|---|
| 222 | $COMPOSE['reply_msgid'] = '<'.$MESSAGE->headers->in_reply_to.'>'; |
|---|
| 223 | |
|---|
| 224 | $COMPOSE['references'] = $MESSAGE->headers->references; |
|---|
| 225 | } |
|---|
| 226 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 227 | { |
|---|
| 228 | $COMPOSE['forward_uid'] = $msg_uid; |
|---|
| 229 | $OUTPUT->set_env('compose_mode', 'forward'); |
|---|
| 230 | |
|---|
| 231 | if (!empty($COMPOSE['param']['attachment'])) |
|---|
| 232 | $MESSAGE->forward_attachment = true; |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | $MESSAGE->compose = array(); |
|---|
| 237 | |
|---|
| 238 | // get user's identities |
|---|
| 239 | $MESSAGE->identities = $USER->list_identities(); |
|---|
| 240 | if (count($MESSAGE->identities)) |
|---|
| 241 | { |
|---|
| 242 | foreach ($MESSAGE->identities as $idx => $ident) { |
|---|
| 243 | $email = mb_strtolower(rcube_idn_to_utf8($ident['email'])); |
|---|
| 244 | |
|---|
| 245 | $MESSAGE->identities[$idx]['email_ascii'] = $ident['email']; |
|---|
| 246 | $MESSAGE->identities[$idx]['ident'] = format_email_recipient($ident['email'], $ident['name']); |
|---|
| 247 | $MESSAGE->identities[$idx]['email'] = $email; |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | // Set From field value |
|---|
| 252 | if (!empty($_POST['_from'])) { |
|---|
| 253 | $MESSAGE->compose['from'] = get_input_value('_from', RCUBE_INPUT_POST); |
|---|
| 254 | } |
|---|
| 255 | else if (!empty($COMPOSE['param']['from'])) { |
|---|
| 256 | $MESSAGE->compose['from'] = $COMPOSE['param']['from']; |
|---|
| 257 | } |
|---|
| 258 | else if (count($MESSAGE->identities)) { |
|---|
| 259 | $a_recipients = array(); |
|---|
| 260 | $a_names = array(); |
|---|
| 261 | |
|---|
| 262 | // extract all recipients of the reply-message |
|---|
| 263 | if (is_object($MESSAGE->headers) && in_array($compose_mode, array(RCUBE_COMPOSE_REPLY, RCUBE_COMPOSE_FORWARD))) |
|---|
| 264 | { |
|---|
| 265 | $a_to = $IMAP->decode_address_list($MESSAGE->headers->to); |
|---|
| 266 | foreach ($a_to as $addr) { |
|---|
| 267 | if (!empty($addr['mailto'])) { |
|---|
| 268 | $a_recipients[] = strtolower($addr['mailto']); |
|---|
| 269 | $a_names[] = $addr['name']; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if (!empty($MESSAGE->headers->cc)) { |
|---|
| 274 | $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc); |
|---|
| 275 | foreach ($a_cc as $addr) { |
|---|
| 276 | if (!empty($addr['mailto'])) { |
|---|
| 277 | $a_recipients[] = strtolower($addr['mailto']); |
|---|
| 278 | $a_names[] = $addr['name']; |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | $from_idx = null; |
|---|
| 285 | $default_identity = null; |
|---|
| 286 | $return_path = $MESSAGE->headers->others['return-path']; |
|---|
| 287 | |
|---|
| 288 | // Select identity |
|---|
| 289 | foreach ($MESSAGE->identities as $idx => $ident) { |
|---|
| 290 | // save default identity ID |
|---|
| 291 | if ($ident['standard']) { |
|---|
| 292 | $default_identity = $idx; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | // use From header |
|---|
| 296 | if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) { |
|---|
| 297 | if ($MESSAGE->headers->from == $ident['ident']) { |
|---|
| 298 | $from_idx = $idx; |
|---|
| 299 | break; |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | // reply to yourself |
|---|
| 303 | else if ($compose_mode == RCUBE_COMPOSE_REPLY && $MESSAGE->headers->from == $ident['ident']) { |
|---|
| 304 | $from_idx = $idx; |
|---|
| 305 | break; |
|---|
| 306 | } |
|---|
| 307 | // use replied message recipients |
|---|
| 308 | else if (($found = array_search($ident['email_ascii'], $a_recipients)) !== false) { |
|---|
| 309 | // match identity name, prefer default identity |
|---|
| 310 | if ($from_idx === null || ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name'])) { |
|---|
| 311 | $from_idx = $idx; |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | // Fallback using Return-Path |
|---|
| 317 | if ($from_idx === null && $return_path) { |
|---|
| 318 | foreach ($MESSAGE->identities as $idx => $ident) { |
|---|
| 319 | if (strpos($return_path, str_replace('@', '=', $ident['email_ascii']).'@') !== false) { |
|---|
| 320 | $from_idx = $idx; |
|---|
| 321 | break; |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | // Still no ID, use default/first identity |
|---|
| 327 | if ($from_idx === null) { |
|---|
| 328 | $from_idx = $default_identity !== null ? $default_identity : key(reset($MESSAGE->identities)); |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | $ident = $MESSAGE->identities[$from_idx]; |
|---|
| 332 | $from_id = $ident['identity_id']; |
|---|
| 333 | |
|---|
| 334 | $MESSAGE->compose['from_email'] = $ident['email']; |
|---|
| 335 | $MESSAGE->compose['from'] = $from_id; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | // Set other headers |
|---|
| 339 | $a_recipients = array(); |
|---|
| 340 | $parts = array('to', 'cc', 'bcc', 'replyto', 'followupto'); |
|---|
| 341 | $separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' '; |
|---|
| 342 | |
|---|
| 343 | foreach ($parts as $header) { |
|---|
| 344 | $fvalue = ''; |
|---|
| 345 | $decode_header = true; |
|---|
| 346 | |
|---|
| 347 | // we have a set of recipients stored is session |
|---|
| 348 | if ($header == 'to' && ($mailto_id = $COMPOSE['param']['mailto']) |
|---|
| 349 | && $COMPOSE[$mailto_id] |
|---|
| 350 | ) { |
|---|
| 351 | $fvalue = urldecode($COMPOSE[$mailto_id]); |
|---|
| 352 | $decode_header = false; |
|---|
| 353 | } |
|---|
| 354 | else if (!empty($_POST['_'.$header])) { |
|---|
| 355 | $fvalue = get_input_value('_'.$header, RCUBE_INPUT_POST, TRUE); |
|---|
| 356 | } |
|---|
| 357 | else if (!empty($COMPOSE['param'][$header])) { |
|---|
| 358 | $fvalue = $COMPOSE['param'][$header]; |
|---|
| 359 | } |
|---|
| 360 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) { |
|---|
| 361 | // get recipent address(es) out of the message headers |
|---|
| 362 | if ($header == 'to') { |
|---|
| 363 | $mailfollowup = $MESSAGE->headers->others['mail-followup-to']; |
|---|
| 364 | $mailreplyto = $MESSAGE->headers->others['mail-reply-to']; |
|---|
| 365 | |
|---|
| 366 | // Reply to mailing list... |
|---|
| 367 | if ($MESSAGE->reply_all == 'list' && $mailfollowup) |
|---|
| 368 | $fvalue = $mailfollowup; |
|---|
| 369 | else if ($MESSAGE->reply_all == 'list' |
|---|
| 370 | && preg_match('/<mailto:([^>]+)>/i', $MESSAGE->headers->others['list-post'], $m)) |
|---|
| 371 | $fvalue = $m[1]; |
|---|
| 372 | // Reply to... |
|---|
| 373 | else if ($MESSAGE->reply_all && $mailfollowup) |
|---|
| 374 | $fvalue = $mailfollowup; |
|---|
| 375 | else if ($mailreplyto) |
|---|
| 376 | $fvalue = $mailreplyto; |
|---|
| 377 | else if (!empty($MESSAGE->headers->replyto)) |
|---|
| 378 | $fvalue = $MESSAGE->headers->replyto; |
|---|
| 379 | else if (!empty($MESSAGE->headers->from)) |
|---|
| 380 | $fvalue = $MESSAGE->headers->from; |
|---|
| 381 | |
|---|
| 382 | // Reply to message sent by yourself (#1487074) |
|---|
| 383 | if (!empty($ident) && $fvalue == $ident['ident']) { |
|---|
| 384 | $fvalue = $MESSAGE->headers->to; |
|---|
| 385 | } |
|---|
| 386 | } |
|---|
| 387 | // add recipient of original message if reply to all |
|---|
| 388 | else if ($header == 'cc' && !empty($MESSAGE->reply_all) && $MESSAGE->reply_all != 'list') { |
|---|
| 389 | if ($v = $MESSAGE->headers->to) |
|---|
| 390 | $fvalue .= $v; |
|---|
| 391 | if ($v = $MESSAGE->headers->cc) |
|---|
| 392 | $fvalue .= (!empty($fvalue) ? $separator : '') . $v; |
|---|
| 393 | } |
|---|
| 394 | } |
|---|
| 395 | else if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) { |
|---|
| 396 | // get drafted headers |
|---|
| 397 | if ($header=='to' && !empty($MESSAGE->headers->to)) |
|---|
| 398 | $fvalue = $MESSAGE->get_header('to'); |
|---|
| 399 | else if ($header=='cc' && !empty($MESSAGE->headers->cc)) |
|---|
| 400 | $fvalue = $MESSAGE->get_header('cc'); |
|---|
| 401 | else if ($header=='bcc' && !empty($MESSAGE->headers->bcc)) |
|---|
| 402 | $fvalue = $MESSAGE->get_header('bcc'); |
|---|
| 403 | else if ($header=='replyto' && !empty($MESSAGE->headers->others['mail-reply-to'])) |
|---|
| 404 | $fvalue = $MESSAGE->get_header('mail-reply-to'); |
|---|
| 405 | else if ($header=='replyto' && !empty($MESSAGE->headers->replyto)) |
|---|
| 406 | $fvalue = $MESSAGE->get_header('reply-to'); |
|---|
| 407 | else if ($header=='followupto' && !empty($MESSAGE->headers->others['mail-followup-to'])) |
|---|
| 408 | $fvalue = $MESSAGE->get_header('mail-followup-to'); |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | // split recipients and put them back together in a unique way |
|---|
| 412 | if (!empty($fvalue) && in_array($header, array('to', 'cc', 'bcc'))) { |
|---|
| 413 | $to_addresses = $IMAP->decode_address_list($fvalue, null, $decode_header); |
|---|
| 414 | $fvalue = array(); |
|---|
| 415 | |
|---|
| 416 | foreach ($to_addresses as $addr_part) { |
|---|
| 417 | if (empty($addr_part['mailto'])) |
|---|
| 418 | continue; |
|---|
| 419 | |
|---|
| 420 | $mailto = mb_strtolower(rcube_idn_to_utf8($addr_part['mailto'])); |
|---|
| 421 | |
|---|
| 422 | if (!in_array($mailto, $a_recipients) |
|---|
| 423 | && ($header == 'to' || empty($MESSAGE->compose['from_email']) || $mailto != $MESSAGE->compose['from_email']) |
|---|
| 424 | ) { |
|---|
| 425 | if ($addr_part['name'] && $addr_part['mailto'] != $addr_part['name']) |
|---|
| 426 | $string = format_email_recipient($mailto, $addr_part['name']); |
|---|
| 427 | else |
|---|
| 428 | $string = $mailto; |
|---|
| 429 | |
|---|
| 430 | $fvalue[] = $string; |
|---|
| 431 | $a_recipients[] = $addr_part['mailto']; |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | $fvalue = implode($separator, $fvalue); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | $MESSAGE->compose[$header] = $fvalue; |
|---|
| 439 | } |
|---|
| 440 | unset($a_recipients); |
|---|
| 441 | |
|---|
| 442 | // process $MESSAGE body/attachments, set $MESSAGE_BODY/$HTML_MODE vars and some session data |
|---|
| 443 | $MESSAGE_BODY = rcmail_prepare_message_body(); |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | /****** compose mode functions ********/ |
|---|
| 447 | |
|---|
| 448 | function rcmail_compose_headers($attrib) |
|---|
| 449 | { |
|---|
| 450 | global $MESSAGE; |
|---|
| 451 | |
|---|
| 452 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 453 | |
|---|
| 454 | $out = ''; |
|---|
| 455 | $part = strtolower($attrib['part']); |
|---|
| 456 | |
|---|
| 457 | switch ($part) |
|---|
| 458 | { |
|---|
| 459 | case 'from': |
|---|
| 460 | return $form_start . rcmail_compose_header_from($attrib); |
|---|
| 461 | |
|---|
| 462 | case 'to': |
|---|
| 463 | case 'cc': |
|---|
| 464 | case 'bcc': |
|---|
| 465 | $fname = '_' . $part; |
|---|
| 466 | $header = $param = $part; |
|---|
| 467 | |
|---|
| 468 | $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex'); |
|---|
| 469 | $field_type = 'html_textarea'; |
|---|
| 470 | break; |
|---|
| 471 | |
|---|
| 472 | case 'replyto': |
|---|
| 473 | case 'reply-to': |
|---|
| 474 | $fname = '_replyto'; |
|---|
| 475 | $param = 'replyto'; |
|---|
| 476 | $header = 'reply-to'; |
|---|
| 477 | |
|---|
| 478 | case 'followupto': |
|---|
| 479 | case 'followup-to': |
|---|
| 480 | if (!$fname) { |
|---|
| 481 | $fname = '_followupto'; |
|---|
| 482 | $param = 'followupto'; |
|---|
| 483 | $header = 'mail-followup-to'; |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex'); |
|---|
| 487 | $field_type = 'html_inputfield'; |
|---|
| 488 | break; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | if ($fname && $field_type) |
|---|
| 492 | { |
|---|
| 493 | // pass the following attributes to the form class |
|---|
| 494 | $field_attrib = array('name' => $fname, 'spellcheck' => 'false'); |
|---|
| 495 | foreach ($attrib as $attr => $value) |
|---|
| 496 | if (in_array($attr, $allow_attrib)) |
|---|
| 497 | $field_attrib[$attr] = $value; |
|---|
| 498 | |
|---|
| 499 | // create teaxtarea object |
|---|
| 500 | $input = new $field_type($field_attrib); |
|---|
| 501 | $out = $input->show($MESSAGE->compose[$param]); |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | if ($form_start) |
|---|
| 505 | $out = $form_start.$out; |
|---|
| 506 | |
|---|
| 507 | // configure autocompletion |
|---|
| 508 | rcube_autocomplete_init(); |
|---|
| 509 | |
|---|
| 510 | return $out; |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | function rcmail_compose_header_from($attrib) |
|---|
| 515 | { |
|---|
| 516 | global $MESSAGE, $OUTPUT; |
|---|
| 517 | |
|---|
| 518 | // pass the following attributes to the form class |
|---|
| 519 | $field_attrib = array('name' => '_from'); |
|---|
| 520 | foreach ($attrib as $attr => $value) |
|---|
| 521 | if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) |
|---|
| 522 | $field_attrib[$attr] = $value; |
|---|
| 523 | |
|---|
| 524 | if (count($MESSAGE->identities)) |
|---|
| 525 | { |
|---|
| 526 | $a_signatures = array(); |
|---|
| 527 | |
|---|
| 528 | $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)"; |
|---|
| 529 | $select_from = new html_select($field_attrib); |
|---|
| 530 | |
|---|
| 531 | // create SELECT element |
|---|
| 532 | foreach ($MESSAGE->identities as $sql_arr) |
|---|
| 533 | { |
|---|
| 534 | $identity_id = $sql_arr['identity_id']; |
|---|
| 535 | $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id); |
|---|
| 536 | |
|---|
| 537 | // add signature to array |
|---|
| 538 | if (!empty($sql_arr['signature']) && empty($COMPOSE['param']['nosig'])) |
|---|
| 539 | { |
|---|
| 540 | $a_signatures[$identity_id]['text'] = $sql_arr['signature']; |
|---|
| 541 | $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false; |
|---|
| 542 | if ($a_signatures[$identity_id]['is_html']) |
|---|
| 543 | { |
|---|
| 544 | $h2t = new html2text($a_signatures[$identity_id]['text'], false, false); |
|---|
| 545 | $a_signatures[$identity_id]['plain_text'] = trim($h2t->get_text()); |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | $out = $select_from->show($MESSAGE->compose['from']); |
|---|
| 551 | |
|---|
| 552 | // add signatures to client |
|---|
| 553 | $OUTPUT->set_env('signatures', $a_signatures); |
|---|
| 554 | } |
|---|
| 555 | // no identities, display text input field |
|---|
| 556 | else { |
|---|
| 557 | $field_attrib['class'] = 'from_address'; |
|---|
| 558 | $input_from = new html_inputfield($field_attrib); |
|---|
| 559 | $out = $input_from->show($MESSAGE->compose['from']); |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | return $out; |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | function rcmail_compose_editor_mode() |
|---|
| 567 | { |
|---|
| 568 | global $RCMAIL, $MESSAGE, $compose_mode; |
|---|
| 569 | static $useHtml; |
|---|
| 570 | |
|---|
| 571 | if ($useHtml !== null) |
|---|
| 572 | return $useHtml; |
|---|
| 573 | |
|---|
| 574 | $html_editor = intval($RCMAIL->config->get('htmleditor')); |
|---|
| 575 | |
|---|
| 576 | if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) { |
|---|
| 577 | $useHtml = $MESSAGE->has_html_part(); |
|---|
| 578 | } |
|---|
| 579 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) { |
|---|
| 580 | $useHtml = ($html_editor == 1 || ($html_editor == 2 && $MESSAGE->has_html_part())); |
|---|
| 581 | } |
|---|
| 582 | else { // RCUBE_COMPOSE_FORWARD or NEW |
|---|
| 583 | $useHtml = ($html_editor == 1); |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | return $useHtml; |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | function rcmail_prepare_message_body() |
|---|
| 591 | { |
|---|
| 592 | global $RCMAIL, $MESSAGE, $COMPOSE, $compose_mode, $LINE_LENGTH, $HTML_MODE; |
|---|
| 593 | |
|---|
| 594 | // use posted message body |
|---|
| 595 | if (!empty($_POST['_message'])) { |
|---|
| 596 | $body = get_input_value('_message', RCUBE_INPUT_POST, true); |
|---|
| 597 | $isHtml = (bool) get_input_value('_is_html', RCUBE_INPUT_POST); |
|---|
| 598 | } |
|---|
| 599 | else if ($COMPOSE['param']['body']) { |
|---|
| 600 | $body = $COMPOSE['param']['body']; |
|---|
| 601 | $isHtml = false; |
|---|
| 602 | } |
|---|
| 603 | // forward as attachment |
|---|
| 604 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD && $MESSAGE->forward_attachment) { |
|---|
| 605 | $isHtml = rcmail_compose_editor_mode(); |
|---|
| 606 | $body = ''; |
|---|
| 607 | if (empty($COMPOSE['attachments'])) |
|---|
| 608 | rcmail_write_forward_attachment($MESSAGE); |
|---|
| 609 | } |
|---|
| 610 | // reply/edit/draft/forward |
|---|
| 611 | else if ($compose_mode) { |
|---|
| 612 | $has_html_part = $MESSAGE->has_html_part(); |
|---|
| 613 | $isHtml = rcmail_compose_editor_mode(); |
|---|
| 614 | |
|---|
| 615 | if ($isHtml) { |
|---|
| 616 | if ($has_html_part) { |
|---|
| 617 | $body = $MESSAGE->first_html_part(); |
|---|
| 618 | } |
|---|
| 619 | else { |
|---|
| 620 | $body = $MESSAGE->first_text_part(); |
|---|
| 621 | // try to remove the signature |
|---|
| 622 | if ($RCMAIL->config->get('strip_existing_sig', true)) |
|---|
| 623 | $body = rcmail_remove_signature($body); |
|---|
| 624 | // add HTML formatting |
|---|
| 625 | $body = rcmail_plain_body($body); |
|---|
| 626 | if ($body) |
|---|
| 627 | $body = '<pre>' . $body . '</pre>'; |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | else { |
|---|
| 631 | if ($has_html_part) { |
|---|
| 632 | // use html part if it has been used for message (pre)viewing |
|---|
| 633 | // decrease line length for quoting |
|---|
| 634 | $len = $compose_mode == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH; |
|---|
| 635 | $txt = new html2text($MESSAGE->first_html_part(), false, true, $len); |
|---|
| 636 | $body = $txt->get_text(); |
|---|
| 637 | } |
|---|
| 638 | else { |
|---|
| 639 | $body = $MESSAGE->first_text_part($part); |
|---|
| 640 | if ($body && $part && $part->ctype_secondary == 'plain' |
|---|
| 641 | && $part->ctype_parameters['format'] == 'flowed' |
|---|
| 642 | ) { |
|---|
| 643 | $body = rcube_message::unfold_flowed($body); |
|---|
| 644 | } |
|---|
| 645 | } |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | // compose reply-body |
|---|
| 649 | if ($compose_mode == RCUBE_COMPOSE_REPLY) |
|---|
| 650 | $body = rcmail_create_reply_body($body, $isHtml); |
|---|
| 651 | // forward message body inline |
|---|
| 652 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) |
|---|
| 653 | $body = rcmail_create_forward_body($body, $isHtml); |
|---|
| 654 | // load draft message body |
|---|
| 655 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) |
|---|
| 656 | $body = rcmail_create_draft_body($body, $isHtml); |
|---|
| 657 | } |
|---|
| 658 | else { // new message |
|---|
| 659 | $isHtml = rcmail_compose_editor_mode(); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | $plugin = $RCMAIL->plugins->exec_hook('message_compose_body', |
|---|
| 663 | array('body' => $body, 'html' => $isHtml, 'mode' => $compose_mode)); |
|---|
| 664 | $body = $plugin['body']; |
|---|
| 665 | unset($plugin); |
|---|
| 666 | |
|---|
| 667 | // add blocked.gif attachment (#1486516) |
|---|
| 668 | if ($isHtml && preg_match('#<img src="\./program/blocked\.gif"#', $body)) { |
|---|
| 669 | if ($attachment = rcmail_save_image('program/blocked.gif', 'image/gif')) { |
|---|
| 670 | $COMPOSE['attachments'][$attachment['id']] = $attachment; |
|---|
| 671 | $body = preg_replace('#\./program/blocked\.gif#', |
|---|
| 672 | $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id'], |
|---|
| 673 | $body); |
|---|
| 674 | } |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | $HTML_MODE = $isHtml; |
|---|
| 678 | |
|---|
| 679 | return $body; |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | function rcmail_compose_body($attrib) |
|---|
| 683 | { |
|---|
| 684 | global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode, $LINE_LENGTH, $HTML_MODE, $MESSAGE_BODY; |
|---|
| 685 | |
|---|
| 686 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 687 | unset($attrib['form']); |
|---|
| 688 | |
|---|
| 689 | if (empty($attrib['id'])) |
|---|
| 690 | $attrib['id'] = 'rcmComposeBody'; |
|---|
| 691 | |
|---|
| 692 | $attrib['name'] = '_message'; |
|---|
| 693 | |
|---|
| 694 | $isHtml = $HTML_MODE; |
|---|
| 695 | |
|---|
| 696 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 697 | |
|---|
| 698 | $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : '')); |
|---|
| 699 | $out .= $saveid->show(); |
|---|
| 700 | |
|---|
| 701 | $drafttoggle = new html_hiddenfield(array('name' => '_draft', 'value' => 'yes')); |
|---|
| 702 | $out .= $drafttoggle->show(); |
|---|
| 703 | |
|---|
| 704 | $msgtype = new html_hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0"))); |
|---|
| 705 | $out .= $msgtype->show(); |
|---|
| 706 | |
|---|
| 707 | // If desired, set this textarea to be editable by TinyMCE |
|---|
| 708 | if ($isHtml) { |
|---|
| 709 | $attrib['class'] = 'mce_editor'; |
|---|
| 710 | $textarea = new html_textarea($attrib); |
|---|
| 711 | $out .= $textarea->show($MESSAGE_BODY); |
|---|
| 712 | } |
|---|
| 713 | else { |
|---|
| 714 | $textarea = new html_textarea($attrib); |
|---|
| 715 | $out .= $textarea->show(''); |
|---|
| 716 | // quote plain text, inject into textarea |
|---|
| 717 | $table = get_html_translation_table(HTML_SPECIALCHARS); |
|---|
| 718 | $MESSAGE_BODY = strtr($MESSAGE_BODY, $table); |
|---|
| 719 | $out = substr($out, 0, -11) . $MESSAGE_BODY . '</textarea>'; |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 723 | |
|---|
| 724 | $OUTPUT->set_env('composebody', $attrib['id']); |
|---|
| 725 | |
|---|
| 726 | // include HTML editor |
|---|
| 727 | rcube_html_editor(); |
|---|
| 728 | |
|---|
| 729 | // include GoogieSpell |
|---|
| 730 | if (!empty($CONFIG['enable_spellcheck'])) { |
|---|
| 731 | $engine = $RCMAIL->config->get('spellcheck_engine','googie'); |
|---|
| 732 | $dictionary = (bool) $RCMAIL->config->get('spellcheck_dictionary'); |
|---|
| 733 | $spellcheck_langs = (array) $RCMAIL->config->get('spellcheck_languages', |
|---|
| 734 | array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', |
|---|
| 735 | 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', |
|---|
| 736 | 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska')); |
|---|
| 737 | |
|---|
| 738 | // googie works only with two-letter codes |
|---|
| 739 | if ($engine == 'googie') { |
|---|
| 740 | $lang = strtolower(substr($_SESSION['language'], 0, 2)); |
|---|
| 741 | |
|---|
| 742 | $spellcheck_langs_googie = array(); |
|---|
| 743 | foreach ($spellcheck_langs as $key => $name) |
|---|
| 744 | $spellcheck_langs_googie[strtolower(substr($key,0,2))] = $name; |
|---|
| 745 | $spellcheck_langs = $spellcheck_langs_googie; |
|---|
| 746 | } |
|---|
| 747 | else { |
|---|
| 748 | $lang = $_SESSION['language']; |
|---|
| 749 | |
|---|
| 750 | // if not found in the list, try with two-letter code |
|---|
| 751 | if (!$spellcheck_langs[$lang]) |
|---|
| 752 | $lang = strtolower(substr($lang, 0, 2)); |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | if (!$spellcheck_langs[$lang]) |
|---|
| 756 | $lang = 'en'; |
|---|
| 757 | |
|---|
| 758 | $editor_lang_set = array(); |
|---|
| 759 | foreach ($spellcheck_langs as $key => $name) { |
|---|
| 760 | $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key); |
|---|
| 761 | } |
|---|
| 762 | |
|---|
| 763 | $OUTPUT->include_script('googiespell.js'); |
|---|
| 764 | $OUTPUT->add_script(sprintf( |
|---|
| 765 | "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','?_task=utils&_action=spell&lang=', %s);\n". |
|---|
| 766 | "googie.lang_chck_spell = \"%s\";\n". |
|---|
| 767 | "googie.lang_rsm_edt = \"%s\";\n". |
|---|
| 768 | "googie.lang_close = \"%s\";\n". |
|---|
| 769 | "googie.lang_revert = \"%s\";\n". |
|---|
| 770 | "googie.lang_no_error_found = \"%s\";\n". |
|---|
| 771 | "googie.lang_learn_word = \"%s\";\n". |
|---|
| 772 | "googie.setLanguages(%s);\n". |
|---|
| 773 | "googie.setCurrentLanguage('%s');\n". |
|---|
| 774 | "googie.setSpellContainer('spellcheck-control');\n". |
|---|
| 775 | "googie.decorateTextarea('%s');\n". |
|---|
| 776 | "%s.set_env('spellcheck', googie);", |
|---|
| 777 | !empty($dictionary) ? 'true' : 'false', |
|---|
| 778 | JQ(Q(rcube_label('checkspelling'))), |
|---|
| 779 | JQ(Q(rcube_label('resumeediting'))), |
|---|
| 780 | JQ(Q(rcube_label('close'))), |
|---|
| 781 | JQ(Q(rcube_label('revertto'))), |
|---|
| 782 | JQ(Q(rcube_label('nospellerrors'))), |
|---|
| 783 | JQ(Q(rcube_label('addtodict'))), |
|---|
| 784 | json_serialize($spellcheck_langs), |
|---|
| 785 | $lang, |
|---|
| 786 | $attrib['id'], |
|---|
| 787 | JS_OBJECT_NAME), 'foot'); |
|---|
| 788 | |
|---|
| 789 | $OUTPUT->add_label('checking'); |
|---|
| 790 | $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set)); |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>'; |
|---|
| 794 | |
|---|
| 795 | return $out; |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | function rcmail_create_reply_body($body, $bodyIsHtml) |
|---|
| 800 | { |
|---|
| 801 | global $RCMAIL, $MESSAGE, $LINE_LENGTH; |
|---|
| 802 | |
|---|
| 803 | // build reply prefix |
|---|
| 804 | $from = array_pop($RCMAIL->imap->decode_address_list($MESSAGE->get_header('from'), 1, false)); |
|---|
| 805 | $prefix = rcube_label(array( |
|---|
| 806 | 'name' => 'mailreplyintro', |
|---|
| 807 | 'vars' => array( |
|---|
| 808 | 'date' => format_date($MESSAGE->headers->date, $RCMAIL->config->get('date_long')), |
|---|
| 809 | 'sender' => $from['name'] ? $from['name'] : rcube_idn_to_utf8($from['mailto']), |
|---|
| 810 | ) |
|---|
| 811 | )); |
|---|
| 812 | |
|---|
| 813 | if (!$bodyIsHtml) { |
|---|
| 814 | $body = preg_replace('/\r?\n/', "\n", $body); |
|---|
| 815 | |
|---|
| 816 | // try to remove the signature |
|---|
| 817 | if ($RCMAIL->config->get('strip_existing_sig', true)) |
|---|
| 818 | $body = rcmail_remove_signature($body); |
|---|
| 819 | |
|---|
| 820 | // soft-wrap and quote message text |
|---|
| 821 | $body = rcmail_wrap_and_quote(rtrim($body, "\n"), $LINE_LENGTH); |
|---|
| 822 | |
|---|
| 823 | $prefix .= "\n"; |
|---|
| 824 | $suffix = ''; |
|---|
| 825 | |
|---|
| 826 | if ($RCMAIL->config->get('top_posting')) |
|---|
| 827 | $prefix = "\n\n\n" . $prefix; |
|---|
| 828 | } |
|---|
| 829 | else { |
|---|
| 830 | // save inline images to files |
|---|
| 831 | $cid_map = rcmail_write_inline_attachments($MESSAGE); |
|---|
| 832 | // set is_safe flag (we need this for html body washing) |
|---|
| 833 | rcmail_check_safe($MESSAGE); |
|---|
| 834 | // clean up html tags |
|---|
| 835 | $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map); |
|---|
| 836 | |
|---|
| 837 | // build reply (quote content) |
|---|
| 838 | $prefix = '<p>' . Q($prefix) . "</p>\n"; |
|---|
| 839 | $prefix .= '<blockquote>'; |
|---|
| 840 | |
|---|
| 841 | if ($RCMAIL->config->get('top_posting')) { |
|---|
| 842 | $prefix = '<br>' . $prefix; |
|---|
| 843 | $suffix = '</blockquote>'; |
|---|
| 844 | } |
|---|
| 845 | else { |
|---|
| 846 | $suffix = '</blockquote><p></p>'; |
|---|
| 847 | } |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | return $prefix.$body.$suffix; |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | function rcmail_create_forward_body($body, $bodyIsHtml) |
|---|
| 855 | { |
|---|
| 856 | global $RCMAIL, $MESSAGE, $COMPOSE; |
|---|
| 857 | |
|---|
| 858 | // add attachments |
|---|
| 859 | if (!isset($COMPOSE['forward_attachments']) && is_array($MESSAGE->mime_parts)) |
|---|
| 860 | $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
|---|
| 861 | |
|---|
| 862 | $date = format_date($MESSAGE->headers->date, $RCMAIL->config->get('date_long')); |
|---|
| 863 | $charset = $RCMAIL->output->get_charset(); |
|---|
| 864 | |
|---|
| 865 | if (!$bodyIsHtml) |
|---|
| 866 | { |
|---|
| 867 | $prefix = "\n\n\n-------- " . rcube_label('originalmessage') . " --------\n"; |
|---|
| 868 | $prefix .= rcube_label('subject') . ': ' . $MESSAGE->subject . "\n"; |
|---|
| 869 | $prefix .= rcube_label('date') . ': ' . $date . "\n"; |
|---|
| 870 | $prefix .= rcube_label('from') . ': ' . $MESSAGE->get_header('from') . "\n"; |
|---|
| 871 | $prefix .= rcube_label('to') . ': ' . $MESSAGE->get_header('to') . "\n"; |
|---|
| 872 | |
|---|
| 873 | if ($MESSAGE->headers->cc) |
|---|
| 874 | $prefix .= rcube_label('cc') . ': ' . $MESSAGE->get_header('cc') . "\n"; |
|---|
| 875 | if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from) |
|---|
| 876 | $prefix .= rcube_label('replyto') . ': ' . $MESSAGE->get_header('replyto') . "\n"; |
|---|
| 877 | |
|---|
| 878 | $prefix .= "\n"; |
|---|
| 879 | } |
|---|
| 880 | else |
|---|
| 881 | { |
|---|
| 882 | // set is_safe flag (we need this for html body washing) |
|---|
| 883 | rcmail_check_safe($MESSAGE); |
|---|
| 884 | // clean up html tags |
|---|
| 885 | $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map); |
|---|
| 886 | |
|---|
| 887 | $prefix = sprintf( |
|---|
| 888 | "<br /><p>-------- " . rcube_label('originalmessage') . " --------</p>" . |
|---|
| 889 | "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . |
|---|
| 890 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . |
|---|
| 891 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . |
|---|
| 892 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . |
|---|
| 893 | "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", |
|---|
| 894 | rcube_label('subject'), Q($MESSAGE->subject), |
|---|
| 895 | rcube_label('date'), Q($date), |
|---|
| 896 | rcube_label('from'), htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $charset), |
|---|
| 897 | rcube_label('to'), htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $charset)); |
|---|
| 898 | |
|---|
| 899 | if ($MESSAGE->headers->cc) |
|---|
| 900 | $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", |
|---|
| 901 | rcube_label('cc'), |
|---|
| 902 | htmlspecialchars(Q($MESSAGE->get_header('cc'), 'replace'), ENT_COMPAT, $charset)); |
|---|
| 903 | |
|---|
| 904 | if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from) |
|---|
| 905 | $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", |
|---|
| 906 | rcube_label('replyto'), |
|---|
| 907 | htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $charset)); |
|---|
| 908 | |
|---|
| 909 | $prefix .= "</tbody></table><br>"; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | return $prefix.$body; |
|---|
| 913 | } |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | function rcmail_create_draft_body($body, $bodyIsHtml) |
|---|
| 917 | { |
|---|
| 918 | global $MESSAGE, $OUTPUT, $COMPOSE; |
|---|
| 919 | |
|---|
| 920 | /** |
|---|
| 921 | * add attachments |
|---|
| 922 | * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text! |
|---|
| 923 | */ |
|---|
| 924 | if (empty($COMPOSE['forward_attachments']) |
|---|
| 925 | && is_array($MESSAGE->mime_parts) |
|---|
| 926 | && count($MESSAGE->mime_parts) > 0) |
|---|
| 927 | { |
|---|
| 928 | $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
|---|
| 929 | |
|---|
| 930 | // replace cid with href in inline images links |
|---|
| 931 | if ($cid_map) |
|---|
| 932 | $body = str_replace(array_keys($cid_map), array_values($cid_map), $body); |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | return $body; |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | |
|---|
| 939 | function rcmail_remove_signature($body) |
|---|
| 940 | { |
|---|
| 941 | global $RCMAIL; |
|---|
| 942 | |
|---|
| 943 | $len = strlen($body); |
|---|
| 944 | $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15); |
|---|
| 945 | |
|---|
| 946 | while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) { |
|---|
| 947 | if ($sp == 0 || $body[$sp-1] == "\n") { |
|---|
| 948 | // do not touch blocks with more that X lines |
|---|
| 949 | if (substr_count($body, "\n", $sp) < $sig_max_lines) { |
|---|
| 950 | $body = substr($body, 0, max(0, $sp-1)); |
|---|
| 951 | } |
|---|
| 952 | break; |
|---|
| 953 | } |
|---|
| 954 | } |
|---|
| 955 | |
|---|
| 956 | return $body; |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | function rcmail_write_compose_attachments(&$message, $bodyIsHtml) |
|---|
| 961 | { |
|---|
| 962 | global $RCMAIL, $COMPOSE; |
|---|
| 963 | |
|---|
| 964 | $cid_map = $messages = array(); |
|---|
| 965 | foreach ((array)$message->mime_parts as $pid => $part) |
|---|
| 966 | { |
|---|
| 967 | if (($part->ctype_primary != 'message' || !$bodyIsHtml) && $part->ctype_primary != 'multipart' && |
|---|
| 968 | ($part->disposition == 'attachment' || ($part->disposition == 'inline' && $bodyIsHtml) || $part->filename) |
|---|
| 969 | && $part->mimetype != 'application/ms-tnef' |
|---|
| 970 | ) { |
|---|
| 971 | $skip = false; |
|---|
| 972 | if ($part->mimetype == 'message/rfc822') { |
|---|
| 973 | $messages[] = $part->mime_id; |
|---|
| 974 | } else if ($messages) { |
|---|
| 975 | // skip attachments included in message/rfc822 attachment (#1486487) |
|---|
| 976 | foreach ($messages as $mimeid) |
|---|
| 977 | if (strpos($part->mime_id, $mimeid.'.') === 0) { |
|---|
| 978 | $skip = true; |
|---|
| 979 | break; |
|---|
| 980 | } |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | if (!$skip && ($attachment = rcmail_save_attachment($message, $pid))) { |
|---|
| 984 | $COMPOSE['attachments'][$attachment['id']] = $attachment; |
|---|
| 985 | if ($bodyIsHtml && ($part->content_id || $part->content_location)) { |
|---|
| 986 | $url = $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id']; |
|---|
| 987 | if ($part->content_id) |
|---|
| 988 | $cid_map['cid:'.$part->content_id] = $url; |
|---|
| 989 | else |
|---|
| 990 | $cid_map[$part->content_location] = $url; |
|---|
| 991 | } |
|---|
| 992 | } |
|---|
| 993 | } |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | $COMPOSE['forward_attachments'] = true; |
|---|
| 997 | |
|---|
| 998 | return $cid_map; |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | function rcmail_write_inline_attachments(&$message) |
|---|
| 1003 | { |
|---|
| 1004 | global $RCMAIL, $COMPOSE; |
|---|
| 1005 | |
|---|
| 1006 | $cid_map = array(); |
|---|
| 1007 | foreach ((array)$message->mime_parts as $pid => $part) { |
|---|
| 1008 | if (($part->content_id || $part->content_location) && $part->filename) { |
|---|
| 1009 | if ($attachment = rcmail_save_attachment($message, $pid)) { |
|---|
| 1010 | $COMPOSE['attachments'][$attachment['id']] = $attachment; |
|---|
| 1011 | $url = $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id']; |
|---|
| 1012 | if ($part->content_id) |
|---|
| 1013 | $cid_map['cid:'.$part->content_id] = $url; |
|---|
| 1014 | else |
|---|
| 1015 | $cid_map[$part->content_location] = $url; |
|---|
| 1016 | } |
|---|
| 1017 | } |
|---|
| 1018 | } |
|---|
| 1019 | |
|---|
| 1020 | return $cid_map; |
|---|
| 1021 | } |
|---|
| 1022 | |
|---|
| 1023 | // Creates an attachment from the forwarded message |
|---|
| 1024 | function rcmail_write_forward_attachment(&$message) |
|---|
| 1025 | { |
|---|
| 1026 | global $RCMAIL, $COMPOSE; |
|---|
| 1027 | |
|---|
| 1028 | if (strlen($message->subject)) { |
|---|
| 1029 | $name = mb_substr($message->subject, 0, 64) . '.eml'; |
|---|
| 1030 | } |
|---|
| 1031 | else { |
|---|
| 1032 | $name = 'message_rfc822.eml'; |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | $mem_limit = parse_bytes(ini_get('memory_limit')); |
|---|
| 1036 | $curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB |
|---|
| 1037 | $data = $path = null; |
|---|
| 1038 | |
|---|
| 1039 | // don't load too big attachments into memory |
|---|
| 1040 | if ($mem_limit > 0 && $message->size > $mem_limit - $curr_mem) { |
|---|
| 1041 | $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); |
|---|
| 1042 | $path = tempnam($temp_dir, 'rcmAttmnt'); |
|---|
| 1043 | if ($fp = fopen($path, 'w')) { |
|---|
| 1044 | $RCMAIL->imap->get_raw_body($message->uid, $fp); |
|---|
| 1045 | fclose($fp); |
|---|
| 1046 | } else |
|---|
| 1047 | return false; |
|---|
| 1048 | } else { |
|---|
| 1049 | $data = $RCMAIL->imap->get_raw_body($message->uid); |
|---|
| 1050 | } |
|---|
| 1051 | |
|---|
| 1052 | $attachment = array( |
|---|
| 1053 | 'group' => $COMPOSE['id'], |
|---|
| 1054 | 'name' => $name, |
|---|
| 1055 | 'mimetype' => 'message/rfc822', |
|---|
| 1056 | 'data' => $data, |
|---|
| 1057 | 'path' => $path, |
|---|
| 1058 | 'size' => $path ? filesize($path) : strlen($data), |
|---|
| 1059 | ); |
|---|
| 1060 | |
|---|
| 1061 | $attachment = $RCMAIL->plugins->exec_hook('attachment_save', $attachment); |
|---|
| 1062 | |
|---|
| 1063 | if ($attachment['status']) { |
|---|
| 1064 | unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); |
|---|
| 1065 | $COMPOSE['attachments'][$attachment['id']] = $attachment; |
|---|
| 1066 | return true; |
|---|
| 1067 | } else if ($path) { |
|---|
| 1068 | @unlink($path); |
|---|
| 1069 | } |
|---|
| 1070 | |
|---|
| 1071 | return false; |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | |
|---|
| 1075 | function rcmail_save_attachment(&$message, $pid) |
|---|
| 1076 | { |
|---|
| 1077 | global $COMPOSE; |
|---|
| 1078 | |
|---|
| 1079 | $rcmail = rcmail::get_instance(); |
|---|
| 1080 | $part = $message->mime_parts[$pid]; |
|---|
| 1081 | $mem_limit = parse_bytes(ini_get('memory_limit')); |
|---|
| 1082 | $curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB |
|---|
| 1083 | $data = $path = null; |
|---|
| 1084 | |
|---|
| 1085 | // don't load too big attachments into memory |
|---|
| 1086 | if ($mem_limit > 0 && $part->size > $mem_limit - $curr_mem) { |
|---|
| 1087 | $temp_dir = unslashify($rcmail->config->get('temp_dir')); |
|---|
| 1088 | $path = tempnam($temp_dir, 'rcmAttmnt'); |
|---|
| 1089 | if ($fp = fopen($path, 'w')) { |
|---|
| 1090 | $message->get_part_content($pid, $fp); |
|---|
| 1091 | fclose($fp); |
|---|
| 1092 | } else |
|---|
| 1093 | return false; |
|---|
| 1094 | } else { |
|---|
| 1095 | $data = $message->get_part_content($pid); |
|---|
| 1096 | } |
|---|
| 1097 | |
|---|
| 1098 | $attachment = array( |
|---|
| 1099 | 'group' => $COMPOSE['id'], |
|---|
| 1100 | 'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary, |
|---|
| 1101 | 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|---|
| 1102 | 'content_id' => $part->content_id, |
|---|
| 1103 | 'data' => $data, |
|---|
| 1104 | 'path' => $path, |
|---|
| 1105 | 'size' => $path ? filesize($path) : strlen($data), |
|---|
| 1106 | ); |
|---|
| 1107 | |
|---|
| 1108 | $attachment = $rcmail->plugins->exec_hook('attachment_save', $attachment); |
|---|
| 1109 | |
|---|
| 1110 | if ($attachment['status']) { |
|---|
| 1111 | unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); |
|---|
| 1112 | return $attachment; |
|---|
| 1113 | } else if ($path) { |
|---|
| 1114 | @unlink($path); |
|---|
| 1115 | } |
|---|
| 1116 | |
|---|
| 1117 | return false; |
|---|
| 1118 | } |
|---|
| 1119 | |
|---|
| 1120 | function rcmail_save_image($path, $mimetype='') |
|---|
| 1121 | { |
|---|
| 1122 | global $COMPOSE; |
|---|
| 1123 | |
|---|
| 1124 | // handle attachments in memory |
|---|
| 1125 | $data = file_get_contents($path); |
|---|
| 1126 | |
|---|
| 1127 | $attachment = array( |
|---|
| 1128 | 'group' => $COMPOSE['id'], |
|---|
| 1129 | 'name' => rcmail_basename($path), |
|---|
| 1130 | 'mimetype' => $mimetype ? $mimetype : rc_mime_content_type($path, $name), |
|---|
| 1131 | 'data' => $data, |
|---|
| 1132 | 'size' => strlen($data), |
|---|
| 1133 | ); |
|---|
| 1134 | |
|---|
| 1135 | $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment); |
|---|
| 1136 | |
|---|
| 1137 | if ($attachment['status']) { |
|---|
| 1138 | unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); |
|---|
| 1139 | return $attachment; |
|---|
| 1140 | } |
|---|
| 1141 | |
|---|
| 1142 | return false; |
|---|
| 1143 | } |
|---|
| 1144 | |
|---|
| 1145 | function rcmail_basename($filename) |
|---|
| 1146 | { |
|---|
| 1147 | // basename() is not unicode safe and locale dependent |
|---|
| 1148 | if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) { |
|---|
| 1149 | return preg_replace('/^.*[\\\\\\/]/', '', $filename); |
|---|
| 1150 | } else { |
|---|
| 1151 | return preg_replace('/^.*[\/]/', '', $filename); |
|---|
| 1152 | } |
|---|
| 1153 | } |
|---|
| 1154 | |
|---|
| 1155 | function rcmail_compose_subject($attrib) |
|---|
| 1156 | { |
|---|
| 1157 | global $MESSAGE, $COMPOSE, $compose_mode; |
|---|
| 1158 | |
|---|
| 1159 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 1160 | unset($attrib['form']); |
|---|
| 1161 | |
|---|
| 1162 | $attrib['name'] = '_subject'; |
|---|
| 1163 | $attrib['spellcheck'] = 'true'; |
|---|
| 1164 | $textfield = new html_inputfield($attrib); |
|---|
| 1165 | |
|---|
| 1166 | $subject = ''; |
|---|
| 1167 | |
|---|
| 1168 | // use subject from post |
|---|
| 1169 | if (isset($_POST['_subject'])) { |
|---|
| 1170 | $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE); |
|---|
| 1171 | } |
|---|
| 1172 | // create a reply-subject |
|---|
| 1173 | else if ($compose_mode == RCUBE_COMPOSE_REPLY) { |
|---|
| 1174 | if (preg_match('/^re:/i', $MESSAGE->subject)) |
|---|
| 1175 | $subject = $MESSAGE->subject; |
|---|
| 1176 | else |
|---|
| 1177 | $subject = 'Re: '.$MESSAGE->subject; |
|---|
| 1178 | } |
|---|
| 1179 | // create a forward-subject |
|---|
| 1180 | else if ($compose_mode == RCUBE_COMPOSE_FORWARD) { |
|---|
| 1181 | if (preg_match('/^fwd:/i', $MESSAGE->subject)) |
|---|
| 1182 | $subject = $MESSAGE->subject; |
|---|
| 1183 | else |
|---|
| 1184 | $subject = 'Fwd: '.$MESSAGE->subject; |
|---|
| 1185 | } |
|---|
| 1186 | // creeate a draft-subject |
|---|
| 1187 | else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) { |
|---|
| 1188 | $subject = $MESSAGE->subject; |
|---|
| 1189 | } |
|---|
| 1190 | else if (!empty($COMPOSE['param']['subject'])) { |
|---|
| 1191 | $subject = $COMPOSE['param']['subject']; |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 1195 | $out .= $textfield->show($subject); |
|---|
| 1196 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 1197 | |
|---|
| 1198 | return $out; |
|---|
| 1199 | } |
|---|
| 1200 | |
|---|
| 1201 | |
|---|
| 1202 | function rcmail_compose_attachment_list($attrib) |
|---|
| 1203 | { |
|---|
| 1204 | global $OUTPUT, $CONFIG, $COMPOSE; |
|---|
| 1205 | |
|---|
| 1206 | // add ID if not given |
|---|
| 1207 | if (!$attrib['id']) |
|---|
| 1208 | $attrib['id'] = 'rcmAttachmentList'; |
|---|
| 1209 | |
|---|
| 1210 | $out = "\n"; |
|---|
| 1211 | $jslist = array(); |
|---|
| 1212 | |
|---|
| 1213 | if (is_array($COMPOSE['attachments'])) { |
|---|
| 1214 | if ($attrib['deleteicon']) { |
|---|
| 1215 | $button = html::img(array( |
|---|
| 1216 | 'src' => $CONFIG['skin_path'] . $attrib['deleteicon'], |
|---|
| 1217 | 'alt' => rcube_label('delete') |
|---|
| 1218 | )); |
|---|
| 1219 | } |
|---|
| 1220 | else |
|---|
| 1221 | $button = Q(rcube_label('delete')); |
|---|
| 1222 | |
|---|
| 1223 | foreach ($COMPOSE['attachments'] as $id => $a_prop) |
|---|
| 1224 | { |
|---|
| 1225 | if (empty($a_prop)) |
|---|
| 1226 | continue; |
|---|
| 1227 | |
|---|
| 1228 | $out .= html::tag('li', array('id' => 'rcmfile'.$id), |
|---|
| 1229 | html::a(array( |
|---|
| 1230 | 'href' => "#delete", |
|---|
| 1231 | 'title' => rcube_label('delete'), |
|---|
| 1232 | 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id)), |
|---|
| 1233 | $button) . Q($a_prop['name'])); |
|---|
| 1234 | |
|---|
| 1235 | $jslist['rcmfile'.$id] = array('name' => $a_prop['name'], 'complete' => true, 'mimetype' => $a_prop['mimetype']); |
|---|
| 1236 | } |
|---|
| 1237 | } |
|---|
| 1238 | |
|---|
| 1239 | if ($attrib['deleteicon']) |
|---|
| 1240 | $COMPOSE['deleteicon'] = $CONFIG['skin_path'] . $attrib['deleteicon']; |
|---|
| 1241 | if ($attrib['cancelicon']) |
|---|
| 1242 | $OUTPUT->set_env('cancelicon', $CONFIG['skin_path'] . $attrib['cancelicon']); |
|---|
| 1243 | if ($attrib['loadingicon']) |
|---|
| 1244 | $OUTPUT->set_env('loadingicon', $CONFIG['skin_path'] . $attrib['loadingicon']); |
|---|
| 1245 | |
|---|
| 1246 | $OUTPUT->set_env('attachments', $jslist); |
|---|
| 1247 | $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); |
|---|
| 1248 | |
|---|
| 1249 | return html::tag('ul', $attrib, $out, html::$common_attrib); |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | function rcmail_compose_attachment_form($attrib) |
|---|
| 1254 | { |
|---|
| 1255 | global $RCMAIL, $OUTPUT; |
|---|
| 1256 | |
|---|
| 1257 | // add ID if not given |
|---|
| 1258 | if (!$attrib['id']) |
|---|
| 1259 | $attrib['id'] = 'rcmUploadbox'; |
|---|
| 1260 | |
|---|
| 1261 | // Get filesize, enable upload progress bar |
|---|
| 1262 | $max_filesize = rcube_upload_init(); |
|---|
| 1263 | |
|---|
| 1264 | $button = new html_inputfield(array('type' => 'button')); |
|---|
| 1265 | |
|---|
| 1266 | $out = html::div($attrib, |
|---|
| 1267 | $OUTPUT->form_tag(array('name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'), |
|---|
| 1268 | html::div(null, rcmail_compose_attachment_field(array('size' => $attrib['attachmentfieldsize']))) . |
|---|
| 1269 | html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) . |
|---|
| 1270 | html::div('buttons', |
|---|
| 1271 | $button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' . |
|---|
| 1272 | $button->show(rcube_label('upload'), array('class' => 'button mainaction', 'onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)")) |
|---|
| 1273 | ) |
|---|
| 1274 | ) |
|---|
| 1275 | ); |
|---|
| 1276 | |
|---|
| 1277 | $OUTPUT->add_gui_object('uploadbox', $attrib['id']); |
|---|
| 1278 | return $out; |
|---|
| 1279 | } |
|---|
| 1280 | |
|---|
| 1281 | |
|---|
| 1282 | function rcmail_compose_attachment_field($attrib) |
|---|
| 1283 | { |
|---|
| 1284 | $attrib['type'] = 'file'; |
|---|
| 1285 | $attrib['name'] = '_attachments[]'; |
|---|
| 1286 | $attrib['multiple'] = 'multiple'; |
|---|
| 1287 | |
|---|
| 1288 | $field = new html_inputfield($attrib); |
|---|
| 1289 | return $field->show(); |
|---|
| 1290 | } |
|---|
| 1291 | |
|---|
| 1292 | |
|---|
| 1293 | function rcmail_priority_selector($attrib) |
|---|
| 1294 | { |
|---|
| 1295 | global $MESSAGE; |
|---|
| 1296 | |
|---|
| 1297 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 1298 | unset($attrib['form']); |
|---|
| 1299 | |
|---|
| 1300 | $attrib['name'] = '_priority'; |
|---|
| 1301 | $selector = new html_select($attrib); |
|---|
| 1302 | |
|---|
| 1303 | $selector->add(array(rcube_label('lowest'), |
|---|
| 1304 | rcube_label('low'), |
|---|
| 1305 | rcube_label('normal'), |
|---|
| 1306 | rcube_label('high'), |
|---|
| 1307 | rcube_label('highest')), |
|---|
| 1308 | array(5, 4, 0, 2, 1)); |
|---|
| 1309 | |
|---|
| 1310 | if (isset($_POST['_priority'])) |
|---|
| 1311 | $sel = $_POST['_priority']; |
|---|
| 1312 | else if (intval($MESSAGE->headers->priority) != 3) |
|---|
| 1313 | $sel = intval($MESSAGE->headers->priority); |
|---|
| 1314 | else |
|---|
| 1315 | $sel = 0; |
|---|
| 1316 | |
|---|
| 1317 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 1318 | $out .= $selector->show($sel); |
|---|
| 1319 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 1320 | |
|---|
| 1321 | return $out; |
|---|
| 1322 | } |
|---|
| 1323 | |
|---|
| 1324 | |
|---|
| 1325 | function rcmail_receipt_checkbox($attrib) |
|---|
| 1326 | { |
|---|
| 1327 | global $RCMAIL, $MESSAGE, $compose_mode; |
|---|
| 1328 | |
|---|
| 1329 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 1330 | unset($attrib['form']); |
|---|
| 1331 | |
|---|
| 1332 | if (!isset($attrib['id'])) |
|---|
| 1333 | $attrib['id'] = 'receipt'; |
|---|
| 1334 | |
|---|
| 1335 | $attrib['name'] = '_receipt'; |
|---|
| 1336 | $attrib['value'] = '1'; |
|---|
| 1337 | $checkbox = new html_checkbox($attrib); |
|---|
| 1338 | |
|---|
| 1339 | if ($MESSAGE && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) |
|---|
| 1340 | $mdn_default = (bool) $MESSAGE->headers->mdn_to; |
|---|
| 1341 | else |
|---|
| 1342 | $mdn_default = $RCMAIL->config->get('mdn_default'); |
|---|
| 1343 | |
|---|
| 1344 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 1345 | $out .= $checkbox->show($mdn_default); |
|---|
| 1346 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 1347 | |
|---|
| 1348 | return $out; |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | |
|---|
| 1352 | function rcmail_dsn_checkbox($attrib) |
|---|
| 1353 | { |
|---|
| 1354 | global $RCMAIL; |
|---|
| 1355 | |
|---|
| 1356 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 1357 | unset($attrib['form']); |
|---|
| 1358 | |
|---|
| 1359 | if (!isset($attrib['id'])) |
|---|
| 1360 | $attrib['id'] = 'dsn'; |
|---|
| 1361 | |
|---|
| 1362 | $attrib['name'] = '_dsn'; |
|---|
| 1363 | $attrib['value'] = '1'; |
|---|
| 1364 | $checkbox = new html_checkbox($attrib); |
|---|
| 1365 | |
|---|
| 1366 | $out = $form_start ? "$form_start\n" : ''; |
|---|
| 1367 | $out .= $checkbox->show($RCMAIL->config->get('dsn_default')); |
|---|
| 1368 | $out .= $form_end ? "\n$form_end" : ''; |
|---|
| 1369 | |
|---|
| 1370 | return $out; |
|---|
| 1371 | } |
|---|
| 1372 | |
|---|
| 1373 | |
|---|
| 1374 | function rcmail_editor_selector($attrib) |
|---|
| 1375 | { |
|---|
| 1376 | global $CONFIG, $MESSAGE, $compose_mode; |
|---|
| 1377 | |
|---|
| 1378 | // determine whether HTML or plain text should be checked |
|---|
| 1379 | $useHtml = rcmail_compose_editor_mode(); |
|---|
| 1380 | |
|---|
| 1381 | if (empty($attrib['editorid'])) |
|---|
| 1382 | $attrib['editorid'] = 'rcmComposeBody'; |
|---|
| 1383 | |
|---|
| 1384 | if (empty($attrib['name'])) |
|---|
| 1385 | $attrib['name'] = 'editorSelect'; |
|---|
| 1386 | |
|---|
| 1387 | $attrib['onchange'] = "return rcmail_toggle_editor(this, '".$attrib['editorid']."', '_is_html')"; |
|---|
| 1388 | |
|---|
| 1389 | $select = new html_select($attrib); |
|---|
| 1390 | |
|---|
| 1391 | $select->add(Q(rcube_label('htmltoggle')), 'html'); |
|---|
| 1392 | $select->add(Q(rcube_label('plaintoggle')), 'plain'); |
|---|
| 1393 | |
|---|
| 1394 | return $select->show($useHtml ? 'html' : 'plain'); |
|---|
| 1395 | |
|---|
| 1396 | foreach ($choices as $value => $text) { |
|---|
| 1397 | $attrib['id'] = '_' . $value; |
|---|
| 1398 | $attrib['value'] = $value; |
|---|
| 1399 | $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text))); |
|---|
| 1400 | } |
|---|
| 1401 | |
|---|
| 1402 | return $selector; |
|---|
| 1403 | } |
|---|
| 1404 | |
|---|
| 1405 | |
|---|
| 1406 | function rcmail_store_target_selection($attrib) |
|---|
| 1407 | { |
|---|
| 1408 | global $COMPOSE; |
|---|
| 1409 | |
|---|
| 1410 | $attrib['name'] = '_store_target'; |
|---|
| 1411 | $select = rcmail_mailbox_select(array_merge($attrib, array( |
|---|
| 1412 | 'noselection' => '- '.rcube_label('dontsave').' -', |
|---|
| 1413 | 'folder_filter' => 'mail', |
|---|
| 1414 | 'folder_rights' => 'w', |
|---|
| 1415 | ))); |
|---|
| 1416 | return $select->show($COMPOSE['param']['sent_mbox'], $attrib); |
|---|
| 1417 | } |
|---|
| 1418 | |
|---|
| 1419 | |
|---|
| 1420 | function rcmail_check_sent_folder($folder, $create=false) |
|---|
| 1421 | { |
|---|
| 1422 | global $IMAP; |
|---|
| 1423 | |
|---|
| 1424 | if ($IMAP->mailbox_exists($folder, true)) { |
|---|
| 1425 | return true; |
|---|
| 1426 | } |
|---|
| 1427 | |
|---|
| 1428 | // folder may exist but isn't subscribed (#1485241) |
|---|
| 1429 | if ($create) { |
|---|
| 1430 | if (!$IMAP->mailbox_exists($folder)) |
|---|
| 1431 | return $IMAP->create_mailbox($folder, true); |
|---|
| 1432 | else |
|---|
| 1433 | return $IMAP->subscribe($folder); |
|---|
| 1434 | } |
|---|
| 1435 | |
|---|
| 1436 | return false; |
|---|
| 1437 | } |
|---|
| 1438 | |
|---|
| 1439 | |
|---|
| 1440 | function get_form_tags($attrib) |
|---|
| 1441 | { |
|---|
| 1442 | global $RCMAIL, $MESSAGE_FORM, $COMPOSE; |
|---|
| 1443 | |
|---|
| 1444 | $form_start = ''; |
|---|
| 1445 | if (!$MESSAGE_FORM) |
|---|
| 1446 | { |
|---|
| 1447 | $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); |
|---|
| 1448 | $hiddenfields->add(array('name' => '_action', 'value' => 'send')); |
|---|
| 1449 | $hiddenfields->add(array('name' => '_id', 'value' => $COMPOSE['id'])); |
|---|
| 1450 | |
|---|
| 1451 | $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; |
|---|
| 1452 | $form_start .= $hiddenfields->show(); |
|---|
| 1453 | } |
|---|
| 1454 | |
|---|
| 1455 | $form_end = ($MESSAGE_FORM && !strlen($attrib['form'])) ? '</form>' : ''; |
|---|
| 1456 | $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
|---|
| 1457 | |
|---|
| 1458 | if (!$MESSAGE_FORM) |
|---|
| 1459 | $RCMAIL->output->add_gui_object('messageform', $form_name); |
|---|
| 1460 | |
|---|
| 1461 | $MESSAGE_FORM = $form_name; |
|---|
| 1462 | |
|---|
| 1463 | return array($form_start, $form_end); |
|---|
| 1464 | } |
|---|
| 1465 | |
|---|
| 1466 | |
|---|
| 1467 | // register UI objects |
|---|
| 1468 | $OUTPUT->add_handlers(array( |
|---|
| 1469 | 'composeheaders' => 'rcmail_compose_headers', |
|---|
| 1470 | 'composesubject' => 'rcmail_compose_subject', |
|---|
| 1471 | 'composebody' => 'rcmail_compose_body', |
|---|
| 1472 | 'composeattachmentlist' => 'rcmail_compose_attachment_list', |
|---|
| 1473 | 'composeattachmentform' => 'rcmail_compose_attachment_form', |
|---|
| 1474 | 'composeattachment' => 'rcmail_compose_attachment_field', |
|---|
| 1475 | 'priorityselector' => 'rcmail_priority_selector', |
|---|
| 1476 | 'editorselector' => 'rcmail_editor_selector', |
|---|
| 1477 | 'receiptcheckbox' => 'rcmail_receipt_checkbox', |
|---|
| 1478 | 'dsncheckbox' => 'rcmail_dsn_checkbox', |
|---|
| 1479 | 'storetarget' => 'rcmail_store_target_selection', |
|---|
| 1480 | )); |
|---|
| 1481 | |
|---|
| 1482 | $OUTPUT->send('compose'); |
|---|
| 1483 | |
|---|
| 1484 | |
|---|