| 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 | * Given an IMAP message id number, this will look it up in the cached |
| 28 | * and sorted msgs array and return the index. Used for finding the next |
| 29 | * and previous messages. |
| 30 | * |
| 31 | * @return the index of the next valid message from the array |
| 32 | */ |
| 33 | function findNextMessage($passed_id) { |
| 34 | global $msort, $msgs, $sort, |
| 35 | $thread_sort_messages, $allow_server_sort, |
| 36 | $server_sort_array; |
| 37 | if (!is_array($server_sort_array)) { |
| 38 | $thread_sort_messages = 0; |
| 39 | $allow_server_sort = FALSE; |
| 40 | } |
| 41 | $result = -1; |
| 42 | if ($thread_sort_messages || $allow_server_sort) { |
| 43 | reset($server_sort_array); |
| 44 | while(list($key, $value) = each ($server_sort_array)) { |
| 45 | if ($passed_id == $value) { |
| 46 | if ($key == (count($server_sort_array) - 1)) { |
| 47 | $result = -1; |
| 48 | break; |
| 49 | } |
| 50 | $result = $server_sort_array[$key + 1]; |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | } else if ($sort == 6 && !$allow_server_sort && |
| 55 | !$thread_sort_messages ) { |
| 56 | if ($passed_id != 1) { |
| 57 | $result = $passed_id - 1; |
| 58 | } |
| 59 | } else if (!$allow_server_sort && !$thread_sort_messages ) { |
| 60 | if (!is_array($msort)) { |
| 61 | return -1; |
| 62 | } |
| 63 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 64 | if ($passed_id == $msgs[$key]['ID']) { |
| 65 | next($msort); |
| 66 | $key = key($msort); |
| 67 | if (isset($key)){ |
| 68 | $result = $msgs[$key]['ID']; |
| 69 | break; |
| 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 | reset($server_sort_array); |
| 89 | while(list($key, $value) = each ($server_sort_array)) { |
| 90 | if ($passed_id == $value) { |
| 91 | if ($key == 0) { |
| 92 | $result = -1; |
| 93 | break; |
| 94 | } |
| 95 | $result = $server_sort_array[$key -1]; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | } else if ($sort == 6 && !$allow_server_sort && |
| 100 | !$thread_sort_messages) { |
| 101 | if ($passed_id != $numMessages) { |
| 102 | $result = $passed_id + 1; |
| 103 | } |
| 104 | } else if (!$thread_sort_messages && !$allow_server_sort) { |
| 105 | if (!is_array($msort)) { |
| 106 | return -1; |
| 107 | } |
| 108 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 109 | if ($passed_id == $msgs[$key]['ID']) { |
| 110 | prev($msort); |
| 111 | $key = key($msort); |
| 112 | if (isset($key)) { |
| 113 | //echo $msort[$key]; /* Why again were we echoing here? */ |
| 114 | $result = $msgs[$key]['ID']; |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | return ($result); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Displays a link to a page where the message is displayed more |
| 125 | * "printer friendly". |
| 126 | */ |
| 127 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
| 128 | global $javascript_on; |
| 129 | |
| 130 | $params = '?passed_ent_id=' . $passed_ent_id . |
| 131 | '&mailbox=' . urlencode($mailbox) . |
| 132 | '&passed_id=' . $passed_id; |
| 133 | |
| 134 | $print_text = _("View Printable Version"); |
| 135 | |
| 136 | $result = ''; |
| 137 | /* Output the link. */ |
| 138 | if ($javascript_on) { |
| 139 | $result .= '<script language="javascript" type="text/javascript">' . "\n" . |
| 140 | '<!--' . "\n" . |
| 141 | " function printFormat() {\n" . |
| 142 | ' window.open("../src/printer_friendly_main.php' . |
| 143 | $params . '","Print","width=800,height=600");' . "\n". |
| 144 | " }\n" . |
| 145 | "// -->\n" . |
| 146 | "</script>\n" . |
| 147 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
| 148 | } else { |
| 149 | $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' . |
| 150 | "$params\">$print_text</a>\n"; |
| 151 | } |
| 152 | return ($result); |
| 153 | } |
| 154 | |
| 155 | function ServerMDNSupport( $read ) { |
| 156 | /* escaping $ doesn't work -> \x36 */ |
| 157 | $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read ); |
| 158 | return ( $ret ); |
| 159 | } |
| 160 | |
| 161 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
| 162 | global $username, $attachment_dir, $SERVER_NAME, |
| 163 | $version, $attachments, $squirrelmail_language, $default_charset, |
| 164 | $languages, $useSendmail, $domain, $sent_folder, |
| 165 | $popuser, $data_dir, $username; |
| 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_SMTP.class.php'); |
| 280 | $deliver = new Deliver_SMTP(); |
| 281 | global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp; |
| 282 | if ($use_authenticated_smtp) { |
| 283 | global $key, $onetimepad; |
| 284 | $user = $username; |
| 285 | $pass = OneTimePadDecrypt($key, $onetimepad); |
| 286 | } else { |
| 287 | $user = ''; |
| 288 | $pass = ''; |
| 289 | } |
| 290 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
| 291 | $stream = $deliver->initStream($composeMessage,$domain,0, |
| 292 | $smtpServerAddress, $smtpPort, $authPop); |
| 293 | } else { |
| 294 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
| 295 | global $sendmail_path; |
| 296 | $deliver = new Deliver_SendMail(); |
| 297 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
| 298 | } |
| 299 | $succes = false; |
| 300 | if ($stream) { |
| 301 | $length = $deliver->mail($composeMessage, $stream); |
| 302 | $succes = $deliver->finalizeStream($stream); |
| 303 | } |
| 304 | if (!$succes) { |
| 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 $succes; |
| 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 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
| 354 | $string = ''; |
| 355 | $ary = $recipients; |
| 356 | $show = false; |
| 357 | |
| 358 | if ($item == 'to') { |
| 359 | if ($show_more) { |
| 360 | $show = true; |
| 361 | $url = set_url_var($PHP_SELF, 'show_more',0); |
| 362 | } else { |
| 363 | $url = set_url_var($PHP_SELF, 'show_more',1); |
| 364 | } |
| 365 | } else if ($item == 'cc') { |
| 366 | if ($show_more_cc) { |
| 367 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
| 368 | $show = true; |
| 369 | } else { |
| 370 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
| 371 | } |
| 372 | } else if ($item == 'bcc') { |
| 373 | if ($show_more_bcc) { |
| 374 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
| 375 | $show = true; |
| 376 | } else { |
| 377 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | $cnt = count($ary); |
| 382 | $i = 0; |
| 383 | while ($i < $cnt) { |
| 384 | $ary[$i] = htmlspecialchars($ary[$i]->getAddress()); |
| 385 | if ($string) { |
| 386 | $string .= '<BR>'.$ary[$i]; |
| 387 | } else { |
| 388 | $string = $ary[$i]; |
| 389 | if ($cnt>1) { |
| 390 | $string .= ' (<A HREF="'.$url; |
| 391 | if ($show) { |
| 392 | $string .= '">'._("less").'</A>)'; |
| 393 | } else { |
| 394 | $string .= '">'._("more").'</A>)'; |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | $i++; |
| 400 | } |
| 401 | } |
| 402 | else { |
| 403 | $string = ''; |
| 404 | } |
| 405 | return $string; |
| 406 | } |
| 407 | |
| 408 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, |
| 409 | $color, $FirstTimeSee) { |
| 410 | global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder, |
| 411 | $default_use_priority, $show_xmailer_default, |
| 412 | $mdn_user_support, $PHP_SELF, $javascript_on; |
| 413 | |
| 414 | $header = $message->rfc822_header; |
| 415 | $env = array(); |
| 416 | $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject)); |
| 417 | $from_name = $header->getAddr_s('from'); |
| 418 | if (!$from_name) { |
| 419 | $from_name = $header->getAddr_s('sender'); |
| 420 | if (!$from_name) { |
| 421 | $from_name = _("Unknown sender"); |
| 422 | } |
| 423 | } |
| 424 | $env[_("From")] = htmlspecialchars(decodeHeader($from_name)); |
| 425 | $env[_("Date")] = getLongDateString($header->date); |
| 426 | $env[_("To")] = formatRecipientString($header->to, "to"); |
| 427 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
| 428 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
| 429 | if ($default_use_priority) { |
| 430 | $env[_("Priority")] = getPriorityStr($header->priority); |
| 431 | } |
| 432 | if ($show_xmailer_default) { |
| 433 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
| 434 | } |
| 435 | if ($default_use_mdn) { |
| 436 | if ($mdn_user_support) { |
| 437 | if ($header->dnt) { |
| 438 | if ($message->is_mdnsent) { |
| 439 | $env[_("Read receipt")] = _("send"); |
| 440 | } else { |
| 441 | if ( !($mailbox == $draft_folder || |
| 442 | $mailbox == $sent_folder || |
| 443 | $message->is_deleted || |
| 444 | $passed_ent_id)) { |
| 445 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
| 446 | if ($FirstTimeSee && $javascript_on) { |
| 447 | $script = '<script language="JavaScript" type="text/javascript">' ."\n"; |
| 448 | $script .= '<!--'. "\n"; |
| 449 | $script .= 'if(window.confirm("' . |
| 450 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
| 451 | '")) { '."\n" . |
| 452 | ' sendMDN()'. |
| 453 | '}' . "\n"; |
| 454 | $script .= '// -->'. "\n"; |
| 455 | $script .= '</script>'. "\n"; |
| 456 | echo $script; |
| 457 | } |
| 458 | $env[_("Read receipt")] = _("requested") . |
| 459 | ' <a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>'; |
| 460 | } else { |
| 461 | $env[_("Read receipt")] = _("requested"); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"'; |
| 469 | $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">'; |
| 470 | foreach ($env as $key => $val) { |
| 471 | if ($val) { |
| 472 | $s .= '<TR>'; |
| 473 | $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n"; |
| 474 | $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n"; |
| 475 | $s .= '</TR>'; |
| 476 | } |
| 477 | } |
| 478 | echo $s; |
| 479 | do_hook("read_body_header"); |
| 480 | formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color); |
| 481 | echo '</table>'; |
| 482 | } |
| 483 | |
| 484 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { |
| 485 | global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort, |
| 486 | $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft, |
| 487 | $enable_forward_as_attachment; |
| 488 | |
| 489 | $topbar_delimiter = ' | '; |
| 490 | $urlMailbox = urlencode($mailbox); |
| 491 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
| 492 | ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>'; |
| 493 | |
| 494 | $msgs_url = $base_uri . 'src/'; |
| 495 | if (isset($where) && isset($what)) { |
| 496 | $msgs_url .= 'search.php?where='.urlencode($where). |
| 497 | '&what='.urlencode($what).'&mailbox='.$urlMailbox; |
| 498 | $msgs_str = _("Search results"); |
| 499 | } else { |
| 500 | $msgs_url .= 'right_main.php?sort='.$sort.'&startMessage='. |
| 501 | $startMessage.'&mailbox='.$urlMailbox; |
| 502 | $msgs_str = _("Message List"); |
| 503 | } |
| 504 | $s .= '<a href="'. $msgs_url.'">'.$msgs_str.'</a>'; |
| 505 | $s .= $topbar_delimiter; |
| 506 | |
| 507 | $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox. |
| 508 | '&message='.$passed_id.'&'; |
| 509 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
| 510 | if ($where && $what) { |
| 511 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
| 512 | } else { |
| 513 | $delete_url .= 'sort='. $sort . '&startMessage='. $startMessage; |
| 514 | } |
| 515 | $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>'; |
| 516 | } |
| 517 | |
| 518 | $comp_uri = $base_uri . 'src/compose.php'. |
| 519 | '?passed_id='.$passed_id. |
| 520 | '&mailbox='.$urlMailbox. |
| 521 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
| 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 | if ($compose_new_win == '1') { |
| 533 | $s .= '<a href="javascript:void(0)" '. |
| 534 | 'onclick="comp_in_new(\''.$comp_alt_uri.'\')">'.$comp_alt_string.'</a>'; |
| 535 | } else { |
| 536 | $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>'; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | $s .= '</small></td><td align="center" width="33%"><small>'; |
| 541 | |
| 542 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
| 543 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
| 544 | $next = findNextMessage($passed_id); |
| 545 | if ($prev != -1) { |
| 546 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
| 547 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
| 548 | '&startMessage='.$startMessage.'&show_more=0'; |
| 549 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
| 550 | } else { |
| 551 | $s .= _("Previous"); |
| 552 | } |
| 553 | $s .= $topbar_delimiter; |
| 554 | if ($next != -1) { |
| 555 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
| 556 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
| 557 | '&startMessage='.$startMessage.'&show_more=0'; |
| 558 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
| 559 | } else { |
| 560 | $s .= _("Next"); |
| 561 | } |
| 562 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
| 563 | /* code for navigating through attached message/rfc822 messages */ |
| 564 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
| 565 | $s .= '<a href="'.$url.'">'._("View Message").'</a>'; |
| 566 | $par_ent_id = $message->parent->entity_id; |
| 567 | if ($par_ent_id) { |
| 568 | $par_ent_id = substr($par_ent_id,0,-2); |
| 569 | $s .= $topbar_delimiter; |
| 570 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
| 571 | $s .= '<a href="'.$url.'">'._("Up").'</a>'; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | $s .= '</small></td><td align="right" width="33%" nowrap><small>'; |
| 576 | $comp_action_uri = $comp_uri . '&action=forward'; |
| 577 | if ($compose_new_win == '1') { |
| 578 | $s .= '<a href="javascript:void(0)" '. |
| 579 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>'; |
| 580 | } else { |
| 581 | $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>'; |
| 582 | } |
| 583 | $s .= $topbar_delimiter; |
| 584 | |
| 585 | if ($enable_forward_as_attachment) { |
| 586 | $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; |
| 587 | if ($compose_new_win == '1') { |
| 588 | $s .= '<a href="javascript:void(0)" '. |
| 589 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward as Attachment").'</a>'; |
| 590 | } else { |
| 591 | $s .= '<a href="'.$comp_action_uri.'">'._("Forward as Attachment").'</a>'; |
| 592 | } |
| 593 | $s .= $topbar_delimiter; |
| 594 | } |
| 595 | |
| 596 | $comp_action_uri = decodeHeader($comp_uri . '&action=reply'); |
| 597 | if ($compose_new_win == '1') { |
| 598 | $s .= '<a href="javascript:void(0)" '. |
| 599 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>'; |
| 600 | } else { |
| 601 | $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>'; |
| 602 | } |
| 603 | $s .= $topbar_delimiter; |
| 604 | |
| 605 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
| 606 | if ($compose_new_win == '1') { |
| 607 | $s .= '<a href="javascript:void(0)" '. |
| 608 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>'; |
| 609 | } else { |
| 610 | $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>'; |
| 611 | } |
| 612 | $s .= '</small></td></tr></table>'; |
| 613 | do_hook("read_body_menu_top"); |
| 614 | echo $s; |
| 615 | do_hook("read_body_menu_bottom"); |
| 616 | } |
| 617 | |
| 618 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
| 619 | global $QUERY_STRING, $base_uri; |
| 620 | |
| 621 | $urlMailbox = urlencode($mailbox); |
| 622 | $url = $base_uri.'src/view_header.php?'.$QUERY_STRING; |
| 623 | |
| 624 | $s = "<TR>\n" . |
| 625 | '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ": </B></TD>\n" . |
| 626 | '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' . |
| 627 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
| 628 | |
| 629 | /* Output the printer friendly link if we are in subtle mode. */ |
| 630 | $s .= ' | ' . |
| 631 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
| 632 | echo $s; |
| 633 | do_hook("read_body_header_right"); |
| 634 | $s = "</SMALL></TD>\n" . |
| 635 | "</TR>\n"; |
| 636 | echo $s; |
| 637 | |
| 638 | } |
| 639 | |
| 640 | /***************************/ |
| 641 | /* Main of read_body.php */ |
| 642 | /***************************/ |
| 643 | |
| 644 | /* |
| 645 | Urled vars |
| 646 | ---------- |
| 647 | $passed_id |
| 648 | */ |
| 649 | |
| 650 | global $uid_support, $sqimap_capabilities; |
| 651 | |
| 652 | if (isset($mailbox)) { |
| 653 | $mailbox = urldecode( $mailbox ); |
| 654 | } |
| 655 | |
| 656 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 657 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 658 | |
| 659 | if (!isset($messages)) { |
| 660 | $messages = array(); |
| 661 | sqsession_register($messages,'messages'); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * $message contains all information about the message |
| 666 | * including header and body |
| 667 | */ |
| 668 | |
| 669 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
| 670 | |
| 671 | if (!isset($messages[$uidvalidity])) { |
| 672 | $messages[$uidvalidity] = array(); |
| 673 | } |
| 674 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
| 675 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 676 | $FirstTimeSee = !$message->is_seen; |
| 677 | $message->is_seen = true; |
| 678 | $messages[$uidvalidity][$passed_id] = $message; |
| 679 | sqsession_register($messages, 'messages'); |
| 680 | } else { |
| 681 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 682 | $message = $messages[$uidvalidity][$passed_id]; |
| 683 | $FirstTimeSee = !$message->is_seen; |
| 684 | } |
| 685 | //$FirstTimeSee = !$message->is_seen; |
| 686 | //$message->is_seen = true; |
| 687 | //$messages[$uidvalidity][$passed_id] = $message; |
| 688 | |
| 689 | if (isset($passed_ent_id) && $passed_ent_id) { |
| 690 | $message = $message->getEntity($passed_ent_id); |
| 691 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
| 692 | $message = $message->parent; |
| 693 | } |
| 694 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support); |
| 695 | $rfc822_header = new Rfc822Header(); |
| 696 | $rfc822_header->parseHeader($read); |
| 697 | $message->rfc822_header = $rfc822_header; |
| 698 | } else { |
| 699 | $passed_ent_id = 0; |
| 700 | } |
| 701 | $header = $message->header; |
| 702 | |
| 703 | do_hook('html_top'); |
| 704 | |
| 705 | /****************************************/ |
| 706 | /* Block for handling incoming url vars */ |
| 707 | /****************************************/ |
| 708 | |
| 709 | if (isset($sendreceipt)) { |
| 710 | if ( !$message->is_mdnsent ) { |
| 711 | if (isset($identity) ) { |
| 712 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
| 713 | } else { |
| 714 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 715 | } |
| 716 | |
| 717 | $final_recipient = trim($final_recipient); |
| 718 | if ($final_recipient == '' ) { |
| 719 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 720 | } |
| 721 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
| 722 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
| 723 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
| 724 | $message->is_mdnsent = true; |
| 725 | $messages[$uidvalidity][$passed_id]=$message; |
| 726 | } |
| 727 | ClearAttachments(); |
| 728 | } |
| 729 | } |
| 730 | /***********************************************/ |
| 731 | /* End of block for handling incoming url vars */ |
| 732 | /***********************************************/ |
| 733 | |
| 734 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
| 735 | |
| 736 | $messagebody = ''; |
| 737 | do_hook('read_body_top'); |
| 738 | if ($show_html_default == 1) { |
| 739 | $ent_ar = $message->findDisplayEntity(array()); |
| 740 | } else { |
| 741 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
| 742 | } |
| 743 | $cnt = count($ent_ar); |
| 744 | for ($i = 0; $i < $cnt; $i++) { |
| 745 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
| 746 | if ($i != $cnt-1) { |
| 747 | $messagebody .= '<hr noshade size=1>'; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | displayPageHeader($color, $mailbox); |
| 752 | formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
| 753 | formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
| 754 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
| 755 | echo ' <tr><td>'; |
| 756 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
| 757 | echo ' <tr><td>'; |
| 758 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
| 759 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
| 760 | echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">'; |
| 761 | echo ' <tr><td><br>' . $messagebody . '</td></td>'; |
| 762 | echo ' </table>'; |
| 763 | echo ' </td></tr>'; |
| 764 | echo ' </table></td></tr>'; |
| 765 | echo ' </table>'; |
| 766 | echo ' </td></tr>'; |
| 767 | |
| 768 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
| 769 | if ($attachmentsdisplay) { |
| 770 | echo ' <tr><td>'; |
| 771 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
| 772 | echo ' <tr><td>'; |
| 773 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
| 774 | echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">'; |
| 775 | echo ' <b>' . _("Attachments") . ':</b>'; |
| 776 | echo ' </td></tr>'; |
| 777 | echo ' <tr><td>'; |
| 778 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
| 779 | echo $attachmentsdisplay; |
| 780 | echo ' </td></tr></table>'; |
| 781 | echo ' </table></td></tr>'; |
| 782 | echo ' </table></td></tr>'; |
| 783 | echo ' </table>'; |
| 784 | echo ' </td></tr>'; |
| 785 | } |
| 786 | echo '</table>'; |
| 787 | |
| 788 | |
| 789 | /* show attached images inline -- if pref'fed so */ |
| 790 | if (($attachment_common_show_images) && |
| 791 | is_array($attachment_common_show_images_list)) { |
| 792 | foreach ($attachment_common_show_images_list as $img) { |
| 793 | $imgurl = '../src/download.php' . |
| 794 | '?' . |
| 795 | 'passed_id=' . urlencode($img['passed_id']) . |
| 796 | '&mailbox=' . urlencode($mailbox) . |
| 797 | '&ent_id=' . urlencode($img['ent_id']) . |
| 798 | '&absolute_dl=true'; |
| 799 | |
| 800 | echo html_tag( 'table', "\n" . |
| 801 | html_tag( 'tr', "\n" . |
| 802 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
| 803 | ) |
| 804 | ) , |
| 805 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | do_hook('read_body_bottom'); |
| 810 | do_hook('html_bottom'); |
| 811 | //$message->clean_up(); |
| 812 | sqimap_logout($imapConnection); |
| 813 | ?> |
| 814 | </body> |
| 815 | </html> |