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