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