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