| 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 | /* Path for SquirrelMail required files. */ |
| 21 | define('SM_PATH','../'); |
| 22 | |
| 23 | /* SquirrelMail required files. */ |
| 24 | require_once(SM_PATH . 'include/validate.php'); |
| 25 | require_once(SM_PATH . 'functions/imap.php'); |
| 26 | require_once(SM_PATH . 'functions/date.php'); |
| 27 | require_once(SM_PATH . 'functions/mime.php'); |
| 28 | require_once(SM_PATH . 'functions/plugin.php'); |
| 29 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 30 | require_once(SM_PATH . 'class/deliver/Deliver.class.php'); |
| 31 | |
| 32 | /* --------------------- Get globals ------------------------------------- */ |
| 33 | $username = $_SESSION['username']; |
| 34 | $onetimepad = $_SESSION['onetimepad']; |
| 35 | $base_uri = $_SESSION['base_uri']; |
| 36 | $delimiter = $_SESSION['delimiter']; |
| 37 | |
| 38 | if (isset($_POST['return'])) { |
| 39 | $html_addr_search_done = 'Use Addresses'; |
| 40 | } |
| 41 | if ( isset($_SESSION['composesession']) ) { |
| 42 | $composesession = $_SESSION['composesession']; |
| 43 | } |
| 44 | sqextractGlobalVar('action'); |
| 45 | sqextractGlobalVar('session'); |
| 46 | sqextractGlobalVar('mailbox'); |
| 47 | sqextractGlobalVar('identity'); |
| 48 | sqextractGlobalVar('send_to'); |
| 49 | sqextractGlobalVar('send_to_cc'); |
| 50 | sqextractGlobalVar('send_to_bcc'); |
| 51 | sqextractGlobalVar('subject'); |
| 52 | sqextractGlobalVar('body'); |
| 53 | sqextractGlobalVar('mailprio'); |
| 54 | sqextractGlobalVar('request_mdn'); |
| 55 | sqextractGlobalVar('request_dr'); |
| 56 | sqextractGlobalVar('html_addr_search'); |
| 57 | sqextractGlobalVar('mail_sent'); |
| 58 | sqextractGlobalVar('passed_id'); |
| 59 | sqextractGlobalVar('passed_ent_id'); |
| 60 | sqextractGlobalVar('send'); |
| 61 | |
| 62 | if ( isset($_POST['sigappend']) ) { |
| 63 | $sigappend = $_POST['sigappend']; |
| 64 | } |
| 65 | /* From addressbook search */ |
| 66 | if ( isset($_POST['from_htmladdr_search']) ) { |
| 67 | $from_htmladdr_search = $_POST['from_htmladdr_search']; |
| 68 | } |
| 69 | if ( isset($_POST['addr_search_done']) ) { |
| 70 | $html_addr_search_done = $_POST['addr_search_done']; |
| 71 | } |
| 72 | if ( isset($_POST['send_to_search']) ) { |
| 73 | $send_to_search = &$_POST['send_to_search']; |
| 74 | } |
| 75 | |
| 76 | /* Attachments */ |
| 77 | sqextractGlobalVar('attach'); |
| 78 | if ( isset($_POST['do_delete']) ) { |
| 79 | $do_delete = $_POST['do_delete']; |
| 80 | } |
| 81 | if ( isset($_POST['delete']) ) { |
| 82 | $delete = &$_POST['delete']; |
| 83 | } |
| 84 | if ( isset($_SESSION['compose_messages']) ) { |
| 85 | $compose_messages = &$_SESSION['compose_messages']; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /* Forward message as attachment */ |
| 90 | if ( isset($_GET['attachedmessages']) ) { |
| 91 | $attachedmessages = $_GET['attachedmessages']; |
| 92 | } |
| 93 | |
| 94 | /* Drafts */ |
| 95 | sqextractGlobalVar('draft'); |
| 96 | sqextractGlobalVar('draft_id'); |
| 97 | sqextractGlobalVar('ent_num'); |
| 98 | sqextractGlobalVar('saved_draft'); |
| 99 | sqextractGlobalVar('delete_draft'); |
| 100 | |
| 101 | $key = $_COOKIE['key']; |
| 102 | |
| 103 | /* --------------------- Specific Functions ------------------------------ */ |
| 104 | |
| 105 | function replyAllString($header) { |
| 106 | global $include_self_reply_all, $username, $data_dir; |
| 107 | $excl_ar = array(); |
| 108 | /** |
| 109 | * 1) Remove the addresses we'll be sending the message 'to' |
| 110 | */ |
| 111 | $url_replytoall_avoid_addrs = ''; |
| 112 | if (isset($header->replyto)) { |
| 113 | $excl_ar = $header->getAddr_a('replyto'); |
| 114 | } |
| 115 | /** |
| 116 | * 2) Remove our identities from the CC list (they still can be in the |
| 117 | * TO list) only if $include_self_reply_all is turned off |
| 118 | */ |
| 119 | if (!$include_self_reply_all) { |
| 120 | $email_address = trim(getPref($data_dir, $username, 'email_address')); |
| 121 | $excl_ar[$email_address] = ''; |
| 122 | $idents = getPref($data_dir, $username, 'identities'); |
| 123 | if ($idents != '' && $idents > 1) { |
| 124 | $first_id = false; |
| 125 | for ($i = 1; $i < $idents; $i ++) { |
| 126 | $cur_email_address = getPref($data_dir, $username, |
| 127 | 'email_address' . $i); |
| 128 | $cur_email_address = strtolower($cur_email_address); |
| 129 | $excl_ar[$cur_email_address] = ''; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * 3) get the addresses. |
| 136 | */ |
| 137 | $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); |
| 138 | |
| 139 | /** |
| 140 | * 4) generate the string. |
| 141 | */ |
| 142 | $url_replytoallcc = ''; |
| 143 | foreach( $url_replytoall_ar as $email => $personal) { |
| 144 | if ($personal) { |
| 145 | $url_replytoallcc .= ", \"$personal\" <$email>"; |
| 146 | } else { |
| 147 | $url_replytoallcc .= ', '. $email; |
| 148 | } |
| 149 | } |
| 150 | $url_replytoallcc = substr($url_replytoallcc,2); |
| 151 | return $url_replytoallcc; |
| 152 | } |
| 153 | |
| 154 | function getforwardHeader($orig_header) { |
| 155 | global $editor_size; |
| 156 | |
| 157 | $display = array( _("Subject") => strlen(_("Subject")), |
| 158 | _("From") => strlen(_("From")), |
| 159 | _("Date") => strlen(_("Date")), |
| 160 | _("To") => strlen(_("To")), |
| 161 | _("Cc") => strlen(_("Cc")) ); |
| 162 | $maxsize = max($display); |
| 163 | $indent = str_pad('',$maxsize+2); |
| 164 | foreach($display as $key => $val) { |
| 165 | $display[$key] = $key .': '. str_pad('', $maxsize - $val); |
| 166 | } |
| 167 | $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . |
| 168 | "\n". $display[_("Subject")] . |
| 169 | decodeHeader($orig_header->subject) . "\n" . |
| 170 | $display[_("From")] . |
| 171 | decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" . |
| 172 | $display[_("Date")] . |
| 173 | getLongDateString( $orig_header->date ). "\n" . |
| 174 | $display[_("To")] . |
| 175 | decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n"; |
| 176 | if ($orig_header->cc != array() && $orig_header->cc !='') { |
| 177 | $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n"; |
| 178 | } |
| 179 | $bodyTop .= str_pad('', $editor_size -2 , '-') . |
| 180 | "\n"; |
| 181 | return $bodyTop; |
| 182 | } |
| 183 | /* ----------------------------------------------------------------------- */ |
| 184 | |
| 185 | /* |
| 186 | * If the session is expired during a post this restores the compose session |
| 187 | * vars. |
| 188 | */ |
| 189 | if (sqsession_is_registered('session_expired_post')) { |
| 190 | $session_expired_post = $_SESSION['session_expired_post']; |
| 191 | /* |
| 192 | * extra check for username so we don't display previous post data from |
| 193 | * another user during this session. |
| 194 | */ |
| 195 | if ($session_expired_post['username'] != $username) { |
| 196 | unset($session_expired_post); |
| 197 | sqsession_unregister('session_expired_post'); |
| 198 | session_write_close(); |
| 199 | } else { |
| 200 | foreach ($session_expired_post as $postvar => $val) { |
| 201 | if (isset($val)) { |
| 202 | $$postvar = $val; |
| 203 | } else { |
| 204 | $$postvar = ''; |
| 205 | } |
| 206 | } |
| 207 | $compose_messages = unserialize(urldecode($restoremessages)); |
| 208 | sqsession_register($compose_messages,'compose_messages'); |
| 209 | sqsession_register($composesession,'composesession'); |
| 210 | if (isset($send)) { |
| 211 | unset($send); |
| 212 | } |
| 213 | $session_expired = true; |
| 214 | } |
| 215 | unset($session_expired_post); |
| 216 | sqsession_unregister('session_expired_post'); |
| 217 | session_write_close(); |
| 218 | if (!isset($mailbox)) { |
| 219 | $mailbox = ''; |
| 220 | } |
| 221 | |
| 222 | if ($compose_new_win == '1') { |
| 223 | compose_Header($color, $mailbox); |
| 224 | } else { |
| 225 | displayPageHeader($color, $mailbox); |
| 226 | } |
| 227 | showInputForm($session, false); |
| 228 | exit(); |
| 229 | } |
| 230 | if (!isset($composesession)) { |
| 231 | $composesession = 0; |
| 232 | sqsession_register(0,'composesession'); |
| 233 | } |
| 234 | |
| 235 | if (!isset($session) || (isset($newmessage) && $newmessage)) { |
| 236 | sqsession_unregister('composesession'); |
| 237 | $session = "$composesession" +1; |
| 238 | $composesession = $session; |
| 239 | sqsession_register($composesession,'composesession'); |
| 240 | } |
| 241 | if (!isset($compose_messages)) { |
| 242 | $compose_messages = array(); |
| 243 | } |
| 244 | if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { |
| 245 | /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */ |
| 246 | $composeMessage = new Message(); |
| 247 | $rfc822_header = new Rfc822Header(); |
| 248 | $composeMessage->rfc822_header = $rfc822_header; |
| 249 | $composeMessage->reply_rfc822_header = ''; |
| 250 | $compose_messages[$session] = $composeMessage; |
| 251 | sqsession_register($compose_messages,'compose_messages'); |
| 252 | } else { |
| 253 | $composeMessage=$compose_messages[$session]; |
| 254 | } |
| 255 | |
| 256 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
| 257 | $mailbox = 'INBOX'; |
| 258 | } |
| 259 | |
| 260 | if ($draft) { |
| 261 | /* |
| 262 | * Set $default_charset to correspond with the user's selection |
| 263 | * of language interface. |
| 264 | */ |
| 265 | set_my_charset(); |
| 266 | $composeMessage=$compose_messages[$session]; |
| 267 | if (! deliverMessage($composeMessage, true)) { |
| 268 | showInputForm($session); |
| 269 | exit(); |
| 270 | } else { |
| 271 | unset($compose_messages[$session]); |
| 272 | $draft_message = _("Draft Email Saved"); |
| 273 | /* If this is a resumed draft, then delete the original */ |
| 274 | if(isset($delete_draft)) { |
| 275 | Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) . |
| 276 | "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes"); |
| 277 | exit(); |
| 278 | } |
| 279 | else { |
| 280 | if ($compose_new_win == '1') { |
| 281 | Header("Location: compose.php?saved_draft=yes&session=$composesession"); |
| 282 | exit(); |
| 283 | } |
| 284 | else { |
| 285 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
| 286 | "&startMessage=1¬e=".urlencode($draft_message)); |
| 287 | exit(); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if ($send) { |
| 294 | if (isset($_FILES['attachfile']) && |
| 295 | $_FILES['attachfile']['tmp_name'] && |
| 296 | $_FILES['attachfile']['tmp_name'] != 'none') { |
| 297 | $AttachFailure = saveAttachedFiles($session); |
| 298 | } |
| 299 | if (checkInput(false) && !isset($AttachFailure)) { |
| 300 | $urlMailbox = urlencode (trim($mailbox)); |
| 301 | if (! isset($passed_id)) { |
| 302 | $passed_id = 0; |
| 303 | } |
| 304 | /* |
| 305 | * Set $default_charset to correspond with the user's selection |
| 306 | * of language interface. |
| 307 | */ |
| 308 | set_my_charset(); |
| 309 | /* |
| 310 | * This is to change all newlines to \n |
| 311 | * We'll change them to \r\n later (in the sendMessage function) |
| 312 | */ |
| 313 | $body = str_replace("\r\n", "\n", $body); |
| 314 | $body = str_replace("\r", "\n", $body); |
| 315 | |
| 316 | /* |
| 317 | * Rewrap $body so that no line is bigger than $editor_size |
| 318 | * This should only really kick in the sqWordWrap function |
| 319 | * if the browser doesn't support "VIRTUAL" as the wrap type. |
| 320 | */ |
| 321 | $body = explode("\n", $body); |
| 322 | $newBody = ''; |
| 323 | foreach ($body as $line) { |
| 324 | if( $line <> '-- ' ) { |
| 325 | $line = rtrim($line); |
| 326 | } |
| 327 | if (strlen($line) <= $editor_size + 1) { |
| 328 | $newBody .= $line . "\n"; |
| 329 | } else { |
| 330 | sqWordWrap($line, $editor_size); |
| 331 | $newBody .= $line . "\n"; |
| 332 | } |
| 333 | } |
| 334 | $body = $newBody; |
| 335 | do_hook('compose_send'); |
| 336 | $composeMessage=$compose_messages[$session]; |
| 337 | |
| 338 | $Result = deliverMessage($composeMessage); |
| 339 | if (! $Result) { |
| 340 | showInputForm($session); |
| 341 | exit(); |
| 342 | } |
| 343 | unset($compose_messages[$session]); |
| 344 | if ( isset($delete_draft)) { |
| 345 | Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ). |
| 346 | "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes"); |
| 347 | exit(); |
| 348 | } |
| 349 | if ($compose_new_win == '1') { |
| 350 | |
| 351 | Header("Location: compose.php?mail_sent=yes"); |
| 352 | } |
| 353 | else { |
| 354 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
| 355 | "&startMessage=1"); |
| 356 | } |
| 357 | } else { |
| 358 | if ($compose_new_win == '1') { |
| 359 | compose_Header($color, $mailbox); |
| 360 | } |
| 361 | else { |
| 362 | displayPageHeader($color, $mailbox); |
| 363 | } |
| 364 | if (isset($AttachFailure)) { |
| 365 | plain_error_message(_("Could not move/copy file. File not attached"), |
| 366 | $color); |
| 367 | } |
| 368 | checkInput(true); |
| 369 | showInputForm($session); |
| 370 | /* sqimap_logout($imapConnection); */ |
| 371 | } |
| 372 | } elseif (isset($html_addr_search_done)) { |
| 373 | if ($compose_new_win == '1') { |
| 374 | compose_Header($color, $mailbox); |
| 375 | } |
| 376 | else { |
| 377 | displayPageHeader($color, $mailbox); |
| 378 | } |
| 379 | |
| 380 | if (isset($send_to_search) && is_array($send_to_search)) { |
| 381 | foreach ($send_to_search as $k => $v) { |
| 382 | if (substr($k, 0, 1) == 'T') { |
| 383 | if ($send_to) { |
| 384 | $send_to .= ', '; |
| 385 | } |
| 386 | $send_to .= $v; |
| 387 | } |
| 388 | elseif (substr($k, 0, 1) == 'C') { |
| 389 | if ($send_to_cc) { |
| 390 | $send_to_cc .= ', '; |
| 391 | } |
| 392 | $send_to_cc .= $v; |
| 393 | } |
| 394 | elseif (substr($k, 0, 1) == 'B') { |
| 395 | if ($send_to_bcc) { |
| 396 | $send_to_bcc .= ', '; |
| 397 | } |
| 398 | $send_to_bcc .= $v; |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | showInputForm($session); |
| 403 | } elseif (isset($html_addr_search)) { |
| 404 | if (isset($_FILES['attachfile']) && |
| 405 | $_FILES['attachfile']['tmp_name'] && |
| 406 | $_FILES['attachfile']['tmp_name'] != 'none') { |
| 407 | if(saveAttachedFiles($session)) { |
| 408 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 409 | } |
| 410 | } |
| 411 | /* |
| 412 | * I am using an include so as to elminiate an extra unnecessary |
| 413 | * click. If you can think of a better way, please implement it. |
| 414 | */ |
| 415 | include_once('./addrbook_search_html.php'); |
| 416 | } elseif (isset($attach)) { |
| 417 | if (saveAttachedFiles($session)) { |
| 418 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 419 | } |
| 420 | if ($compose_new_win == '1') { |
| 421 | compose_Header($color, $mailbox); |
| 422 | } |
| 423 | else { |
| 424 | displayPageHeader($color, $mailbox); |
| 425 | } |
| 426 | showInputForm($session); |
| 427 | } |
| 428 | elseif (isset($sigappend)) { |
| 429 | $idents = getPref($data_dir, $username, 'identities', 0); |
| 430 | if ($idents > 1) { |
| 431 | if ($identity == 'default') { |
| 432 | $no = 'g'; |
| 433 | } else { |
| 434 | $no = $identity; |
| 435 | } |
| 436 | $signature = getSig($data_dir, $username, $no); |
| 437 | } |
| 438 | $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; |
| 439 | if ($compose_new_win == '1') { |
| 440 | compose_Header($color, $mailbox); |
| 441 | } else { |
| 442 | displayPageHeader($color, $mailbox); |
| 443 | } |
| 444 | showInputForm($session); |
| 445 | } elseif (isset($do_delete)) { |
| 446 | if ($compose_new_win == '1') { |
| 447 | compose_Header($color, $mailbox); |
| 448 | } |
| 449 | else { |
| 450 | displayPageHeader($color, $mailbox); |
| 451 | } |
| 452 | |
| 453 | if (isset($delete) && is_array($delete)) { |
| 454 | $composeMessage = $compose_messages[$session]; |
| 455 | foreach($delete as $index) { |
| 456 | $attached_file = $composeMessage->entities[$index]->att_local_name; |
| 457 | unlink ($attached_file); |
| 458 | unset ($composeMessage->entities[$index]); |
| 459 | } |
| 460 | $new_entities = array(); |
| 461 | foreach ($composeMessage->entities as $entity) { |
| 462 | $new_entities[] = $entity; |
| 463 | } |
| 464 | $composeMessage->entities = $new_entities; |
| 465 | $compose_messages[$session] = $composeMessage; |
| 466 | sqsession_register($compose_messages, 'compose_messages'); |
| 467 | } |
| 468 | showInputForm($session); |
| 469 | } else { |
| 470 | /* |
| 471 | * This handles the default case as well as the error case |
| 472 | * (they had the same code) --> if (isset($smtpErrors)) |
| 473 | */ |
| 474 | |
| 475 | if ($compose_new_win == '1') { |
| 476 | compose_Header($color, $mailbox); |
| 477 | } else { |
| 478 | displayPageHeader($color, $mailbox); |
| 479 | } |
| 480 | |
| 481 | $newmail = true; |
| 482 | |
| 483 | if (!isset($passed_ent_id)) { |
| 484 | $passed_ent_id = ''; |
| 485 | } |
| 486 | if (!isset($passed_id)) { |
| 487 | $passed_id = ''; |
| 488 | } |
| 489 | if (!isset($mailbox)) { |
| 490 | $mailbox = ''; |
| 491 | } |
| 492 | if (!isset($action)) { |
| 493 | $action = ''; |
| 494 | } |
| 495 | |
| 496 | $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); |
| 497 | |
| 498 | /* in case the origin is not read_body.php */ |
| 499 | if (isset($send_to)) { |
| 500 | $values['send_to'] = $send_to; |
| 501 | } |
| 502 | if (isset($send_to_cc)) { |
| 503 | $values['send_to_cc'] = $send_to_cc; |
| 504 | } |
| 505 | if (isset($send_to_bcc)) { |
| 506 | $values['send_to_bcc'] = $send_to_bcc; |
| 507 | } |
| 508 | showInputForm($session, $values); |
| 509 | } |
| 510 | |
| 511 | exit(); |
| 512 | |
| 513 | /**************** Only function definitions go below *************/ |
| 514 | |
| 515 | |
| 516 | /* This function is used when not sending or adding attachments */ |
| 517 | function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { |
| 518 | global $editor_size, $default_use_priority, $body, |
| 519 | $use_signature, $composesession, $data_dir, $username, |
| 520 | $username, $key, $imapServerAddress, $imapPort, $compose_messages, |
| 521 | $composeMessage; |
| 522 | |
| 523 | $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; |
| 524 | $mailprio = 3; |
| 525 | |
| 526 | if ($passed_id) { |
| 527 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 528 | $imapPort, 0); |
| 529 | |
| 530 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 531 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 532 | |
| 533 | $body = ''; |
| 534 | if ($passed_ent_id) { |
| 535 | /* redefine the messsage in case of message/rfc822 */ |
| 536 | $message = $message->getEntity($passed_ent_id); |
| 537 | /* message is an entity which contains the envelope and type0=message |
| 538 | * and type1=rfc822. The actual entities are childs from |
| 539 | * $message->entities[0]. That's where the encoding and is located |
| 540 | */ |
| 541 | |
| 542 | $entities = $message->entities[0]->findDisplayEntity |
| 543 | (array(), $alt_order = array('text/plain')); |
| 544 | if (!count($entities)) { |
| 545 | $entities = $message->entities[0]->findDisplayEntity |
| 546 | (array(), $alt_order = array('text/plain','html/plain')); |
| 547 | } |
| 548 | $orig_header = $message->rfc822_header; /* here is the envelope located */ |
| 549 | /* redefine the message for picking up the attachments */ |
| 550 | $message = $message->entities[0]; |
| 551 | |
| 552 | } else { |
| 553 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); |
| 554 | if (!count($entities)) { |
| 555 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); |
| 556 | } |
| 557 | $orig_header = $message->rfc822_header; |
| 558 | } |
| 559 | |
| 560 | $encoding = $message->header->encoding; |
| 561 | $type0 = $message->type0; |
| 562 | $type1 = $message->type1; |
| 563 | foreach ($entities as $ent) { |
| 564 | $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); |
| 565 | $body_part_entity = $message->getEntity($ent); |
| 566 | $bodypart = decodeBody($unencoded_bodypart, |
| 567 | $body_part_entity->header->encoding); |
| 568 | if ($type1 == 'html') { |
| 569 | $bodypart = strip_tags($bodypart); |
| 570 | } |
| 571 | $body .= $bodypart; |
| 572 | } |
| 573 | if ($default_use_priority) { |
| 574 | $mailprio = substr($orig_header->priority,0,1); |
| 575 | if (!$mailprio) { |
| 576 | $mailprio = 3; |
| 577 | } |
| 578 | } else { |
| 579 | $mailprio = ''; |
| 580 | } |
| 581 | //ClearAttachments($session); |
| 582 | |
| 583 | $identity = ''; |
| 584 | $idents = getPref($data_dir, $username, 'identities'); |
| 585 | $from_o = $orig_header->from; |
| 586 | if (is_object($from_o)) { |
| 587 | $orig_from = $from_o->getAddress(); |
| 588 | } else { |
| 589 | $orig_from = ''; |
| 590 | } |
| 591 | $identities = array(); |
| 592 | if (!empty($idents) && $idents > 1) { |
| 593 | $identities[] = '"'. getPref($data_dir, $username, 'full_name') |
| 594 | . '" <' . getPref($data_dir, $username, 'email_address') . '>'; |
| 595 | for ($i = 1; $i < $idents; $i++) { |
| 596 | $enc_from_name = '"'. |
| 597 | getPref($data_dir, $username, 'full_name' . $i) . |
| 598 | '" <' . |
| 599 | getPref($data_dir, $username, 'email_address' . $i) . '>'; |
| 600 | if ($enc_from_name == $orig_from && $i) { |
| 601 | $identity = $i; |
| 602 | break; |
| 603 | } |
| 604 | $identities[] = $enc_from_name; |
| 605 | } |
| 606 | $identity_match = $orig_header->findAddress($identities); |
| 607 | if ($identity_match) { |
| 608 | $identity = $identity_match; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | switch ($action) { |
| 613 | case ('draft'): |
| 614 | $use_signature = FALSE; |
| 615 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
| 616 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
| 617 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
| 618 | $subject = decodeHeader($orig_header->subject); |
| 619 | |
| 620 | $body_ary = explode("\n", $body); |
| 621 | $cnt = count($body_ary) ; |
| 622 | $body = ''; |
| 623 | for ($i=0; $i < $cnt; $i++) { |
| 624 | if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { |
| 625 | sqWordWrap($body_ary[$i], $editor_size ); |
| 626 | $body .= $body_ary[$i] . "\n"; |
| 627 | } |
| 628 | unset($body_ary[$i]); |
| 629 | } |
| 630 | sqUnWordWrap($body); |
| 631 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
| 632 | break; |
| 633 | case ('edit_as_new'): |
| 634 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
| 635 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
| 636 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
| 637 | $subject = decodeHeader($orig_header->subject); |
| 638 | $mailprio = $orig_header->priority; |
| 639 | $orig_from = ''; |
| 640 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
| 641 | sqUnWordWrap($body); |
| 642 | break; |
| 643 | case ('forward'): |
| 644 | $send_to = ''; |
| 645 | $subject = decodeHeader($orig_header->subject); |
| 646 | if ((substr(strtolower($subject), 0, 4) != 'fwd:') && |
| 647 | (substr(strtolower($subject), 0, 5) != '[fwd:') && |
| 648 | (substr(strtolower($subject), 0, 6) != '[ fwd:')) { |
| 649 | $subject = '[Fwd: ' . $subject . ']'; |
| 650 | } |
| 651 | $body = getforwardHeader($orig_header) . $body; |
| 652 | sqUnWordWrap($body); |
| 653 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
| 654 | $body = "\n" . $body; |
| 655 | break; |
| 656 | case ('forward_as_attachment'): |
| 657 | $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); |
| 658 | $body = ''; |
| 659 | break; |
| 660 | case ('reply_all'): |
| 661 | $send_to_cc = replyAllString($orig_header); |
| 662 | case ('reply'): |
| 663 | $send_to = $orig_header->reply_to; |
| 664 | if (is_object($send_to)) { |
| 665 | $send_to = decodeHeader($send_to->getAddr_s('reply_to')); |
| 666 | } else { |
| 667 | $send_to = decodeHeader($orig_header->getAddr_s('from')); |
| 668 | } |
| 669 | $subject = decodeHeader($orig_header->subject); |
| 670 | $subject = str_replace('"', "'", $subject); |
| 671 | $subject = trim($subject); |
| 672 | if (substr(strtolower($subject), 0, 3) != 're:') { |
| 673 | $subject = 'Re: ' . $subject; |
| 674 | } |
| 675 | /* this corrects some wrapping/quoting problems on replies */ |
| 676 | $rewrap_body = explode("\n", $body); |
| 677 | $from = (is_array($orig_header->from)) ? |
| 678 | $orig_header->from[0] : $orig_header->from; |
| 679 | $body = getReplyCitation($from->getAddress(false)); |
| 680 | sqUnWordWrap($body); |
| 681 | $cnt = count($rewrap_body); |
| 682 | for ($i=0;$i<$cnt;$i++) { |
| 683 | sqWordWrap($rewrap_body[$i], ($editor_size)); |
| 684 | if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { |
| 685 | $gt = $matches[1]; |
| 686 | $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n"; |
| 687 | } else { |
| 688 | $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n"; |
| 689 | } |
| 690 | unset($rewrap_body[$i]); |
| 691 | } |
| 692 | $composeMessage->reply_rfc822_header = $orig_header; |
| 693 | break; |
| 694 | default: |
| 695 | break; |
| 696 | } |
| 697 | $compose_messages[$session] = $composeMessage; |
| 698 | sqsession_register($compose_messages, 'compose_messages'); |
| 699 | session_write_close(); |
| 700 | sqimap_logout($imapConnection); |
| 701 | } |
| 702 | $ret = array( 'send_to' => $send_to, |
| 703 | 'send_to_cc' => $send_to_cc, |
| 704 | 'send_to_bcc' => $send_to_bcc, |
| 705 | 'subject' => $subject, |
| 706 | 'mailprio' => $mailprio, |
| 707 | 'body' => $body, |
| 708 | 'identity' => $identity ); |
| 709 | |
| 710 | return ($ret); |
| 711 | } /* function newMail() */ |
| 712 | |
| 713 | function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) { |
| 714 | global $attachment_dir, $username, $data_dir, $squirrelmail_language; |
| 715 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 716 | if (!count($message->entities) || |
| 717 | ($message->type0 == 'message' && $message->type1 == 'rfc822')) { |
| 718 | if ( !in_array($message->entity_id, $entities) && $message->entity_id) { |
| 719 | switch ($message->type0) { |
| 720 | case 'message': |
| 721 | if ($message->type1 == 'rfc822') { |
| 722 | $filename = decodeHeader($message->rfc822_header->subject.'.eml'); |
| 723 | if ($filename == "") { |
| 724 | $filename = "untitled-".$message->entity_id.'.eml'; |
| 725 | } |
| 726 | } else { |
| 727 | $filename = decodeHeader($message->getFilename()); |
| 728 | } |
| 729 | break; |
| 730 | default: |
| 731 | $filename = decodeHeader($message->getFilename()); |
| 732 | break; |
| 733 | } |
| 734 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
| 735 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
| 736 | $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename); |
| 737 | } |
| 738 | |
| 739 | $localfilename = GenerateRandomString(32, '', 7); |
| 740 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 741 | while (file_exists($full_localfilename)) { |
| 742 | $localfilename = GenerateRandomString(32, '', 7); |
| 743 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 744 | } |
| 745 | $message->att_local_name = $full_localfilename; |
| 746 | if (!$message->mime_header) { /* temporary hack */ |
| 747 | $message->mime_header = $message->header; |
| 748 | } |
| 749 | |
| 750 | $composeMessage->addEntity($message); |
| 751 | |
| 752 | /* Write Attachment to file */ |
| 753 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb'); |
| 754 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
| 755 | $passed_id, $message->entity_id), |
| 756 | $message->header->encoding)); |
| 757 | fclose ($fp); |
| 758 | } |
| 759 | } else { |
| 760 | for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) { |
| 761 | $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection); |
| 762 | } |
| 763 | } |
| 764 | // setPref($data_dir, $username, 'attachments', serialize($attachments)); |
| 765 | return $composeMessage; |
| 766 | } |
| 767 | |
| 768 | function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
| 769 | $passed_ent_id='', $imapConnection) { |
| 770 | global $attachments, $attachment_dir, $username, $data_dir, $uid_support; |
| 771 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 772 | if (!$passed_ent_id) { |
| 773 | $body_a = sqimap_run_command($imapConnection, |
| 774 | 'FETCH '.$passed_id.' RFC822', |
| 775 | TRUE, $response, $readmessage, |
| 776 | $uid_support); |
| 777 | } else { |
| 778 | $body_a = sqimap_run_command($imapConnection, |
| 779 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
| 780 | TRUE, $response, $readmessage, $uid_support); |
| 781 | $message = $message->parent; |
| 782 | } |
| 783 | if ($response = 'OK') { |
| 784 | $subject = encodeHeader($message->rfc822_header->subject); |
| 785 | array_shift($body_a); |
| 786 | $body = implode('', $body_a) . "\r\n"; |
| 787 | |
| 788 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
| 789 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 790 | |
| 791 | $fp = fopen( $full_localfilename, 'w'); |
| 792 | fwrite ($fp, $body); |
| 793 | fclose($fp); |
| 794 | $composeMessage->initAttachment('message/rfc822',$subject.'.eml', |
| 795 | $full_localfilename); |
| 796 | } |
| 797 | return $composeMessage; |
| 798 | } |
| 799 | |
| 800 | function showInputForm ($session, $values=false) { |
| 801 | global $send_to, $send_to_cc, $body, |
| 802 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
| 803 | $editor_size, $attachments, $subject, $newmail, |
| 804 | $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox, |
| 805 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
| 806 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
| 807 | $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win, |
| 808 | $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action, |
| 809 | $username, $compose_messages, $composesession; |
| 810 | |
| 811 | $composeMessage = $compose_messages[$session]; |
| 812 | |
| 813 | $subject = decodeHeader($subject, false); |
| 814 | if ($values) { |
| 815 | $send_to = $values['send_to']; |
| 816 | $send_to_cc = $values['send_to_cc']; |
| 817 | $send_to_bcc = $values['send_to_bcc']; |
| 818 | $subject = $values['subject']; |
| 819 | $mailprio = $values['mailprio']; |
| 820 | $body = $values['body']; |
| 821 | $identity = $values['identity']; |
| 822 | } |
| 823 | |
| 824 | if ($use_javascript_addr_book) { |
| 825 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
| 826 | 'function open_abook() { ' . "\n" . |
| 827 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
| 828 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
| 829 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
| 830 | ' nwin.opener = document.windows;' . "\n" . |
| 831 | "}\n" . |
| 832 | '// --></SCRIPT>' . "\n\n"; |
| 833 | } |
| 834 | |
| 835 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
| 836 | 'ENCTYPE="multipart/form-data"'; |
| 837 | do_hook("compose_form"); |
| 838 | |
| 839 | echo ">\n"; |
| 840 | |
| 841 | if ($action == 'draft') { |
| 842 | echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n"; |
| 843 | } |
| 844 | if (isset($delete_draft)) { |
| 845 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
| 846 | } |
| 847 | if (isset($session)) { |
| 848 | echo '<input type="hidden" name="session" value="' . $session . "\">\n"; |
| 849 | } |
| 850 | |
| 851 | if (isset($passed_id)) { |
| 852 | echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n"; |
| 853 | } |
| 854 | |
| 855 | if ($saved_draft == 'yes') { |
| 856 | echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>'; |
| 857 | } |
| 858 | if ($mail_sent == 'yes') { |
| 859 | echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>'; |
| 860 | } |
| 861 | echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
| 862 | if ($compose_new_win == '1') { |
| 863 | echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" . |
| 864 | ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n"; |
| 865 | } |
| 866 | if ($location_of_buttons == 'top') { |
| 867 | showComposeButtonRow(); |
| 868 | } |
| 869 | |
| 870 | $idents = getPref($data_dir, $username, 'identities', 0); |
| 871 | if ($idents > 1) { |
| 872 | echo ' <TR>' . "\n" . |
| 873 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
| 874 | _("From:") . '</TD>' . "\n" . |
| 875 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 876 | ' <select name=identity>' . "\n" . |
| 877 | ' <option value=default>' . |
| 878 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
| 879 | $em = getPref($data_dir, $username, 'email_address'); |
| 880 | if ($em != '') { |
| 881 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 882 | } |
| 883 | for ($i = 1; $i < $idents; $i ++) { |
| 884 | echo '<option value="' . $i . '"'; |
| 885 | if (isset($identity) && $identity == $i) { |
| 886 | echo ' SELECTED'; |
| 887 | } |
| 888 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
| 889 | 'full_name' . $i)); |
| 890 | $em = getPref($data_dir, $username, 'email_address' . $i); |
| 891 | if ($em != '') { |
| 892 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 893 | } |
| 894 | echo '</option>'; |
| 895 | } |
| 896 | echo '</select>' . "\n" . |
| 897 | ' </TD>' . "\n" . |
| 898 | ' </TR>' . "\n"; |
| 899 | } |
| 900 | echo ' <TR>' . "\n" . |
| 901 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
| 902 | _("To:") . '</TD>' . "\n" . |
| 903 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 904 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
| 905 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
| 906 | ' </TD>' . "\n" . |
| 907 | ' </TR>' . "\n" . |
| 908 | ' <TR>' . "\n" . |
| 909 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
| 910 | _("CC:") . '</TD>' . "\n" . |
| 911 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 912 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
| 913 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
| 914 | ' </TD>' . "\n" . |
| 915 | ' </TR>' . "\n" . |
| 916 | ' <TR>' . "\n" . |
| 917 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
| 918 | _("BCC:") . '</TD>' . "\n" . |
| 919 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 920 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
| 921 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
| 922 | ' </TD>' . "\n" . |
| 923 | ' </TR>' . "\n" . |
| 924 | ' <TR>' . "\n" . |
| 925 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
| 926 | _("Subject:") . '</TD>' . "\n" . |
| 927 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
| 928 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
| 929 | htmlspecialchars($subject) . '">' . "\n" . |
| 930 | ' </TD>' . "\n" . |
| 931 | ' </TR>' . "\n\n"; |
| 932 | |
| 933 | if ($location_of_buttons == 'between') { |
| 934 | showComposeButtonRow(); |
| 935 | } |
| 936 | |
| 937 | if ($compose_new_win == '1') { |
| 938 | echo ' <TR>' . "\n" . |
| 939 | ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" . |
| 940 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
| 941 | $editor_size . '" WRAP="VIRTUAL">'; |
| 942 | } |
| 943 | else { |
| 944 | echo ' <TR>' . "\n" . |
| 945 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
| 946 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
| 947 | $editor_size . '" WRAP="VIRTUAL">'; |
| 948 | } |
| 949 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
| 950 | if ($sig_first == '1') { |
| 951 | if ($charset == 'iso-2022-jp') { |
| 952 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
| 953 | } else { |
| 954 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
| 955 | } |
| 956 | echo "\n\n".htmlspecialchars($body); |
| 957 | } |
| 958 | else { |
| 959 | echo "\n\n".htmlspecialchars($body); |
| 960 | if ($charset == 'iso-2022-jp') { |
| 961 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
| 962 | }else{ |
| 963 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | else { |
| 968 | echo htmlspecialchars($body); |
| 969 | } |
| 970 | echo '</TEXTAREA><BR>' . "\n" . |
| 971 | ' </TD>' . "\n" . |
| 972 | ' </TR>' . "\n"; |
| 973 | |
| 974 | if ($location_of_buttons == 'bottom') { |
| 975 | showComposeButtonRow(); |
| 976 | } else { |
| 977 | echo ' <TR>' . "\n" . |
| 978 | ' <TD COLSPAN=2 ALIGN=RIGHT>' . "\n" . |
| 979 | ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . "\n" . |
| 980 | ' <BR><BR>' . "\n" . |
| 981 | ' </TD>' . "\n" . |
| 982 | ' </TR>' . "\n"; |
| 983 | } |
| 984 | |
| 985 | /* This code is for attachments */ |
| 986 | echo ' <TR>' . "\n" . |
| 987 | ' <TD COLSPAN=2>' . "\n" . |
| 988 | ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'. |
| 989 | ' border="0" bgcolor="'.$color[9].'">' . "\n" . |
| 990 | ' <TR>' . "\n" . |
| 991 | ' <TD>' . "\n" . |
| 992 | ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
| 993 | ' border="0">' . "\n" . |
| 994 | ' <TR>' . "\n" . |
| 995 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . |
| 996 | _("Attach:") . '</TD>' . "\n" . |
| 997 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
| 998 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
| 999 | ' <input type="submit" name="attach"' . |
| 1000 | ' value="' . _("Add") .'">' . "\n" . |
| 1001 | ' </TD>' . "\n" . |
| 1002 | ' </TR>' . "\n"; |
| 1003 | |
| 1004 | |
| 1005 | $s_a = array(); |
| 1006 | if ($composeMessage->entities) { |
| 1007 | foreach ($composeMessage->entities as $key => $attachment) { |
| 1008 | $attached_file = $attachment->att_local_name; |
| 1009 | if ($attachment->att_local_name || $attachment->body_part) { |
| 1010 | $attached_filename = decodeHeader($attachment->mime_header->getParameter('name')); |
| 1011 | $type = $attachment->mime_header->type0.'/'. |
| 1012 | $attachment->mime_header->type1; |
| 1013 | $s_a[] = '<input type="checkbox" name="delete[]" value="' . |
| 1014 | $key . "\">\n" . $attached_filename . ' - ' . $type . |
| 1015 | ' ('.show_readable_size( filesize( $attached_file ) ) |
| 1016 | . ')<br>'."\n"; |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | if (count($s_a)) { |
| 1021 | foreach ($s_a as $s) { |
| 1022 | echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>'; |
| 1023 | } |
| 1024 | echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' . |
| 1025 | _("Delete selected attachments") . "\">\n" . |
| 1026 | '</td></tr>'; |
| 1027 | } |
| 1028 | echo ' </table>' . "\n" . |
| 1029 | ' </td>' . "\n" . |
| 1030 | ' </tr>' . "\n" . |
| 1031 | ' </TABLE>' . "\n" . |
| 1032 | ' </TD>' . "\n" . |
| 1033 | ' </TR>' . "\n"; |
| 1034 | |
| 1035 | /* End of attachment code */ |
| 1036 | if ($compose_new_win == '1') { |
| 1037 | echo '</TABLE>'."\n"; |
| 1038 | } |
| 1039 | echo '</TABLE>' . "\n" . |
| 1040 | '<input type="hidden" name="username" value="'. $username . "\">\n" . |
| 1041 | '<input type=hidden name=action value="' . $action . "\">\n" . |
| 1042 | '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
| 1043 | "\">\n"; |
| 1044 | /* |
| 1045 | store the complete ComposeMessages array in a hidden input value |
| 1046 | so we can restore them in case of a session timeout. |
| 1047 | */ |
| 1048 | echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n"; |
| 1049 | echo '<input type=hidden name=composesession value="' . $composesession . "\">\n"; |
| 1050 | echo '<input type=hidden name=querystring value="' . $_SERVER['QUERY_STRING'] . "\">\n"; |
| 1051 | echo '</FORM>'; |
| 1052 | do_hook('compose_bottom'); |
| 1053 | echo '</BODY></HTML>' . "\n"; |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | function showComposeButtonRow() { |
| 1058 | global $use_javascript_addr_book, $save_as_draft, |
| 1059 | $default_use_priority, $mailprio, $default_use_mdn, |
| 1060 | $request_mdn, $request_dr, |
| 1061 | $data_dir, $username; |
| 1062 | |
| 1063 | echo ' <TR>' . "\n" . |
| 1064 | ' <TD></TD>' . "\n" . |
| 1065 | ' <TD>' . "\n"; |
| 1066 | if ($default_use_priority) { |
| 1067 | if(!isset($mailprio)) { |
| 1068 | $mailprio = "3"; |
| 1069 | } |
| 1070 | echo ' ' . _("Priority") .': <select name="mailprio">'. |
| 1071 | '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
| 1072 | '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
| 1073 | '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
| 1074 | '</select>' . "\n"; |
| 1075 | } |
| 1076 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
| 1077 | if ($default_use_mdn) { |
| 1078 | if ($mdn_user_support) { |
| 1079 | echo ' ' . _("Receipt") .': '. |
| 1080 | '<input type="checkbox" name="request_mdn" value=1'. |
| 1081 | ($request_mdn=='1'?' checked':'') .'>'. _("On Read"). |
| 1082 | ' <input type="checkbox" name="request_dr" value=1'. |
| 1083 | ($request_dr=='1'?' checked':'') .'>'. _("On Delivery"); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | echo ' </TD>' . "\n" . |
| 1088 | ' </TR>' . "\n" . |
| 1089 | ' <TR>' . "\n" . |
| 1090 | ' <TD></TD>' . "\n" . |
| 1091 | ' <TD>' . "\n" . |
| 1092 | ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n"; |
| 1093 | if ($use_javascript_addr_book) { |
| 1094 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"". |
| 1095 | " <input type=button value=\\\""._("Addresses"). |
| 1096 | "\\\" onclick='javascript:open_abook();'>\");". |
| 1097 | " // --></SCRIPT><NOSCRIPT>\n". |
| 1098 | " <input type=submit name=\"html_addr_search\" value=\"". |
| 1099 | _("Addresses")."\">". |
| 1100 | " </NOSCRIPT>\n"; |
| 1101 | } else { |
| 1102 | echo ' <input type=submit name="html_addr_search" value="'. |
| 1103 | _("Addresses").'">' . "\n"; |
| 1104 | } |
| 1105 | |
| 1106 | if ($save_as_draft) { |
| 1107 | echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
| 1108 | } |
| 1109 | |
| 1110 | echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n"; |
| 1111 | do_hook('compose_button_row'); |
| 1112 | |
| 1113 | echo ' </TD>' . "\n" . |
| 1114 | ' </TR>' . "\n\n"; |
| 1115 | } |
| 1116 | |
| 1117 | function checkInput ($show) { |
| 1118 | /* |
| 1119 | * I implemented the $show variable because the error messages |
| 1120 | * were getting sent before the page header. So, I check once |
| 1121 | * using $show=false, and then when i'm ready to display the error |
| 1122 | * message, show=true |
| 1123 | */ |
| 1124 | global $body, $send_to, $send_to_bcc, $subject, $color; |
| 1125 | |
| 1126 | if ($send_to == '' && $send_to_bcc == '') { |
| 1127 | if ($show) { |
| 1128 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
| 1129 | } |
| 1130 | return false; |
| 1131 | } |
| 1132 | return true; |
| 1133 | } /* function checkInput() */ |
| 1134 | |
| 1135 | |
| 1136 | /* True if FAILURE */ |
| 1137 | function saveAttachedFiles($session) { |
| 1138 | global $_FILES, $attachment_dir, $attachments, $username, |
| 1139 | $data_dir, $compose_messages; |
| 1140 | |
| 1141 | /* get out of here if no file was attached at all */ |
| 1142 | if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) { |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
| 1146 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 1147 | $localfilename = GenerateRandomString(32, '', 7); |
| 1148 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 1149 | while (file_exists($full_localfilename)) { |
| 1150 | $localfilename = GenerateRandomString(32, '', 7); |
| 1151 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 1152 | } |
| 1153 | |
| 1154 | if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 1155 | if (function_exists("move_uploaded_file")) { |
| 1156 | if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) { |
| 1157 | return true; |
| 1158 | } |
| 1159 | } else { |
| 1160 | if (!@copy($_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 1161 | return true; |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | $message = $compose_messages[$session]; |
| 1166 | $type = strtolower($_FILES['attachfile']['type']); |
| 1167 | $name = $_FILES['attachfile']['name']; |
| 1168 | $message->initAttachment($type, $name, $full_localfilename); |
| 1169 | $compose_messages[$session] = $message; |
| 1170 | } |
| 1171 | |
| 1172 | function ClearAttachments($composeMessage) { |
| 1173 | if ($composeMessage->att_local_name) { |
| 1174 | $attached_file = $composeMessage->att_local_name; |
| 1175 | if (file_exists($attached_file)) { |
| 1176 | unlink($attached_file); |
| 1177 | } |
| 1178 | } |
| 1179 | for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) { |
| 1180 | ClearAttachments($composeMessage->entities[$i]); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | function getReplyCitation($orig_from) { |
| 1187 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
| 1188 | |
| 1189 | /* First, return an empty string when no citation style selected. */ |
| 1190 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
| 1191 | return ''; |
| 1192 | } |
| 1193 | |
| 1194 | /* Make sure our final value isn't an empty string. */ |
| 1195 | if ($orig_from == '') { |
| 1196 | return ''; |
| 1197 | } |
| 1198 | |
| 1199 | /* Otherwise, try to select the desired citation style. */ |
| 1200 | switch ($reply_citation_style) { |
| 1201 | case 'author_said': |
| 1202 | $start = ''; |
| 1203 | $end = ' ' . _("said") . ':'; |
| 1204 | break; |
| 1205 | case 'quote_who': |
| 1206 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
| 1207 | $end = '">'; |
| 1208 | break; |
| 1209 | case 'user-defined': |
| 1210 | $start = $reply_citation_start . |
| 1211 | ($reply_citation_start == '' ? '' : ' '); |
| 1212 | $end = $reply_citation_end; |
| 1213 | break; |
| 1214 | default: |
| 1215 | return ''; |
| 1216 | } |
| 1217 | |
| 1218 | /* Build and return the citation string. */ |
| 1219 | return ($start . $orig_from . $end . "\n"); |
| 1220 | } |
| 1221 | |
| 1222 | /* temporary function to make use of the deliver class. |
| 1223 | In the future the responsable backend should be automaticly loaded |
| 1224 | and conf.pl should show a list of available backends. |
| 1225 | The message also should be constructed by the message class. |
| 1226 | */ |
| 1227 | |
| 1228 | function deliverMessage($composeMessage, $draft=false) { |
| 1229 | global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, |
| 1230 | $username, $popuser, $usernamedata, $identity, $data_dir, |
| 1231 | $request_mdn, $request_dr, $default_charset, $color, $useSendmail, |
| 1232 | $domain, $action; |
| 1233 | global $imapServerAddress, $imapPort, $sent_folder, $key; |
| 1234 | |
| 1235 | $rfc822_header = $composeMessage->rfc822_header; |
| 1236 | $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain); |
| 1237 | $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain); |
| 1238 | $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain); |
| 1239 | $rfc822_header->priority = $mailprio; |
| 1240 | $rfc822_header->subject = $subject; |
| 1241 | $special_encoding=''; |
| 1242 | if (strtolower($default_charset) == 'iso-2022-jp') { |
| 1243 | if (mb_detect_encoding($body) == 'ASCII') { |
| 1244 | $special_encoding = '8bit'; |
| 1245 | } else { |
| 1246 | $body = mb_convert_encoding($body, 'JIS'); |
| 1247 | $special_encoding = '7bit'; |
| 1248 | } |
| 1249 | } |
| 1250 | $composeMessage->setBody($body); |
| 1251 | |
| 1252 | if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { |
| 1253 | $popuser = $usernamedata[1]; |
| 1254 | $domain = $usernamedata[2]; |
| 1255 | unset($usernamedata); |
| 1256 | } else { |
| 1257 | $popuser = $username; |
| 1258 | } |
| 1259 | $reply_to = ''; |
| 1260 | if (isset($identity) && $identity != 'default') { |
| 1261 | $from_mail = getPref($data_dir, $username,'email_address' . $identity); |
| 1262 | $full_name = getPref($data_dir, $username,'full_name' . $identity); |
| 1263 | $reply_to = getPref($data_dir, $username,'reply_to' . $identity); |
| 1264 | } else { |
| 1265 | $from_mail = getPref($data_dir, $username, 'email_address'); |
| 1266 | $full_name = getPref($data_dir, $username, 'full_name'); |
| 1267 | $reply_to = getPref($data_dir, $username,'reply_to'); |
| 1268 | } |
| 1269 | if (!$from_mail) { |
| 1270 | $from_mail = "$popuser@$domain"; |
| 1271 | $full_name = ''; |
| 1272 | } |
| 1273 | $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); |
| 1274 | if ($full_name) { |
| 1275 | $from = $rfc822_header->from[0]; |
| 1276 | if (!$from->host) $from->host = $domain; |
| 1277 | $from_addr = $full_name .' <'.$from->mailbox.'@'.$from->host.'>'; |
| 1278 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
| 1279 | } |
| 1280 | if ($reply_to) { |
| 1281 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
| 1282 | } |
| 1283 | /* Receipt: On Read */ |
| 1284 | if (isset($request_mdn) && $request_mdn) { |
| 1285 | $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); |
| 1286 | } |
| 1287 | /* Receipt: On Delivery */ |
| 1288 | if (isset($request_dr) && $request_dr) { |
| 1289 | $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; |
| 1290 | } |
| 1291 | /* multipart messages */ |
| 1292 | if (count($composeMessage->entities)) { |
| 1293 | $message_body = new Message(); |
| 1294 | $message_body->body_part = $composeMessage->body_part; |
| 1295 | $composeMessage->body_part = ''; |
| 1296 | $mime_header = new MessageHeader; |
| 1297 | $mime_header->type0 = 'text'; |
| 1298 | $mime_header->type1 = 'plain'; |
| 1299 | if ($special_encoding) { |
| 1300 | $mime_header->encoding = $special_encoding; |
| 1301 | } else { |
| 1302 | $mime_header->encoding = 'us-ascii'; |
| 1303 | } |
| 1304 | if ($default_charset) { |
| 1305 | $mime_header->parameters['charset'] = $default_charset; |
| 1306 | } |
| 1307 | $message_body->mime_header = $mime_header; |
| 1308 | array_unshift($composeMessage->entities, $message_body); |
| 1309 | $content_type = new ContentType('multipart/mixed'); |
| 1310 | } else { |
| 1311 | $content_type = new ContentType('text/plain'); |
| 1312 | } |
| 1313 | if ($default_charset) { |
| 1314 | $content_type->properties['charset']=$default_charset; |
| 1315 | } |
| 1316 | |
| 1317 | $rfc822_header->content_type = $content_type; |
| 1318 | $composeMessage->rfc822_header = $rfc822_header; |
| 1319 | |
| 1320 | if (!$useSendmail && !$draft) { |
| 1321 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
| 1322 | $deliver = new Deliver_SMTP(); |
| 1323 | global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp; |
| 1324 | if ($use_authenticated_smtp) { |
| 1325 | global $key, $onetimepad; |
| 1326 | $user = $username; |
| 1327 | $pass = OneTimePadDecrypt($key, $onetimepad); |
| 1328 | } else { |
| 1329 | $user = ''; |
| 1330 | $pass = ''; |
| 1331 | } |
| 1332 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
| 1333 | $stream = $deliver->initStream($composeMessage,$domain,0, |
| 1334 | $smtpServerAddress, $smtpPort, $authPop); |
| 1335 | } elseif (!$draft) { |
| 1336 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
| 1337 | global $sendmail_path; |
| 1338 | $deliver = new Deliver_SendMail(); |
| 1339 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
| 1340 | } elseif ($draft) { |
| 1341 | global $draft_folder; |
| 1342 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
| 1343 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
| 1344 | $imapPort, 0); |
| 1345 | if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { |
| 1346 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
| 1347 | $imap_deliver = new Deliver_IMAP(); |
| 1348 | $length = $imap_deliver->mail($composeMessage); |
| 1349 | sqimap_append ($imap_stream, $draft_folder, $length); |
| 1350 | $imap_deliver->mail($composeMessage, $imap_stream); |
| 1351 | sqimap_append_done ($imap_stream); |
| 1352 | sqimap_logout($imap_stream); |
| 1353 | unset ($imap_deliver); |
| 1354 | return $length; |
| 1355 | } else { |
| 1356 | $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.'; |
| 1357 | plain_error_message($msg, $color); |
| 1358 | return false; |
| 1359 | } |
| 1360 | } |
| 1361 | $succes = false; |
| 1362 | if ($stream) { |
| 1363 | $length = $deliver->mail($composeMessage, $stream); |
| 1364 | $succes = $deliver->finalizeStream($stream); |
| 1365 | } |
| 1366 | if (!$succes) { |
| 1367 | $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr; |
| 1368 | plain_error_message($msg, $color); |
| 1369 | } else { |
| 1370 | unset ($deliver); |
| 1371 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
| 1372 | $imapPort, 0); |
| 1373 | if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) { |
| 1374 | sqimap_append ($imap_stream, $sent_folder, $length); |
| 1375 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
| 1376 | $imap_deliver = new Deliver_IMAP(); |
| 1377 | $imap_deliver->mail($composeMessage, $imap_stream); |
| 1378 | sqimap_append_done ($imap_stream); |
| 1379 | unset ($imap_deliver); |
| 1380 | } |
| 1381 | global $passed_id, $mailbox, $action; |
| 1382 | ClearAttachments($composeMessage); |
| 1383 | if ($action == 'reply' || $action == 'reply_all') { |
| 1384 | sqimap_mailbox_select ($imap_stream, $mailbox); |
| 1385 | sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true); |
| 1386 | } |
| 1387 | sqimap_logout($imap_stream); |
| 1388 | } |
| 1389 | return $succes; |
| 1390 | } |
| 1391 | |
| 1392 | ?> |