| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * compose.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This code sends a mail. |
| 10 | * |
| 11 | * There are 4 modes of operation: |
| 12 | * - Start new mail |
| 13 | * - Add an attachment |
| 14 | * - Send mail |
| 15 | * - Save As Draft |
| 16 | * |
| 17 | * $Id$ |
| 18 | */ |
| 19 | |
| 20 | require_once('../src/validate.php'); |
| 21 | require_once('../functions/imap.php'); |
| 22 | require_once('../functions/date.php'); |
| 23 | require_once('../functions/mime.php'); |
| 24 | require_once('../functions/smtp.php'); |
| 25 | require_once('../functions/plugin.php'); |
| 26 | require_once('../functions/display_messages.php'); |
| 27 | |
| 28 | /* --------------------- Specific Functions ------------------------------ */ |
| 29 | |
| 30 | function replyAllString($header) { |
| 31 | global $include_self_reply_all, $username, $data_dir; |
| 32 | $excl_arr = array(); |
| 33 | /** |
| 34 | * 1) Remove the addresses we'll be sending the message 'to' |
| 35 | */ |
| 36 | $url_replytoall_avoid_addrs = ''; |
| 37 | if (isset($header->replyto)) { |
| 38 | $excl_ar = $header->getAddr_a('replyto'); |
| 39 | } |
| 40 | /** |
| 41 | * 2) Remove our identities from the CC list (they still can be in the |
| 42 | * TO list) only if $include_self_reply_all is turned off |
| 43 | */ |
| 44 | if (!$include_self_reply_all) { |
| 45 | $email_address = trim(getPref($data_dir, $username, 'email_address')); |
| 46 | $excl_ar[$email_address] = ''; |
| 47 | |
| 48 | $idents = getPref($data_dir, $username, 'identities'); |
| 49 | if ($idents != '' && $idents > 1) { |
| 50 | for ($i = 1; $i < $idents; $i ++) { |
| 51 | $cur_email_address = getPref($data_dir, $username, |
| 52 | 'email_address' . $i); |
| 53 | $cur_email_address = strtolower($cur_email_address); |
| 54 | $excl_ar[$cur_email_address] = ''; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * 3) get the addresses. |
| 61 | */ |
| 62 | $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); |
| 63 | |
| 64 | /** |
| 65 | * 4) generate the string. |
| 66 | */ |
| 67 | $url_replytoallcc = ''; |
| 68 | foreach( $url_replytoall_ar as $email => $personal) { |
| 69 | if ($personal) { |
| 70 | $url_replytoallcc .= ", \"$personal\" <$email>"; |
| 71 | } else { |
| 72 | $url_replytoallcc .= ', '. $email; |
| 73 | } |
| 74 | } |
| 75 | $url_replytoallcc = substr($url_replytoallcc,2); |
| 76 | return $url_replytoallcc; |
| 77 | } |
| 78 | |
| 79 | function getforwardHeader($orig_header) { |
| 80 | global $editor_size; |
| 81 | |
| 82 | $display = array( _("Subject") => strlen(_("Subject")), |
| 83 | _("From") => strlen(_("From")), |
| 84 | _("Date") => strlen(_("Date")), |
| 85 | _("To") => strlen(_("To")), |
| 86 | _("Cc") => strlen(_("Cc")) ); |
| 87 | $maxsize = max($display); |
| 88 | $indent = str_pad('',$maxsize+2); |
| 89 | foreach($display as $key => $val) { |
| 90 | $display[$key] = $key .': '. str_pad('', $maxsize - $val); |
| 91 | } |
| 92 | $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . |
| 93 | "\n". $display[_("Subject")] . |
| 94 | decodeHeader($orig_header->subject) . "\n" . |
| 95 | $display[_("From")] . |
| 96 | decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" . |
| 97 | $display[_("Date")] . |
| 98 | getLongDateString( $orig_header->date ). "\n" . |
| 99 | $display[_("To")] . |
| 100 | decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n"; |
| 101 | if ($orig_header->cc != array() && $orig_header->cc !='') { |
| 102 | $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n"; |
| 103 | } |
| 104 | $bodyTop .= str_pad('', $editor_size -2 , '-') . |
| 105 | "\n"; |
| 106 | return $bodyTop; |
| 107 | } |
| 108 | /* ----------------------------------------------------------------------- */ |
| 109 | |
| 110 | /* |
| 111 | * If the session is expired during a post this restores the compose session |
| 112 | * vars. |
| 113 | */ |
| 114 | //$session_expired = false; |
| 115 | if (session_is_registered('session_expired_post')) { |
| 116 | global $session_expired_post, $session_expired; |
| 117 | /* |
| 118 | * extra check for username so we don't display previous post data from |
| 119 | * another user during this session. |
| 120 | */ |
| 121 | if ($session_expired_post['username'] != $username) { |
| 122 | session_unregister('session_expired_post'); |
| 123 | session_unregister('session_expired'); |
| 124 | } else { |
| 125 | foreach ($session_expired_post as $postvar => $val) { |
| 126 | if (isset($val)) { |
| 127 | $$postvar = $val; |
| 128 | } else { |
| 129 | $$postvar = ''; |
| 130 | } |
| 131 | } |
| 132 | if (isset($send)) { |
| 133 | unset($send); |
| 134 | } |
| 135 | $session_expired = true; |
| 136 | } |
| 137 | session_unregister('session_expired_post'); |
| 138 | session_unregister('session_expired'); |
| 139 | if (!isset($mailbox)) { |
| 140 | $mailbox = ''; |
| 141 | } |
| 142 | if ($compose_new_win == '1') { |
| 143 | compose_Header($color, $mailbox); |
| 144 | } else { |
| 145 | displayPageHeader($color, $mailbox); |
| 146 | } |
| 147 | showInputForm($session, false); |
| 148 | exit(); |
| 149 | } |
| 150 | |
| 151 | if (!isset($attachments)) { |
| 152 | $attachments = array(); |
| 153 | session_register('attachments'); |
| 154 | } |
| 155 | |
| 156 | if (!isset($composesession)) { |
| 157 | $composesession = 0; |
| 158 | session_register('composesession'); |
| 159 | } |
| 160 | |
| 161 | if (!isset($session) || (isset($newmessage) && $newmessage)) { |
| 162 | $session = "$composesession" +1; |
| 163 | $composesession = $session; |
| 164 | session_register('composesession'); |
| 165 | } |
| 166 | |
| 167 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
| 168 | $mailbox = 'INBOX'; |
| 169 | } |
| 170 | |
| 171 | if (isset($draft)) { |
| 172 | include_once ('../src/draft_actions.php'); |
| 173 | if (! isset($passed_id)) { |
| 174 | $passed_id = 0; |
| 175 | } |
| 176 | if (! isset($MDN)) { |
| 177 | $MDN = 'False'; |
| 178 | } |
| 179 | if (! isset($mailprio)) { |
| 180 | $mailprio = ''; |
| 181 | } |
| 182 | if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) { |
| 183 | showInputForm($session); |
| 184 | exit(); |
| 185 | } else { |
| 186 | $draft_message = _("Draft Email Saved"); |
| 187 | /* If this is a resumed draft, then delete the original */ |
| 188 | if(isset($delete_draft)) { |
| 189 | Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) . |
| 190 | "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes"); |
| 191 | exit(); |
| 192 | } |
| 193 | else { |
| 194 | if ($compose_new_win == '1') { |
| 195 | Header("Location: compose.php?saved_draft=yes&session=$composesession"); |
| 196 | exit(); |
| 197 | } |
| 198 | else { |
| 199 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
| 200 | "&startMessage=1¬e=".urlencode($draft_message)); |
| 201 | exit(); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if (isset($send)) { |
| 208 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 209 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 210 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
| 211 | $AttachFailure = saveAttachedFiles($session); |
| 212 | } |
| 213 | if (checkInput(false) && !isset($AttachFailure)) { |
| 214 | $urlMailbox = urlencode (trim($mailbox)); |
| 215 | if (! isset($passed_id)) { |
| 216 | $passed_id = 0; |
| 217 | } |
| 218 | /* |
| 219 | * Set $default_charset to correspond with the user's selection |
| 220 | * of language interface. |
| 221 | */ |
| 222 | set_my_charset(); |
| 223 | |
| 224 | /* |
| 225 | * This is to change all newlines to \n |
| 226 | * We'll change them to \r\n later (in the sendMessage function) |
| 227 | */ |
| 228 | $body = str_replace("\r\n", "\n", $body); |
| 229 | $body = str_replace("\r", "\n", $body); |
| 230 | |
| 231 | /* |
| 232 | * Rewrap $body so that no line is bigger than $editor_size |
| 233 | * This should only really kick in the sqWordWrap function |
| 234 | * if the browser doesn't support "VIRTUAL" as the wrap type. |
| 235 | */ |
| 236 | $body = explode("\n", $body); |
| 237 | $newBody = ''; |
| 238 | foreach ($body as $line) { |
| 239 | if( $line <> '-- ' ) { |
| 240 | $line = rtrim($line); |
| 241 | } |
| 242 | if (strlen($line) <= $editor_size + 1) { |
| 243 | $newBody .= $line . "\n"; |
| 244 | } else { |
| 245 | sqWordWrap($line, $editor_size); |
| 246 | $newBody .= $line . "\n"; |
| 247 | } |
| 248 | } |
| 249 | $body = $newBody; |
| 250 | |
| 251 | do_hook('compose_send'); |
| 252 | |
| 253 | $MDN = False; // we are not sending a mdn response |
| 254 | if (! isset($mailprio)) { |
| 255 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
| 256 | $subject, $body, $passed_id, $MDN, '', $session); |
| 257 | } else { |
| 258 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
| 259 | $subject, $body, $passed_id, $MDN, $mailprio, $session); |
| 260 | } |
| 261 | if (! $Result) { |
| 262 | showInputForm($session); |
| 263 | exit(); |
| 264 | } |
| 265 | if ( isset($delete_draft)) { |
| 266 | Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ). |
| 267 | "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes"); |
| 268 | exit(); |
| 269 | } |
| 270 | if ($compose_new_win == '1') { |
| 271 | Header("Location: compose.php?mail_sent=yes"); |
| 272 | } |
| 273 | else { |
| 274 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
| 275 | "&startMessage=1"); |
| 276 | } |
| 277 | } else { |
| 278 | /* |
| 279 | *$imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 280 | * $imapPort, 0); |
| 281 | */ |
| 282 | if ($compose_new_win == '1') { |
| 283 | compose_Header($color, $mailbox); |
| 284 | } |
| 285 | else { |
| 286 | displayPageHeader($color, $mailbox); |
| 287 | } |
| 288 | if (isset($AttachFailure)) { |
| 289 | plain_error_message(_("Could not move/copy file. File not attached"), |
| 290 | $color); |
| 291 | } |
| 292 | checkInput(true); |
| 293 | showInputForm($session); |
| 294 | /* sqimap_logout($imapConnection); */ |
| 295 | } |
| 296 | } elseif (isset($html_addr_search_done)) { |
| 297 | if ($compose_new_win == '1') { |
| 298 | compose_Header($color, $mailbox); |
| 299 | } |
| 300 | else { |
| 301 | displayPageHeader($color, $mailbox); |
| 302 | } |
| 303 | |
| 304 | if (isset($send_to_search) && is_array($send_to_search)) { |
| 305 | foreach ($send_to_search as $k => $v) { |
| 306 | if (substr($k, 0, 1) == 'T') { |
| 307 | if ($send_to) { |
| 308 | $send_to .= ', '; |
| 309 | } |
| 310 | $send_to .= $v; |
| 311 | } |
| 312 | elseif (substr($k, 0, 1) == 'C') { |
| 313 | if ($send_to_cc) { |
| 314 | $send_to_cc .= ', '; |
| 315 | } |
| 316 | $send_to_cc .= $v; |
| 317 | } |
| 318 | elseif (substr($k, 0, 1) == 'B') { |
| 319 | if ($send_to_bcc) { |
| 320 | $send_to_bcc .= ', '; |
| 321 | } |
| 322 | $send_to_bcc .= $v; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | showInputForm($session); |
| 327 | } elseif (isset($html_addr_search)) { |
| 328 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 329 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 330 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
| 331 | if (saveAttachedFiles($session)) { |
| 332 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 333 | } |
| 334 | } |
| 335 | /* |
| 336 | * I am using an include so as to elminiate an extra unnecessary |
| 337 | * click. If you can think of a better way, please implement it. |
| 338 | */ |
| 339 | include_once('./addrbook_search_html.php'); |
| 340 | } elseif (isset($attach)) { |
| 341 | if (saveAttachedFiles($session)) { |
| 342 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 343 | } |
| 344 | if ($compose_new_win == '1') { |
| 345 | compose_Header($color, $mailbox); |
| 346 | } |
| 347 | else { |
| 348 | displayPageHeader($color, $mailbox); |
| 349 | } |
| 350 | showInputForm($session); |
| 351 | } |
| 352 | elseif (isset($sigappend)) { |
| 353 | $idents = getPref($data_dir, $username, 'identities', 0); |
| 354 | if ($idents > 1) { |
| 355 | if ($identity == 'default') { |
| 356 | $no = 'g'; |
| 357 | } else { |
| 358 | $no = $identity; |
| 359 | } |
| 360 | $signature = getSig($data_dir, $username, $no); |
| 361 | } |
| 362 | $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; |
| 363 | if ($compose_new_win == '1') { |
| 364 | compose_Header($color, $mailbox); |
| 365 | } else { |
| 366 | displayPageHeader($color, $mailbox); |
| 367 | } |
| 368 | showInputForm($session); |
| 369 | } elseif (isset($do_delete)) { |
| 370 | if ($compose_new_win == '1') { |
| 371 | compose_Header($color, $mailbox); |
| 372 | } |
| 373 | else { |
| 374 | displayPageHeader($color, $mailbox); |
| 375 | } |
| 376 | |
| 377 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 378 | if (isset($delete) && is_array($delete)) { |
| 379 | foreach($delete as $index) { |
| 380 | $attached_file = $hashed_attachment_dir . '/' |
| 381 | . $attachments[$index]['localfilename']; |
| 382 | unlink ($attached_file); |
| 383 | unset ($attachments[$index]); |
| 384 | } |
| 385 | setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 386 | } |
| 387 | |
| 388 | showInputForm($session); |
| 389 | } else { |
| 390 | /* |
| 391 | * This handles the default case as well as the error case |
| 392 | * (they had the same code) --> if (isset($smtpErrors)) |
| 393 | */ |
| 394 | |
| 395 | if ($compose_new_win == '1') { |
| 396 | compose_Header($color, $mailbox); |
| 397 | } else { |
| 398 | displayPageHeader($color, $mailbox); |
| 399 | } |
| 400 | |
| 401 | $newmail = true; |
| 402 | |
| 403 | if (!isset($passed_ent_id)) { |
| 404 | $passed_ent_id = ''; |
| 405 | } |
| 406 | if (!isset($passed_id)) { |
| 407 | $passed_id = ''; |
| 408 | } |
| 409 | if (!isset($mailbox)) { |
| 410 | $mailbox = ''; |
| 411 | } |
| 412 | if (!isset($action)) { |
| 413 | $action = ''; |
| 414 | } |
| 415 | |
| 416 | $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); |
| 417 | |
| 418 | /* in case the origin is not read_body.php */ |
| 419 | if (isset($send_to)) { |
| 420 | $values['send_to'] = $send_to; |
| 421 | } |
| 422 | if (isset($send_to_cc)) { |
| 423 | $values['send_to_cc'] = $send_to_cc; |
| 424 | } |
| 425 | if (isset($send_to_bcc)) { |
| 426 | $values['send_to_bcc'] = $send_to_bcc; |
| 427 | } |
| 428 | showInputForm($session, $values); |
| 429 | } |
| 430 | |
| 431 | exit(); |
| 432 | |
| 433 | /**************** Only function definitions go below *************/ |
| 434 | |
| 435 | |
| 436 | /* This function is used when not sending or adding attachments */ |
| 437 | function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { |
| 438 | global $editor_size, $default_use_priority, $body, |
| 439 | $use_signature, $composesession, $data_dir, $username, |
| 440 | $username, $key, $imapServerAddress, $imapPort; |
| 441 | |
| 442 | $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; |
| 443 | $mailprio = 3; |
| 444 | |
| 445 | if ($passed_id) { |
| 446 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 447 | $imapPort, 0); |
| 448 | |
| 449 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 450 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 451 | $body = ''; |
| 452 | if ($passed_ent_id) { |
| 453 | /* redefine the messsage in case of message/rfc822 */ |
| 454 | $message = $message->getEntity($passed_ent_id); |
| 455 | /* message is an entity which contains the envelope and type0=message |
| 456 | * and type1=rfc822. The actual entities are childs from |
| 457 | * $message->entities[0]. That's where the encoding and is located |
| 458 | */ |
| 459 | |
| 460 | $entities = $message->entities[0]->findDisplayEntity |
| 461 | (array(), $alt_order = array('text/plain')); |
| 462 | if (!count($entities)) { |
| 463 | $entities = $message->entities[0]->findDisplayEntity |
| 464 | (array(), $alt_order = array('text/plain','html/plain')); |
| 465 | } |
| 466 | $orig_header = $message->rfc822_header; /* here is the envelope located */ |
| 467 | /* redefine the message for picking up the attachments */ |
| 468 | $message = $message->entities[0]; |
| 469 | |
| 470 | } else { |
| 471 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); |
| 472 | if (!count($entities)) { |
| 473 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); |
| 474 | } |
| 475 | $orig_header = $message->rfc822_header; |
| 476 | } |
| 477 | $encoding = $message->header->encoding; |
| 478 | $type0 = $message->type0; |
| 479 | $type1 = $message->type1; |
| 480 | foreach ($entities as $ent) { |
| 481 | $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); |
| 482 | $body_part_entity = $message->getEntity($ent); |
| 483 | $bodypart = decodeBody($unencoded_bodypart, |
| 484 | $body_part_entity->header->encoding); |
| 485 | if ($type1 == 'html') { |
| 486 | $bodypart = strip_tags($bodypart); |
| 487 | } |
| 488 | $body .= $bodypart; |
| 489 | } |
| 490 | if ($default_use_priority) { |
| 491 | $mailprio = substr($orig_header->priority,0,1); |
| 492 | if (!$mailprio) { |
| 493 | $mailprio = 3; |
| 494 | } |
| 495 | } else { |
| 496 | $mailprio = ''; |
| 497 | } |
| 498 | ClearAttachments($session); |
| 499 | |
| 500 | $identity = ''; |
| 501 | $idents = getPref($data_dir, $username, 'identities'); |
| 502 | $from_o = $orig_header->from; |
| 503 | if (is_object($from_o)) { |
| 504 | $orig_from = $from_o->getAddress(); |
| 505 | } else { |
| 506 | $orig_from = ''; |
| 507 | } |
| 508 | if (!empty($idents) && $idents > 1) { |
| 509 | for ($i = 1; $i < $idents; $i++) { |
| 510 | $enc_from_name = '"'. |
| 511 | getPref($data_dir, |
| 512 | $username, |
| 513 | 'full_name' . $i) . |
| 514 | '" <' . getPref($data_dir, $username, |
| 515 | 'email_address' . $i) . '>'; |
| 516 | if ($enc_from_name == $orig_from) { |
| 517 | $identity = $i; |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | switch ($action) { |
| 524 | case ('draft'): |
| 525 | $use_signature = FALSE; |
| 526 | $send_to = $orig_header->getAddr_s('to'); |
| 527 | $send_to_cc = $orig_header->getAddr_s('cc'); |
| 528 | $send_to_bcc = $orig_header->getAddr_s('bcc'); |
| 529 | $subject = decodeHeader($orig_header->subject); |
| 530 | |
| 531 | $body_ary = explode("\n", $body); |
| 532 | $cnt = count($body_ary) ; |
| 533 | $body = ''; |
| 534 | for ($i=0; $i < $cnt; $i++) { |
| 535 | if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { |
| 536 | sqWordWrap($body_ary[$i], $editor_size ); |
| 537 | $body .= $body_ary[$i] . "\n"; |
| 538 | } |
| 539 | unset($body_ary[$i]); |
| 540 | } |
| 541 | sqUnWordWrap($body); |
| 542 | getAttachments($message, $session, $passed_id, $entities, $imapConnection); |
| 543 | break; |
| 544 | case ('edit_as_new'): |
| 545 | $send_to = $orig_header->getAddr_s('to'); |
| 546 | $send_to_cc = $orig_header->getAddr_s('cc'); |
| 547 | $send_to_bcc = $orig_header->getAddr_s('bcc'); |
| 548 | $subject = decodeHeader($orig_header->subject); |
| 549 | $mailprio = $orig_header->priority; |
| 550 | $orig_from = ''; |
| 551 | getAttachments($message, $session, $passed_id, $entities, $imapConnection); |
| 552 | sqUnWordWrap($body); |
| 553 | break; |
| 554 | case ('forward'): |
| 555 | $send_to = ''; |
| 556 | $subject = decodeHeader($orig_header->subject); |
| 557 | if ((substr(strtolower($subject), 0, 4) != 'fwd:') && |
| 558 | (substr(strtolower($subject), 0, 5) != '[fwd:') && |
| 559 | (substr(strtolower($subject), 0, 6) != '[ fwd:')) { |
| 560 | $subject = '[Fwd: ' . $subject . ']'; |
| 561 | } |
| 562 | $body = getforwardHeader($orig_header) . $body; |
| 563 | sqUnWordWrap($body); |
| 564 | getAttachments($message, $session, $passed_id, $entities, $imapConnection); |
| 565 | break; |
| 566 | case ('forward_as_attachment'): |
| 567 | getMessage_RFC822_Attachment($message, $session, $passed_id, $passed_ent_id, $imapConnection); |
| 568 | $body = ''; |
| 569 | break; |
| 570 | case ('reply_all'): |
| 571 | $send_to_cc = replyAllString($orig_header); |
| 572 | case ('reply'): |
| 573 | $send_to = $orig_header->reply_to; |
| 574 | if (is_object($send_to)) { |
| 575 | $send_to = $send_to->getAddr_s('reply_to'); |
| 576 | } else { |
| 577 | $send_to = $orig_header->getAddr_s('from'); |
| 578 | } |
| 579 | $subject = decodeHeader($orig_header->subject); |
| 580 | $subject = str_replace('"', "'", $subject); |
| 581 | $subject = trim($subject); |
| 582 | if (substr(strtolower($subject), 0, 3) != 're:') { |
| 583 | $subject = 'Re: ' . $subject; |
| 584 | } |
| 585 | /* this corrects some wrapping/quoting problems on replies */ |
| 586 | $rewrap_body = explode("\n", $body); |
| 587 | |
| 588 | $body = getReplyCitation($orig_header->from->personal); |
| 589 | $cnt = count($rewrap_body); |
| 590 | for ($i=0;$i<$cnt;$i++) { |
| 591 | // sqWordWrap($rewrap_body[$i], ($editor_size - 2)); |
| 592 | if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { |
| 593 | $gt = $matches[1]; |
| 594 | $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n"; |
| 595 | } else { |
| 596 | $body .= '> ' . $rewrap_body[$i] . "\n"; |
| 597 | } |
| 598 | unset($rewrap_body[$i]); |
| 599 | } |
| 600 | break; |
| 601 | default: |
| 602 | break; |
| 603 | } |
| 604 | sqimap_logout($imapConnection); |
| 605 | } |
| 606 | $ret = array( 'send_to' => $send_to, |
| 607 | 'send_to_cc' => $send_to_cc, |
| 608 | 'send_to_bcc' => $send_to_bcc, |
| 609 | 'subject' => $subject, |
| 610 | 'mailprio' => $mailprio, |
| 611 | 'body' => $body, |
| 612 | 'identity' => $identity ); |
| 613 | |
| 614 | return ($ret); |
| 615 | } /* function newMail() */ |
| 616 | |
| 617 | function getAttachments($message, $session, $passed_id, $entities, $imapConnection) { |
| 618 | global $attachments, $attachment_dir, $username, $data_dir; |
| 619 | |
| 620 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 621 | if (!count($message->entities) || |
| 622 | ($message->type0 == 'message' && $message->type1 == 'rfc822')) { |
| 623 | if ( !in_array($message->entity_id, $entities) && $message->entity_id) { |
| 624 | if ($message->type0 == 'message' && $message->type1 == 'rfc822') { |
| 625 | $filename = decodeHeader($message->rfc822_header->subject.'.eml'); |
| 626 | if ($filename == "") { |
| 627 | $filename = "untitled-".$message->entity_id.'.eml'; |
| 628 | } |
| 629 | } else { |
| 630 | $filename = decodeHeader($message->getFilename()); |
| 631 | } |
| 632 | $localfilename = GenerateRandomString(32, '', 7); |
| 633 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 634 | while (file_exists($full_localfilename)) { |
| 635 | $localfilename = GenerateRandomString(32, '', 7); |
| 636 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 637 | } |
| 638 | |
| 639 | $newAttachment = array(); |
| 640 | $newAttachment['localfilename'] = $localfilename; |
| 641 | $newAttachment['remotefilename'] = $filename; |
| 642 | $newAttachment['type'] = strtolower($message->type0 . |
| 643 | '/' . $message->type1); |
| 644 | $newAttachment['id'] = strtolower($message->header->id); |
| 645 | $newAttachment['session'] = $session; |
| 646 | |
| 647 | /* Write Attachment to file */ |
| 648 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w'); |
| 649 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
| 650 | $passed_id, $message->entity_id), |
| 651 | $message->header->encoding)); |
| 652 | fclose ($fp); |
| 653 | $attachments[] = $newAttachment; |
| 654 | } |
| 655 | } else { |
| 656 | for ($i = 0; $i < count($message->entities); $i++) { |
| 657 | getAttachments($message->entities[$i], $session, $passed_id, $entities, $imapConnection); |
| 658 | } |
| 659 | } |
| 660 | setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | function getMessage_RFC822_Attachment($message, $session, $passed_id, |
| 665 | $passed_ent_id='', $imapConnection) { |
| 666 | global $attachments, $attachment_dir, $username, $data_dir, $uid_support; |
| 667 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 668 | if (!$passed_ent_id) { |
| 669 | $body_a = sqimap_run_command($imapConnection, |
| 670 | 'FETCH '.$passed_id.' RFC822', |
| 671 | TRUE, $response, $readmessage, |
| 672 | $uid_support); |
| 673 | } else { |
| 674 | $body_a = sqimap_run_command($imapConnection, |
| 675 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
| 676 | TRUE, $response, $readmessage, $uid_support); |
| 677 | $message = $message->parent; |
| 678 | } |
| 679 | if ($response = 'OK') { |
| 680 | $subject = encodeHeader($message->rfc822_header->subject); |
| 681 | array_shift($body_a); |
| 682 | $body = implode('', $body_a) . "\r\n"; |
| 683 | |
| 684 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
| 685 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 686 | |
| 687 | $fp = fopen( $full_localfilename, 'w'); |
| 688 | fwrite ($fp, $body); |
| 689 | fclose($fp); |
| 690 | $newAttachment = array(); |
| 691 | $newAttachment['localfilename'] = $localfilename; |
| 692 | $newAttachment['type'] = "message/rfc822"; |
| 693 | $newAttachment['remotefilename'] = $subject.'.eml'; |
| 694 | $newAttachment['session'] = $session; |
| 695 | $attachments[] = $newAttachment; |
| 696 | } |
| 697 | setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | function showInputForm ($session, $values=false) { |
| 702 | global $send_to, $send_to_cc, $body, |
| 703 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
| 704 | $editor_size, $attachments, $subject, $newmail, |
| 705 | $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox, |
| 706 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
| 707 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
| 708 | $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win, |
| 709 | $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action, |
| 710 | $username; |
| 711 | |
| 712 | $subject = decodeHeader($subject, false); |
| 713 | if ($values) { |
| 714 | $send_to = $values['send_to']; |
| 715 | $send_to_cc = $values['send_to_cc']; |
| 716 | $send_to_bcc = $values['send_to_bcc']; |
| 717 | $subject = $values['subject']; |
| 718 | $mailprio = $values['mailprio']; |
| 719 | $body = $values['body']; |
| 720 | $identity = $values['identity']; |
| 721 | } |
| 722 | |
| 723 | if ($use_javascript_addr_book) { |
| 724 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
| 725 | 'function open_abook() { ' . "\n" . |
| 726 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
| 727 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
| 728 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
| 729 | ' nwin.opener = document.windows;' . "\n" . |
| 730 | "}\n" . |
| 731 | '// --></SCRIPT>' . "\n\n"; |
| 732 | } |
| 733 | |
| 734 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
| 735 | 'ENCTYPE="multipart/form-data"'; |
| 736 | do_hook("compose_form"); |
| 737 | |
| 738 | |
| 739 | echo ">\n"; |
| 740 | |
| 741 | if ($action == 'draft') { |
| 742 | echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n"; |
| 743 | } |
| 744 | if (isset($delete_draft)) { |
| 745 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
| 746 | } |
| 747 | if (isset($session)) { |
| 748 | echo '<input type="hidden" name="session" value="' . $session . "\">\n"; |
| 749 | } |
| 750 | |
| 751 | if (isset($passed_id)) { |
| 752 | echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n"; |
| 753 | } |
| 754 | |
| 755 | if ($saved_draft == 'yes') { |
| 756 | echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>'; |
| 757 | } |
| 758 | if ($mail_sent == 'yes') { |
| 759 | echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>'; |
| 760 | } |
| 761 | echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
| 762 | if ($compose_new_win == '1') { |
| 763 | echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" . |
| 764 | ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n"; |
| 765 | } |
| 766 | if ($location_of_buttons == 'top') { |
| 767 | showComposeButtonRow(); |
| 768 | } |
| 769 | |
| 770 | $idents = getPref($data_dir, $username, 'identities', 0); |
| 771 | if ($idents > 1) { |
| 772 | echo ' <TR>' . "\n" . |
| 773 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
| 774 | "\n" . |
| 775 | _("From:") . |
| 776 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 777 | '<select name=identity>' . "\n" . |
| 778 | '<option value=default>' . |
| 779 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
| 780 | $em = getPref($data_dir, $username, 'email_address'); |
| 781 | if ($em != '') { |
| 782 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 783 | } |
| 784 | for ($i = 1; $i < $idents; $i ++) { |
| 785 | echo '<option value="' . $i . '"'; |
| 786 | if (isset($identity) && $identity == $i) { |
| 787 | echo ' SELECTED'; |
| 788 | } |
| 789 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
| 790 | 'full_name' . $i)); |
| 791 | $em = getPref($data_dir, $username, 'email_address' . $i); |
| 792 | if ($em != '') { |
| 793 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 794 | } |
| 795 | echo '</option>'; |
| 796 | } |
| 797 | echo '</select>' . "\n" . |
| 798 | ' </TD>' . "\n" . |
| 799 | ' </TR>' . "\n"; |
| 800 | } |
| 801 | echo ' <TR>' . "\n" . |
| 802 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" . |
| 803 | _("To:") . |
| 804 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 805 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
| 806 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
| 807 | ' </TD>' . "\n" . |
| 808 | ' </TR>' . "\n" . |
| 809 | ' <TR>' . "\n" . |
| 810 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 811 | _("CC:") . |
| 812 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 813 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
| 814 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
| 815 | ' </TD>' . "\n" . |
| 816 | ' </TR>' . "\n" . |
| 817 | ' <TR>' . "\n" . |
| 818 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 819 | _("BCC:") . |
| 820 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 821 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
| 822 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
| 823 | '</TD></TR>' . "\n" . |
| 824 | ' <TR>' . "\n" . |
| 825 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 826 | _("Subject:") . |
| 827 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
| 828 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
| 829 | htmlspecialchars($subject) . '">'; |
| 830 | echo '</td></tr>' . "\n\n"; |
| 831 | |
| 832 | if ($location_of_buttons == 'between') { |
| 833 | showComposeButtonRow(); |
| 834 | } |
| 835 | if ($compose_new_win == '1') { |
| 836 | echo ' <TR>' . "\n" . |
| 837 | ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" . |
| 838 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
| 839 | $editor_size . '" WRAP="VIRTUAL">'; |
| 840 | } |
| 841 | else { |
| 842 | echo ' <TR>' . "\n" . |
| 843 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
| 844 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
| 845 | $editor_size . '" WRAP="VIRTUAL">'; |
| 846 | } |
| 847 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
| 848 | if ($sig_first == '1') { |
| 849 | if ($charset == 'iso-2022-jp') { |
| 850 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
| 851 | } else { |
| 852 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
| 853 | } |
| 854 | echo "\n\n".htmlspecialchars($body); |
| 855 | } |
| 856 | else { |
| 857 | echo "\n\n".htmlspecialchars($body); |
| 858 | if ($charset == 'iso-2022-jp') { |
| 859 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
| 860 | }else{ |
| 861 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | else { |
| 866 | echo htmlspecialchars($body); |
| 867 | } |
| 868 | echo '</TEXTAREA><BR>' . "\n" . |
| 869 | ' </TD>' . "\n" . |
| 870 | ' </TR>' . "\n"; |
| 871 | |
| 872 | if ($location_of_buttons == 'bottom') { |
| 873 | showComposeButtonRow(); |
| 874 | } else { |
| 875 | echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' . |
| 876 | ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . |
| 877 | ' <BR><BR>' . |
| 878 | ' </TD></TR>' . "\n"; |
| 879 | } |
| 880 | |
| 881 | /* This code is for attachments */ |
| 882 | echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' . |
| 883 | ' <tr><td>' . |
| 884 | ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' . |
| 885 | ' <tr><td>' . |
| 886 | ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' . |
| 887 | ' <TR>' . "\n" . |
| 888 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" . |
| 889 | _("Attach:") . |
| 890 | ' </TD>' . "\n" . |
| 891 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
| 892 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
| 893 | ' <input type="submit" name="attach"' . |
| 894 | ' value="' . _("Add") .'">' . "\n" . |
| 895 | ' </TD>' . "\n" . |
| 896 | ' </TR>' . "\n"; |
| 897 | |
| 898 | |
| 899 | $s_a = array(); |
| 900 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 901 | foreach ($attachments as $key => $info) { |
| 902 | if ($info['session'] == $session) { |
| 903 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 904 | $s_a[] = '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" . |
| 905 | $info['remotefilename'] . ' - ' . $info['type'] . ' (' . |
| 906 | show_readable_size( filesize( $attached_file ) ) . ")<br>\n"; |
| 907 | } |
| 908 | } |
| 909 | if (count($s_a)) { |
| 910 | foreach ($s_a as $s) { |
| 911 | echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>'; |
| 912 | } |
| 913 | echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' . |
| 914 | _("Delete selected attachments") . "\">\n" . |
| 915 | '</td></tr>'; |
| 916 | } |
| 917 | echo ' </table></td></tr>' . |
| 918 | ' </table>' . |
| 919 | ' </td></tr>'; |
| 920 | |
| 921 | /* End of attachment code */ |
| 922 | if ($compose_new_win == '1') { |
| 923 | echo '</TABLE>'."\n"; |
| 924 | } |
| 925 | echo '</TABLE>' . "\n" . |
| 926 | '<input type="hidden" name="username" value="'. $username . "\">\n" . |
| 927 | '<input type=hidden name=action value=' . $action . ">\n" . |
| 928 | '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
| 929 | "\">\n" . |
| 930 | '</FORM>'; |
| 931 | do_hook('compose_bottom'); |
| 932 | echo '</BODY></HTML>' . "\n"; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | function showComposeButtonRow() { |
| 937 | global $use_javascript_addr_book, $save_as_draft, |
| 938 | $default_use_priority, $mailprio, $default_use_mdn, |
| 939 | $request_mdn, $request_dr, |
| 940 | $data_dir, $username; |
| 941 | |
| 942 | echo " <TR><TD>\n</TD><TD>\n"; |
| 943 | if ($default_use_priority) { |
| 944 | if(!isset($mailprio)) { |
| 945 | $mailprio = "3"; |
| 946 | } |
| 947 | echo _("Priority") .': <select name="mailprio">'. |
| 948 | '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
| 949 | '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
| 950 | '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
| 951 | "</select>"; |
| 952 | } |
| 953 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
| 954 | if ($default_use_mdn) { |
| 955 | if ($mdn_user_support) { |
| 956 | echo "\n\t". _("Receipt") .': '. |
| 957 | '<input type="checkbox" name="request_mdn" value=1'. |
| 958 | ($request_mdn=='1'?' checked':'') .'>'. _("On Read"). |
| 959 | ' <input type="checkbox" name="request_dr" value=1'. |
| 960 | ($request_dr=='1'?' checked':'') .'>'. _("On Delivery"); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | echo " </td></tr>\n <TR><td>\n </td><td>\n" . |
| 965 | "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n"; |
| 966 | if ($use_javascript_addr_book) { |
| 967 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"". |
| 968 | " <input type=button value=\\\""._("Addresses"). |
| 969 | "\\\" onclick='javascript:open_abook();'>\");". |
| 970 | " // --></SCRIPT><NOSCRIPT>\n". |
| 971 | " <input type=submit name=\"html_addr_search\" value=\"". |
| 972 | _("Addresses")."\">". |
| 973 | " </NOSCRIPT>\n"; |
| 974 | } else { |
| 975 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
| 976 | _("Addresses")."\">"; |
| 977 | } |
| 978 | |
| 979 | if ($save_as_draft) { |
| 980 | echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
| 981 | } |
| 982 | |
| 983 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
| 984 | do_hook('compose_button_row'); |
| 985 | |
| 986 | echo " </TD></TR>\n\n"; |
| 987 | } |
| 988 | |
| 989 | function checkInput ($show) { |
| 990 | /* |
| 991 | * I implemented the $show variable because the error messages |
| 992 | * were getting sent before the page header. So, I check once |
| 993 | * using $show=false, and then when i'm ready to display the error |
| 994 | * message, show=true |
| 995 | */ |
| 996 | global $body, $send_to, $subject, $color; |
| 997 | |
| 998 | if ($send_to == '') { |
| 999 | if ($show) { |
| 1000 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
| 1001 | } |
| 1002 | return false; |
| 1003 | } |
| 1004 | return true; |
| 1005 | } /* function checkInput() */ |
| 1006 | |
| 1007 | |
| 1008 | /* True if FAILURE */ |
| 1009 | function saveAttachedFiles($session) { |
| 1010 | global $HTTP_POST_FILES, $attachment_dir, $attachments, $username, |
| 1011 | $data_dir; |
| 1012 | |
| 1013 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 1014 | $localfilename = GenerateRandomString(32, '', 7); |
| 1015 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 1016 | while (file_exists($full_localfilename)) { |
| 1017 | $localfilename = GenerateRandomString(32, '', 7); |
| 1018 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 1019 | } |
| 1020 | |
| 1021 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 1022 | if (function_exists("move_uploaded_file")) { |
| 1023 | if (!@move_uploaded_file($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 1024 | return true; |
| 1025 | } |
| 1026 | } else { |
| 1027 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 1028 | return true; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | } |
| 1033 | $newAttachment['localfilename'] = $localfilename; |
| 1034 | $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name']; |
| 1035 | $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']); |
| 1036 | $newAttachment['session'] = $session; |
| 1037 | |
| 1038 | if ($newAttachment['type'] == "") { |
| 1039 | $newAttachment['type'] = 'application/octet-stream'; |
| 1040 | } |
| 1041 | $attachments[] = $newAttachment; |
| 1042 | setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 1043 | } |
| 1044 | |
| 1045 | function ClearAttachments($session) |
| 1046 | { |
| 1047 | global $username, $attachments, $attachment_dir, $data_dir; |
| 1048 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 1049 | |
| 1050 | $rem_attachments = array(); |
| 1051 | if (is_array($attachments)) { |
| 1052 | foreach ($attachments as $info) { |
| 1053 | if ($info['session'] == $session) { |
| 1054 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 1055 | if (file_exists($attached_file)) { |
| 1056 | unlink($attached_file); |
| 1057 | } |
| 1058 | } |
| 1059 | else { |
| 1060 | $rem_attachments[] = $info; |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | $attachments = $rem_attachments; |
| 1065 | setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | function getReplyCitation($orig_from) |
| 1070 | { |
| 1071 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
| 1072 | |
| 1073 | /* First, return an empty string when no citation style selected. */ |
| 1074 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
| 1075 | return ''; |
| 1076 | } |
| 1077 | |
| 1078 | /* Make sure our final value isn't an empty string. */ |
| 1079 | if ($orig_from == '') { |
| 1080 | return ''; |
| 1081 | } |
| 1082 | |
| 1083 | /* Otherwise, try to select the desired citation style. */ |
| 1084 | switch ($reply_citation_style) { |
| 1085 | case 'author_said': |
| 1086 | $start = ''; |
| 1087 | $end = ' ' . _("said") . ':'; |
| 1088 | break; |
| 1089 | case 'quote_who': |
| 1090 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
| 1091 | $end = '">'; |
| 1092 | break; |
| 1093 | case 'user-defined': |
| 1094 | $start = $reply_citation_start . |
| 1095 | ($reply_citation_start == '' ? '' : ' '); |
| 1096 | $end = $reply_citation_end; |
| 1097 | break; |
| 1098 | default: |
| 1099 | return ''; |
| 1100 | } |
| 1101 | |
| 1102 | /* Build and return the citation string. */ |
| 1103 | return ($start . $orig_from . $end . "\n"); |
| 1104 | } |
| 1105 | |
| 1106 | ?> |