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