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