| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * read_body.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This file is used for reading the msgs array and displaying |
| 10 | * the resulting emails in the right frame. |
| 11 | * |
| 12 | * $Id$ |
| 13 | */ |
| 14 | |
| 15 | /* Path for SquirrelMail required files. */ |
| 16 | define('SM_PATH','../'); |
| 17 | |
| 18 | /* SquirrelMail required files. */ |
| 19 | require_once(SM_PATH . 'include/validate.php'); |
| 20 | require_once(SM_PATH . 'functions/global.php'); |
| 21 | require_once(SM_PATH . 'functions/imap.php'); |
| 22 | require_once(SM_PATH . 'functions/mime.php'); |
| 23 | require_once(SM_PATH . 'functions/date.php'); |
| 24 | require_once(SM_PATH . 'functions/url_parser.php'); |
| 25 | require_once(SM_PATH . 'functions/html.php'); |
| 26 | require_once(SM_PATH . 'functions/global.php'); |
| 27 | require_once(SM_PATH . 'functions/identity.php'); |
| 28 | |
| 29 | /** |
| 30 | * Given an IMAP message id number, this will look it up in the cached |
| 31 | * and sorted msgs array and return the index. Used for finding the next |
| 32 | * and previous messages. |
| 33 | * |
| 34 | * @return the index of the next valid message from the array |
| 35 | */ |
| 36 | function findNextMessage($passed_id) { |
| 37 | global $msort, $msgs, $sort, |
| 38 | $thread_sort_messages, $allow_server_sort, |
| 39 | $server_sort_array; |
| 40 | if (!is_array($server_sort_array)) { |
| 41 | $thread_sort_messages = 0; |
| 42 | $allow_server_sort = FALSE; |
| 43 | } |
| 44 | $result = -1; |
| 45 | if ($thread_sort_messages || $allow_server_sort) { |
| 46 | $count = count($server_sort_array) - 1; |
| 47 | foreach($server_sort_array as $key=>$value) { |
| 48 | if ($passed_id == $value) { |
| 49 | if ($key == $count) { |
| 50 | break; |
| 51 | } |
| 52 | $result = $server_sort_array[$key + 1]; |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | } else { |
| 57 | if (is_array($msort)) { |
| 58 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 59 | if ($passed_id == $msgs[$key]['ID']) { |
| 60 | next($msort); |
| 61 | $key = key($msort); |
| 62 | if (isset($key)){ |
| 63 | $result = $msgs[$key]['ID']; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | return $result; |
| 71 | } |
| 72 | |
| 73 | /** returns the index of the previous message from the array. */ |
| 74 | function findPreviousMessage($numMessages, $passed_id) { |
| 75 | global $msort, $sort, $msgs, |
| 76 | $thread_sort_messages, |
| 77 | $allow_server_sort, $server_sort_array; |
| 78 | $result = -1; |
| 79 | if (!is_array($server_sort_array)) { |
| 80 | $thread_sort_messages = 0; |
| 81 | $allow_server_sort = FALSE; |
| 82 | } |
| 83 | if ($thread_sort_messages || $allow_server_sort ) { |
| 84 | foreach($server_sort_array as $key=>$value) { |
| 85 | if ($passed_id == $value) { |
| 86 | if ($key == 0) { |
| 87 | break; |
| 88 | } |
| 89 | $result = $server_sort_array[$key - 1]; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } else { |
| 94 | if (is_array($msort)) { |
| 95 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 96 | if ($passed_id == $msgs[$key]['ID']) { |
| 97 | prev($msort); |
| 98 | $key = key($msort); |
| 99 | if (isset($key)) { |
| 100 | $result = $msgs[$key]['ID']; |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | return $result; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Displays a link to a page where the message is displayed more |
| 112 | * "printer friendly". |
| 113 | */ |
| 114 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
| 115 | global $javascript_on; |
| 116 | |
| 117 | $params = '?passed_ent_id=' . $passed_ent_id . |
| 118 | '&mailbox=' . urlencode($mailbox) . |
| 119 | '&passed_id=' . $passed_id; |
| 120 | |
| 121 | $print_text = _("View Printable Version"); |
| 122 | |
| 123 | $result = ''; |
| 124 | /* Output the link. */ |
| 125 | if ($javascript_on) { |
| 126 | $result = '<script language="javascript" type="text/javascript">' . "\n" . |
| 127 | '<!--' . "\n" . |
| 128 | " function printFormat() {\n" . |
| 129 | ' window.open("../src/printer_friendly_main.php' . |
| 130 | $params . '","Print","width=800,height=600");' . "\n". |
| 131 | " }\n" . |
| 132 | "// -->\n" . |
| 133 | "</script>\n" . |
| 134 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
| 135 | } else { |
| 136 | $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' . |
| 137 | "$params\">$print_text</a>\n"; |
| 138 | } |
| 139 | return $result; |
| 140 | } |
| 141 | |
| 142 | function ServerMDNSupport($read) { |
| 143 | /* escaping $ doesn't work -> \x36 */ |
| 144 | $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read); |
| 145 | return $ret; |
| 146 | } |
| 147 | |
| 148 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
| 149 | global $username, $attachment_dir, |
| 150 | $version, $attachments, $squirrelmail_language, $default_charset, |
| 151 | $languages, $useSendmail, $domain, $sent_folder, |
| 152 | $popuser, $data_dir, $username; |
| 153 | |
| 154 | sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); |
| 155 | |
| 156 | $header = $message->rfc822_header; |
| 157 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 158 | |
| 159 | $rfc822_header = new Rfc822Header(); |
| 160 | $content_type = new ContentType('multipart/report'); |
| 161 | $content_type->properties['report-type']='disposition-notification'; |
| 162 | |
| 163 | set_my_charset(); |
| 164 | if ($default_charset) { |
| 165 | $content_type->properties['charset']=$default_charset; |
| 166 | } |
| 167 | $rfc822_header->content_type = $content_type; |
| 168 | $rfc822_header->to[] = $header->dnt; |
| 169 | $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject); |
| 170 | |
| 171 | |
| 172 | $reply_to = ''; |
| 173 | $ident = get_identities(); |
| 174 | if(!isset($identity)) $identity = 0; |
| 175 | $full_name = $ident[$identity]['full_name']; |
| 176 | $from_mail = $ident[$identity]['email_address']; |
| 177 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
| 178 | $reply_to = $ident[$identity]['reply_to']; |
| 179 | |
| 180 | if (!$from_addr) { |
| 181 | $from_addr = "$popuser@$domain"; |
| 182 | $from_mail = $from_addr; |
| 183 | } |
| 184 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
| 185 | if ($reply_to) { |
| 186 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
| 187 | } |
| 188 | |
| 189 | // part 1 (RFC2298) |
| 190 | $senton = getLongDateString( $header->date ); |
| 191 | $to_array = $header->to; |
| 192 | $to = ''; |
| 193 | foreach ($to_array as $line) { |
| 194 | $to .= ' '.$line->getAddress(); |
| 195 | } |
| 196 | $now = getLongDateString( time() ); |
| 197 | set_my_charset(); |
| 198 | $body = _("Your message") . "\r\n\r\n" . |
| 199 | "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" . |
| 200 | "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" . |
| 201 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
| 202 | "\r\n" . |
| 203 | sprintf( _("Was displayed on %s"), $now ); |
| 204 | |
| 205 | $special_encoding = ''; |
| 206 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
| 207 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
| 208 | $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body); |
| 209 | if (strtolower($default_charset) == 'iso-2022-jp') { |
| 210 | if (mb_detect_encoding($body) == 'ASCII') { |
| 211 | $special_encoding = '8bit'; |
| 212 | } else { |
| 213 | $body = mb_convert_encoding($body, 'JIS'); |
| 214 | $special_encoding = '7bit'; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | $part1 = new Message(); |
| 219 | $part1->setBody($body); |
| 220 | $mime_header = new MessageHeader; |
| 221 | $mime_header->type0 = 'text'; |
| 222 | $mime_header->type1 = 'plain'; |
| 223 | if ($special_encoding) { |
| 224 | $mime_header->encoding = $special_encoding; |
| 225 | } else { |
| 226 | $mime_header->encoding = 'us-ascii'; |
| 227 | } |
| 228 | if ($default_charset) { |
| 229 | $mime_header->parameters['charset'] = $default_charset; |
| 230 | } |
| 231 | $part1->mime_header = $mime_header; |
| 232 | |
| 233 | // part2 (RFC2298) |
| 234 | $original_recipient = $to; |
| 235 | $original_message_id = $header->message_id; |
| 236 | |
| 237 | $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
| 238 | if ($original_recipient != '') { |
| 239 | $report .= "Original-Recipient : $original_recipient\r\n"; |
| 240 | } |
| 241 | $final_recipient = $sender; |
| 242 | $report .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
| 243 | "Original-Message-ID : $original_message_id\r\n" . |
| 244 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
| 245 | |
| 246 | $part2 = new Message(); |
| 247 | $part2->setBody($report); |
| 248 | $mime_header = new MessageHeader; |
| 249 | $mime_header->type0 = 'message'; |
| 250 | $mime_header->type1 = 'disposition-notification'; |
| 251 | $mime_header->encoding = 'us-ascii'; |
| 252 | $part2->mime_header = $mime_header; |
| 253 | |
| 254 | $composeMessage = new Message(); |
| 255 | $composeMessage->rfc822_header = $rfc822_header; |
| 256 | $composeMessage->addEntity($part1); |
| 257 | $composeMessage->addEntity($part2); |
| 258 | |
| 259 | |
| 260 | if ($useSendmail) { |
| 261 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
| 262 | global $sendmail_path; |
| 263 | $deliver = new Deliver_SendMail(); |
| 264 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
| 265 | } else { |
| 266 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
| 267 | $deliver = new Deliver_SMTP(); |
| 268 | global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp; |
| 269 | if ($smtp_auth_mech == 'none') { |
| 270 | $user = ''; |
| 271 | $pass = ''; |
| 272 | } else { |
| 273 | global $key, $onetimepad; |
| 274 | $user = $username; |
| 275 | $pass = OneTimePadDecrypt($key, $onetimepad); |
| 276 | } |
| 277 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
| 278 | $stream = $deliver->initStream($composeMessage,$domain,0, |
| 279 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
| 280 | } |
| 281 | $success = false; |
| 282 | if ($stream) { |
| 283 | $length = $deliver->mail($composeMessage, $stream); |
| 284 | $success = $deliver->finalizeStream($stream); |
| 285 | } |
| 286 | if (!$success) { |
| 287 | $msg = $deliver->dlv_msg . '<br>' . |
| 288 | _("Server replied: ") . $deliver->dlv_ret_nr . ' '. |
| 289 | $deliver->dlv_server_msg; |
| 290 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 291 | plain_error_message($msg, $color); |
| 292 | } else { |
| 293 | unset ($deliver); |
| 294 | if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
| 295 | sqimap_append ($imapConnection, $sent_folder, $length); |
| 296 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
| 297 | $imap_deliver = new Deliver_IMAP(); |
| 298 | $imap_deliver->mail($composeMessage, $imapConnection); |
| 299 | sqimap_append_done ($imapConnection); |
| 300 | unset ($imap_deliver); |
| 301 | } |
| 302 | } |
| 303 | return $success; |
| 304 | } |
| 305 | |
| 306 | function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) { |
| 307 | $sg = $set?'+':'-'; |
| 308 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
| 309 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
| 310 | $readmessage, $uid_support); |
| 311 | } |
| 312 | |
| 313 | function ClearAttachments() { |
| 314 | global $username, $attachments, $attachment_dir; |
| 315 | |
| 316 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 317 | |
| 318 | $rem_attachments = array(); |
| 319 | if (isset($attachments)) { |
| 320 | foreach ($attachments as $info) { |
| 321 | if ($info['session'] == -1) { |
| 322 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 323 | if (file_exists($attached_file)) { |
| 324 | unlink($attached_file); |
| 325 | } |
| 326 | } else { |
| 327 | $rem_attachments[] = $info; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | $attachments = $rem_attachments; |
| 332 | } |
| 333 | |
| 334 | function formatRecipientString($recipients, $item ) { |
| 335 | global $show_more_cc, $show_more, $show_more_bcc, |
| 336 | $PHP_SELF; |
| 337 | |
| 338 | $string = ''; |
| 339 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
| 340 | $show = false; |
| 341 | |
| 342 | if ($item == 'to') { |
| 343 | if ($show_more) { |
| 344 | $show = true; |
| 345 | $url = set_url_var($PHP_SELF, 'show_more',0); |
| 346 | } else { |
| 347 | $url = set_url_var($PHP_SELF, 'show_more',1); |
| 348 | } |
| 349 | } else if ($item == 'cc') { |
| 350 | if ($show_more_cc) { |
| 351 | $show = true; |
| 352 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
| 353 | } else { |
| 354 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
| 355 | } |
| 356 | } else if ($item == 'bcc') { |
| 357 | if ($show_more_bcc) { |
| 358 | $show = true; |
| 359 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
| 360 | } else { |
| 361 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | $cnt = count($recipients); |
| 366 | foreach($recipients as $r) { |
| 367 | $add = decodeHeader($r->getAddress(true)); |
| 368 | if ($string) { |
| 369 | $string .= '<BR>' . $add; |
| 370 | } else { |
| 371 | $string = $add; |
| 372 | if ($cnt > 1) { |
| 373 | $string .= ' (<A HREF="'.$url; |
| 374 | if ($show) { |
| 375 | $string .= '">'._("less").'</A>)'; |
| 376 | } else { |
| 377 | $string .= '">'._("more").'</A>)'; |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | return $string; |
| 385 | } |
| 386 | |
| 387 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, |
| 388 | $color, $FirstTimeSee) { |
| 389 | global $msn_user_support, $default_use_mdn, $default_use_priority, |
| 390 | $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on, |
| 391 | $squirrelmail_language; |
| 392 | |
| 393 | $header = $message->rfc822_header; |
| 394 | $env = array(); |
| 395 | $env[_("Subject")] = decodeHeader($header->subject); |
| 396 | $from_name = $header->getAddr_s('from'); |
| 397 | if (!$from_name) { |
| 398 | $from_name = $header->getAddr_s('sender'); |
| 399 | if (!$from_name) { |
| 400 | $from_name = _("Unknown sender"); |
| 401 | } |
| 402 | } |
| 403 | $env[_("From")] = decodeHeader($from_name); |
| 404 | $env[_("Date")] = getLongDateString($header->date); |
| 405 | $env[_("To")] = formatRecipientString($header->to, "to"); |
| 406 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
| 407 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
| 408 | if ($default_use_priority) { |
| 409 | $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority)); |
| 410 | } |
| 411 | if ($show_xmailer_default) { |
| 412 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
| 413 | } |
| 414 | if ($default_use_mdn) { |
| 415 | if ($mdn_user_support) { |
| 416 | if ($header->dnt) { |
| 417 | if ($message->is_mdnsent) { |
| 418 | $env[_("Read receipt")] = _("send"); |
| 419 | } else { |
| 420 | $env[_("Read receipt")] = _("requested"); |
| 421 | if (!(handleAsSent($mailbox) || |
| 422 | $message->is_deleted || |
| 423 | $passed_ent_id)) { |
| 424 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
| 425 | if ($FirstTimeSee && $javascript_on) { |
| 426 | $script = '<script language="JavaScript" type="text/javascript">' . "\n"; |
| 427 | $script .= '<!--'. "\n"; |
| 428 | $script .= 'if(window.confirm("' . |
| 429 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
| 430 | '")) { '."\n" . |
| 431 | ' sendMDN()'. |
| 432 | '}' . "\n"; |
| 433 | $script .= '// -->'. "\n"; |
| 434 | $script .= '</script>'. "\n"; |
| 435 | echo $script; |
| 436 | } |
| 437 | $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' . |
| 438 | _("Send read receipt now") . ']</a>'; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"'; |
| 446 | $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">'; |
| 447 | foreach ($env as $key => $val) { |
| 448 | if ($val) { |
| 449 | $s .= '<TR>'; |
| 450 | $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n"; |
| 451 | $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n"; |
| 452 | $s .= '</TR>'; |
| 453 | } |
| 454 | } |
| 455 | echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'. |
| 456 | ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n"; |
| 457 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
| 458 | $color[4].'"></TD></TR><TR><TD align=center>'."\n"; |
| 459 | echo $s; |
| 460 | do_hook('read_body_header'); |
| 461 | formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color); |
| 462 | echo '</TABLE>'; |
| 463 | echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n"; |
| 464 | echo '</TABLE>'; |
| 465 | } |
| 466 | |
| 467 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { |
| 468 | global $base_uri, $draft_folder, $where, $what, $color, $sort, |
| 469 | $startMessage, $PHP_SELF, $save_as_draft, |
| 470 | $enable_forward_as_attachment; |
| 471 | |
| 472 | $topbar_delimiter = ' | '; |
| 473 | $urlMailbox = urlencode($mailbox); |
| 474 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
| 475 | ' border="0" bgcolor="'.$color[9].'"><tr>' . |
| 476 | html_tag( 'td', '', 'left', '', 'width="33%"' ) . '<small>'; |
| 477 | |
| 478 | $msgs_url = $base_uri . 'src/'; |
| 479 | if (isset($where) && isset($what)) { |
| 480 | $msgs_url .= 'search.php?where=' . urlencode($where) . |
| 481 | '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox; |
| 482 | $msgs_str = _("Search results"); |
| 483 | } else { |
| 484 | $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' . |
| 485 | $startMessage . '&mailbox=' . $urlMailbox; |
| 486 | $msgs_str = _("Message List"); |
| 487 | } |
| 488 | $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>'; |
| 489 | |
| 490 | $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox . |
| 491 | '&message=' . $passed_id . '&'; |
| 492 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
| 493 | if ($where && $what) { |
| 494 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
| 495 | } else { |
| 496 | $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage; |
| 497 | } |
| 498 | $s .= $topbar_delimiter; |
| 499 | $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>'; |
| 500 | } |
| 501 | |
| 502 | $comp_uri = 'src/compose.php' . |
| 503 | '?passed_id=' . $passed_id . |
| 504 | '&mailbox=' . $urlMailbox . |
| 505 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
| 506 | |
| 507 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
| 508 | $comp_alt_uri = $comp_uri . '&action=draft'; |
| 509 | $comp_alt_string = _("Resume Draft"); |
| 510 | } else if (handleAsSent($mailbox)) { |
| 511 | $comp_alt_uri = $comp_uri . '&action=edit_as_new'; |
| 512 | $comp_alt_string = _("Edit Message as New"); |
| 513 | } |
| 514 | if (isset($comp_alt_uri)) { |
| 515 | $s .= $topbar_delimiter; |
| 516 | $s .= makeComposeLink($comp_alt_uri, $comp_alt_string); |
| 517 | } |
| 518 | |
| 519 | $s .= '</small></td><td align="center" width="33%"><small>'; |
| 520 | |
| 521 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
| 522 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
| 523 | $next = findNextMessage($passed_id); |
| 524 | if ($prev != -1) { |
| 525 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
| 526 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
| 527 | '&startMessage='.$startMessage.'&show_more=0'; |
| 528 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
| 529 | } else { |
| 530 | $s .= _("Previous"); |
| 531 | } |
| 532 | $s .= $topbar_delimiter; |
| 533 | if ($next != -1) { |
| 534 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
| 535 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
| 536 | '&startMessage='.$startMessage.'&show_more=0'; |
| 537 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
| 538 | } else { |
| 539 | $s .= _("Next"); |
| 540 | } |
| 541 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
| 542 | /* code for navigating through attached message/rfc822 messages */ |
| 543 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
| 544 | $s .= '<a href="'.$url.'">'._("View Message").'</a>'; |
| 545 | $entities = array(); |
| 546 | $entity_count = array(); |
| 547 | $c = 0; |
| 548 | |
| 549 | foreach($message->parent->entities as $ent) { |
| 550 | if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') { |
| 551 | $c++; |
| 552 | $entity_count[$c] = $ent->entity_id; |
| 553 | $entities[$ent->entity_id] = $c; |
| 554 | } |
| 555 | } |
| 556 | $prev_link = _("Previous"); |
| 557 | $next_link = _("Next"); |
| 558 | if($entities[$passed_ent_id] > 1) { |
| 559 | $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1]; |
| 560 | $prev_link = '<a href="' |
| 561 | . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id) |
| 562 | . '">' . $prev_link . '</a>'; |
| 563 | } |
| 564 | if($entities[$passed_ent_id] < $c) { |
| 565 | $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1]; |
| 566 | $next_link = '<a href="' |
| 567 | . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id) |
| 568 | . '">' . $next_link . '</a>'; |
| 569 | } |
| 570 | $s .= $topbar_delimiter . $prev_link; |
| 571 | $par_ent_id = $message->parent->entity_id; |
| 572 | if ($par_ent_id) { |
| 573 | $par_ent_id = substr($par_ent_id,0,-2); |
| 574 | $s .= $topbar_delimiter; |
| 575 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
| 576 | $s .= '<a href="'.$url.'">'._("Up").'</a>'; |
| 577 | } |
| 578 | $s .= $topbar_delimiter . $next_link; |
| 579 | } |
| 580 | |
| 581 | $s .= '</small></td>' . "\n" . |
| 582 | html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>'; |
| 583 | $comp_action_uri = $comp_uri . '&action=forward'; |
| 584 | $s .= makeComposeLink($comp_action_uri, _("Forward")); |
| 585 | |
| 586 | if ($enable_forward_as_attachment) { |
| 587 | $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; |
| 588 | $s .= $topbar_delimiter; |
| 589 | $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment")); |
| 590 | } |
| 591 | |
| 592 | $comp_action_uri = $comp_uri . '&action=reply'; |
| 593 | $s .= $topbar_delimiter; |
| 594 | $s .= makeComposeLink($comp_action_uri, _("Reply")); |
| 595 | |
| 596 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
| 597 | $s .= $topbar_delimiter; |
| 598 | $s .= makeComposeLink($comp_action_uri, _("Reply All")); |
| 599 | $s .= '</small></td></tr></table>'; |
| 600 | do_hook('read_body_menu_top'); |
| 601 | echo $s; |
| 602 | do_hook('read_body_menu_bottom'); |
| 603 | } |
| 604 | |
| 605 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
| 606 | global $base_uri; |
| 607 | |
| 608 | $urlMailbox = urlencode($mailbox); |
| 609 | sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER); |
| 610 | $url = $base_uri.'src/view_header.php?'.$query_string; |
| 611 | |
| 612 | $s = "<TR>\n" . |
| 613 | html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" . |
| 614 | html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' . |
| 615 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
| 616 | |
| 617 | /* Output the printer friendly link if we are in subtle mode. */ |
| 618 | $s .= ' | ' . |
| 619 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
| 620 | echo $s; |
| 621 | do_hook("read_body_header_right"); |
| 622 | $s = "</SMALL></TD>\n" . |
| 623 | "</TR>\n"; |
| 624 | echo $s; |
| 625 | |
| 626 | } |
| 627 | |
| 628 | /***************************/ |
| 629 | /* Main of read_body.php */ |
| 630 | /***************************/ |
| 631 | |
| 632 | /* get the globals we may need */ |
| 633 | |
| 634 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 635 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 636 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
| 637 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 638 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
| 639 | |
| 640 | sqgetGlobalVar('msgs', $msgs, SQ_SESSION); |
| 641 | sqgetGlobalVar('msort', $msort, SQ_SESSION); |
| 642 | sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); |
| 643 | sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION); |
| 644 | if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) { |
| 645 | $messages = array(); |
| 646 | } |
| 647 | |
| 648 | /** GET VARS */ |
| 649 | sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET); |
| 650 | sqgetGlobalVar('where', $where, SQ_GET); |
| 651 | sqgetGlobalVar('what', $what, SQ_GET); |
| 652 | if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) { |
| 653 | $show_more = (int) $temp; |
| 654 | } |
| 655 | if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) { |
| 656 | $show_more_cc = (int) $temp; |
| 657 | } |
| 658 | if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) { |
| 659 | $show_more_bcc = (int) $temp; |
| 660 | } |
| 661 | if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) { |
| 662 | $view_hdr = (int) $temp; |
| 663 | } |
| 664 | |
| 665 | /** POST VARS */ |
| 666 | sqgetGlobalVar('move_id', $move_id, SQ_POST); |
| 667 | |
| 668 | /** GET/POST VARS */ |
| 669 | sqgetGlobalVar('passed_ent_id', $passed_ent_id); |
| 670 | sqgetGlobalVar('mailbox', $mailbox); |
| 671 | |
| 672 | if ( sqgetGlobalVar('passed_id', $temp) ) { |
| 673 | $passed_id = (int) $temp; |
| 674 | } |
| 675 | if ( sqgetGlobalVar('sort', $temp) ) { |
| 676 | $sort = (int) $temp; |
| 677 | } |
| 678 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
| 679 | $startMessage = (int) $temp; |
| 680 | } |
| 681 | |
| 682 | /* end of get globals */ |
| 683 | global $uid_support, $sqimap_capabilities; |
| 684 | |
| 685 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 686 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 687 | |
| 688 | |
| 689 | /** |
| 690 | * $message contains all information about the message |
| 691 | * including header and body |
| 692 | */ |
| 693 | |
| 694 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
| 695 | |
| 696 | if (!isset($messages[$uidvalidity])) { |
| 697 | $messages[$uidvalidity] = array(); |
| 698 | } |
| 699 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
| 700 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 701 | $FirstTimeSee = !$message->is_seen; |
| 702 | $message->is_seen = true; |
| 703 | $messages[$uidvalidity][$passed_id] = $message; |
| 704 | } else { |
| 705 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 706 | $message = $messages[$uidvalidity][$passed_id]; |
| 707 | $FirstTimeSee = !$message->is_seen; |
| 708 | } |
| 709 | |
| 710 | if (isset($passed_ent_id) && $passed_ent_id) { |
| 711 | $message = $message->getEntity($passed_ent_id); |
| 712 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
| 713 | $message = $message->parent; |
| 714 | } |
| 715 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support); |
| 716 | $rfc822_header = new Rfc822Header(); |
| 717 | $rfc822_header->parseHeader($read); |
| 718 | $message->rfc822_header = $rfc822_header; |
| 719 | } else { |
| 720 | $passed_ent_id = 0; |
| 721 | } |
| 722 | $header = $message->header; |
| 723 | |
| 724 | do_hook('html_top'); |
| 725 | |
| 726 | /****************************************/ |
| 727 | /* Block for handling incoming url vars */ |
| 728 | /****************************************/ |
| 729 | |
| 730 | if (isset($sendreceipt)) { |
| 731 | if ( !$message->is_mdnsent ) { |
| 732 | if (isset($identity) ) { |
| 733 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
| 734 | } else { |
| 735 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 736 | } |
| 737 | |
| 738 | $final_recipient = trim($final_recipient); |
| 739 | if ($final_recipient == '' ) { |
| 740 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 741 | } |
| 742 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
| 743 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
| 744 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
| 745 | $message->is_mdnsent = true; |
| 746 | $messages[$uidvalidity][$passed_id]=$message; |
| 747 | } |
| 748 | ClearAttachments(); |
| 749 | } |
| 750 | } |
| 751 | /***********************************************/ |
| 752 | /* End of block for handling incoming url vars */ |
| 753 | /***********************************************/ |
| 754 | |
| 755 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
| 756 | |
| 757 | $messagebody = ''; |
| 758 | do_hook('read_body_top'); |
| 759 | if ($show_html_default == 1) { |
| 760 | $ent_ar = $message->findDisplayEntity(array()); |
| 761 | } else { |
| 762 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
| 763 | } |
| 764 | $cnt = count($ent_ar); |
| 765 | for ($i = 0; $i < $cnt; $i++) { |
| 766 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
| 767 | if ($i != $cnt-1) { |
| 768 | $messagebody .= '<hr noshade size=1>'; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | displayPageHeader($color, $mailbox); |
| 773 | formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
| 774 | formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
| 775 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
| 776 | echo ' <tr><td>'; |
| 777 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
| 778 | echo ' <tr><td>'; |
| 779 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
| 780 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
| 781 | // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">'; |
| 782 | echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' ); |
| 783 | echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left') |
| 784 | . '</tr>'; |
| 785 | echo ' </table>'; |
| 786 | echo ' </td></tr>'; |
| 787 | echo ' </table></td></tr>'; |
| 788 | echo ' </table>'; |
| 789 | echo ' </td></tr>'; |
| 790 | |
| 791 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
| 792 | $color[4].'"></TD></TR>'."\n"; |
| 793 | |
| 794 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
| 795 | if ($attachmentsdisplay) { |
| 796 | echo ' </table>'; |
| 797 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
| 798 | echo ' <tr><td>'; |
| 799 | echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
| 800 | echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] ); |
| 801 | echo ' <b>' . _("Attachments") . ':</b>'; |
| 802 | echo ' </td></tr>'; |
| 803 | echo ' <tr><td>'; |
| 804 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
| 805 | echo $attachmentsdisplay; |
| 806 | echo ' </td></tr></table>'; |
| 807 | echo ' </td></tr></table>'; |
| 808 | echo ' </td></tr>'; |
| 809 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
| 810 | $color[4].'"></TD></TR>'; |
| 811 | } |
| 812 | echo '</table>'; |
| 813 | |
| 814 | /* show attached images inline -- if pref'fed so */ |
| 815 | if (($attachment_common_show_images) && |
| 816 | is_array($attachment_common_show_images_list)) { |
| 817 | foreach ($attachment_common_show_images_list as $img) { |
| 818 | $imgurl = SM_PATH . 'src/download.php' . |
| 819 | '?' . |
| 820 | 'passed_id=' . urlencode($img['passed_id']) . |
| 821 | '&mailbox=' . urlencode($mailbox) . |
| 822 | '&ent_id=' . urlencode($img['ent_id']) . |
| 823 | '&absolute_dl=true'; |
| 824 | |
| 825 | echo html_tag( 'table', "\n" . |
| 826 | html_tag( 'tr', "\n" . |
| 827 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
| 828 | ) |
| 829 | ) , |
| 830 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | do_hook('read_body_bottom'); |
| 835 | do_hook('html_bottom'); |
| 836 | sqimap_logout($imapConnection); |
| 837 | /* sessions are written at the end of the script. it's better to register |
| 838 | them at the end so we avoid double session_register calls */ |
| 839 | sqsession_register($messages,'messages'); |
| 840 | |
| 841 | ?> |
| 842 | </body> |
| 843 | </html> |