| 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 | require_once('../src/validate.php'); |
| 16 | require_once('../functions/imap.php'); |
| 17 | require_once('../functions/mime.php'); |
| 18 | require_once('../functions/date.php'); |
| 19 | require_once('../functions/url_parser.php'); |
| 20 | require_once('../functions/smtp.php'); |
| 21 | |
| 22 | /** |
| 23 | * Given an IMAP message id number, this will look it up in the cached |
| 24 | * and sorted msgs array and return the index. Used for finding the next |
| 25 | * and previous messages. |
| 26 | * |
| 27 | * returns the index of the next valid message from the array |
| 28 | */ |
| 29 | function findNextMessage() { |
| 30 | global $msort, $currentArrayIndex, $msgs, $sort; |
| 31 | $result = -1; |
| 32 | |
| 33 | if ($sort == 6) { |
| 34 | if ($currentArrayIndex != 1) { |
| 35 | $result = $currentArrayIndex - 1; |
| 36 | } |
| 37 | } else { |
| 38 | if (!is_array($msort)) { |
| 39 | return -1; |
| 40 | } |
| 41 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 42 | if ($currentArrayIndex == $msgs[$key]['ID']) { |
| 43 | next($msort); |
| 44 | $key = key($msort); |
| 45 | if (isset($key)) |
| 46 | $result = $msgs[$key]['ID']; |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | return ($result); |
| 52 | } |
| 53 | |
| 54 | /** Removes just one address from the list of addresses. */ |
| 55 | function RemoveAddress(&$addr_list, $addr) { |
| 56 | if ($addr != '') { |
| 57 | foreach (array_keys($addr_list, $addr) as $key_to_delete) { |
| 58 | unset($addr_list[$key_to_delete]); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** returns the index of the previous message from the array. */ |
| 64 | function findPreviousMessage() { |
| 65 | global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, |
| 66 | $mailbox, $data_dir, $username; |
| 67 | |
| 68 | $result = -1; |
| 69 | |
| 70 | if ($sort == 6) { |
| 71 | $numMessages = sqimap_get_num_messages($imapConnection, $mailbox); |
| 72 | if ($currentArrayIndex != $numMessages) { |
| 73 | $result = $currentArrayIndex + 1; |
| 74 | } |
| 75 | } else { |
| 76 | if (!is_array($msort)) { |
| 77 | return -1; |
| 78 | } |
| 79 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
| 80 | if ($currentArrayIndex == $msgs[$key]['ID']) { |
| 81 | prev($msort); |
| 82 | $key = key($msort); |
| 83 | if (isset($key)) { |
| 84 | $result = $msgs[$key]['ID']; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | return ($result); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Displays a link to a page where the message is displayed more |
| 95 | * "printer friendly". |
| 96 | */ |
| 97 | function printer_friendly_link() { |
| 98 | global $passed_id, $mailbox, $ent_num, $color, |
| 99 | $pf_subtle_link, |
| 100 | $javascript_on; |
| 101 | |
| 102 | if (strlen(trim($mailbox)) < 1) { |
| 103 | $mailbox = 'INBOX'; |
| 104 | } |
| 105 | |
| 106 | $params = '?passed_ent_id=' . $ent_num . |
| 107 | '&mailbox=' . urlencode($mailbox) . |
| 108 | '&passed_id=' . $passed_id; |
| 109 | |
| 110 | $print_text = _("View Printable Version"); |
| 111 | |
| 112 | if (!$pf_subtle_link) { |
| 113 | /* The link is large, on the bottom of the header panel. */ |
| 114 | $result = '<tr bgcolor="' . $color[0] . '">' . |
| 115 | '<td class="medText" align="right" valign="top">' . |
| 116 | ' ' . |
| 117 | '</td><td class="medText" valign="top" colspan="2">'."\n"; |
| 118 | } else { |
| 119 | /* The link is subtle, below "view full header". */ |
| 120 | $result = "<BR>\n"; |
| 121 | } |
| 122 | |
| 123 | /* Output the link. */ |
| 124 | if ($javascript_on) { |
| 125 | $result .= '<script language="javascript" type="text/javascript">' . "\n" . |
| 126 | '<!--' . "\n" . |
| 127 | " function printFormat() {\n" . |
| 128 | ' window.open("../src/printer_friendly_main.php' . |
| 129 | $params . '","Print","width=800,height=600");' . "\n". |
| 130 | " }\n" . |
| 131 | "// -->\n" . |
| 132 | "</script>\n" . |
| 133 | "<A HREF=\"javascript:printFormat();\">$print_text</A>\n"; |
| 134 | } else { |
| 135 | $result .= '<A TARGET="_blank" HREF="../src/printer_friendly_bottom.php' . |
| 136 | "$params\">$print_text</A>\n"; |
| 137 | } |
| 138 | |
| 139 | if (!$pf_subtle_link) { |
| 140 | /* The link is large, on the bottom of the header panel. */ |
| 141 | $result .= '</td></tr>' . "\n"; |
| 142 | } |
| 143 | |
| 144 | return ($result); |
| 145 | } |
| 146 | |
| 147 | function ServerMDNSupport( $read ) { |
| 148 | /* escaping $ doesn't work -> \x36 */ |
| 149 | $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read ); |
| 150 | return ( $ret ); |
| 151 | } |
| 152 | |
| 153 | function SendMDN ( $recipient , $sender) { |
| 154 | global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME, |
| 155 | $version, $attachments, $identity, $data_dir, $passed_id; |
| 156 | |
| 157 | $header = sqimap_get_message_header($imapConnection, $passed_id, $mailbox); |
| 158 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 159 | |
| 160 | // part 1 (RFC2298) |
| 161 | |
| 162 | $senton = getLongDateString( $header->date ); |
| 163 | $to_array = $header->to; |
| 164 | $to = ''; |
| 165 | foreach ($to_array as $line) { |
| 166 | $to .= " $line "; |
| 167 | } |
| 168 | |
| 169 | $subject = $header->subject; |
| 170 | $now = getLongDateString( time() ); |
| 171 | |
| 172 | $body = _("Your message") . "\r\n\r\n" . |
| 173 | "\t" . _("To:") . ' ' . $to . "\r\n" . |
| 174 | "\t" . _("Subject:") . ' ' . $subject . "\r\n" . |
| 175 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
| 176 | "\r\n" . |
| 177 | sprintf( _("Was displayed on %s"), $now ); |
| 178 | |
| 179 | // part2 (RFC2298) |
| 180 | |
| 181 | $original_recipient = $to; |
| 182 | $original_message_id = $header->message_id; |
| 183 | |
| 184 | $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
| 185 | if ($original_recipient != '') { |
| 186 | $part2 .= "Original-Recipient : $original_recipient\r\n"; |
| 187 | } |
| 188 | $final_recipient = $sender; |
| 189 | $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
| 190 | "Original-Message-ID : $original_message_id\r\n" . |
| 191 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
| 192 | |
| 193 | |
| 194 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
| 195 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 196 | |
| 197 | $fp = fopen( $full_localfilename, 'w'); |
| 198 | fwrite ($fp, $part2); |
| 199 | fclose($fp); |
| 200 | |
| 201 | $newAttachment = array(); |
| 202 | $newAttachment['localfilename'] = $localfilename; |
| 203 | $newAttachment['type'] = "message/disposition-notification"; |
| 204 | $newAttachment['session']=-1; |
| 205 | $attachments[] = $newAttachment; |
| 206 | $MDN_to = trim($recipient); |
| 207 | $reply_id = 0; |
| 208 | |
| 209 | return (SendMessage($MDN_to,'','', _("Read:") . ' ' . $subject, $body,$reply_id, True, 3, -1) ); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | function ToggleMDNflag ( $set ) { |
| 214 | global $imapConnection, $passed_id, $mailbox; |
| 215 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 216 | |
| 217 | $sg = $set?'+':'-'; |
| 218 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
| 219 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
| 220 | $readmessage); |
| 221 | } |
| 222 | |
| 223 | function ClearAttachments() { |
| 224 | global $username, $attachments, $attachment_dir; |
| 225 | |
| 226 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 227 | |
| 228 | $rem_attachments = array(); |
| 229 | foreach ($attachments as $info) { |
| 230 | if ($info->session == -1) { |
| 231 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 232 | if (file_exists($attached_file)) { |
| 233 | unlink($attached_file); |
| 234 | } |
| 235 | } else { |
| 236 | $rem_attachments[] = $info; |
| 237 | } |
| 238 | } |
| 239 | $attachments = rem_attachments; |
| 240 | } |
| 241 | |
| 242 | function formatRecipientString($recipients, $item ) { |
| 243 | global $base_uri, $passed_id, $urlMailbox, $startMessage, $show_more_cc, $echo_more, $echo_less, $show_more, $show_more_bcc, $sort; |
| 244 | |
| 245 | $i = 0; |
| 246 | $url_string = ''; |
| 247 | |
| 248 | if (isset ($recipients[0]) && trim($recipients[0])) { |
| 249 | $string = ''; |
| 250 | $ary = $recipients; |
| 251 | |
| 252 | switch ($item) { |
| 253 | case 'to': |
| 254 | $show = "&show_more=1&show_more_cc=$show_more_cc&show_more_bcc=$show_more_bcc"; |
| 255 | $show_n = "&show_more=0&show_more_cc=$show_more_cc&show_more_bcc=$show_more_bcc"; |
| 256 | break; |
| 257 | case 'cc': |
| 258 | $show = "&show_more=$show_more&show_more_cc=1&show_more_bcc=$show_more_bcc"; |
| 259 | $show_n = "&show_more=$show_more&show_more_cc=0&show_more_bcc=$show_more_bcc"; |
| 260 | $show_more = $show_more_cc; |
| 261 | break; |
| 262 | case 'bcc': |
| 263 | $show = "&show_more=$show_more&show_more_cc=$show_more_cc&show_more_bcc=1"; |
| 264 | $show_n = "&show_more=$show_more&show_more_cc=$show_more_cc&show_more_bcc=0"; |
| 265 | $show_more = $show_more_bcc; |
| 266 | break; |
| 267 | default: |
| 268 | $break; |
| 269 | } |
| 270 | |
| 271 | while ($i < count($ary)) { |
| 272 | $ary[$i] = htmlspecialchars(decodeHeader($ary[$i])); |
| 273 | $url_string .= $ary[$i]; |
| 274 | if ($string) { |
| 275 | $string = "$string<BR>$ary[$i]"; |
| 276 | } else { |
| 277 | $string = "$ary[$i]"; |
| 278 | } |
| 279 | |
| 280 | $i++; |
| 281 | if (count($ary) > 1) { |
| 282 | if ($show_more == false) { |
| 283 | if ($i == 1) { |
| 284 | /* From a search... */ |
| 285 | $string .= ' (<A HREF="' . $base_uri . |
| 286 | "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&"; |
| 287 | if (isset($where) && isset($what)) { |
| 288 | $string .= 'what=' . urlencode($what)."&where=".urlencode($where)."$show\">$echo_more</A>)"; |
| 289 | } else { |
| 290 | $string .= "sort=$sort&startMessage=$startMessage"."$show\">$echo_more</A>)"; |
| 291 | } |
| 292 | $i = count($ary); |
| 293 | } |
| 294 | } else if ($i == 1) { |
| 295 | /* From a search... */ |
| 296 | $string .= ' (<A HREF="' . $base_uri . |
| 297 | "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&"; |
| 298 | if (isset($where) && isset($what)) { |
| 299 | $string .= 'what=' . urlencode($what)."&where=".urlencode($where)."$show_n\">$echo_less</A>)"; |
| 300 | } else { |
| 301 | $string .= "sort=$sort&startMessage=$startMessage"."$show_n\">$echo_less</A>)"; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | } |
| 307 | } |
| 308 | else { |
| 309 | $string = ''; |
| 310 | } |
| 311 | $url_string = urlencode($url_string); |
| 312 | $result = array(); |
| 313 | $result['str'] = $string; |
| 314 | $result['url_str'] = $url_string; |
| 315 | return $result; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | |
| 320 | /* |
| 321 | * Main of read_boby.php -------------------------------------------------- |
| 322 | */ |
| 323 | |
| 324 | /* |
| 325 | Urled vars |
| 326 | ---------- |
| 327 | $passed_id |
| 328 | */ |
| 329 | |
| 330 | if ( isset( $mailbox ) ) { |
| 331 | $mailbox = urldecode( $mailbox ); |
| 332 | } |
| 333 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 334 | $read = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 335 | |
| 336 | do_hook('html_top'); |
| 337 | |
| 338 | /* |
| 339 | * The following code sets necesarry stuff for the MDN thing |
| 340 | */ |
| 341 | if( $default_use_mdn && |
| 342 | ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) { |
| 343 | |
| 344 | $supportMDN = ServerMDNSupport($read["PERMANENTFLAGS"]); |
| 345 | $flags = sqimap_get_flags ($imapConnection, $passed_id); |
| 346 | $FirstTimeSee = !(in_array( 'Seen', $flags )); |
| 347 | } |
| 348 | |
| 349 | displayPageHeader($color, $mailbox); |
| 350 | |
| 351 | |
| 352 | /* |
| 353 | * The following code shows the header of the message and then exit |
| 354 | */ |
| 355 | if (isset($view_hdr)) { |
| 356 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", true, $a, $b); |
| 357 | |
| 358 | echo '<BR>' . |
| 359 | '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" . |
| 360 | " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>" . _("Viewing Full Header") . '</B> - '. |
| 361 | '<a href="' . $base_uri . "src/read_body.php?mailbox=".urlencode($mailbox); |
| 362 | if (isset($where) && isset($what)) { |
| 363 | // Got here from a search |
| 364 | echo "&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">'; |
| 365 | } else { |
| 366 | echo "&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">"; |
| 367 | } |
| 368 | echo _("View message") . "</a></b></td></tr></table>\n" . |
| 369 | "<table width=\"99%\" cellpadding=2 cellspacing=0 border=0 align=center>\n" . |
| 370 | '<tr><td>'; |
| 371 | |
| 372 | $cnum = 0; |
| 373 | for ($i=1; $i < count($read); $i++) { |
| 374 | $line = htmlspecialchars($read[$i]); |
| 375 | if (eregi("^>", $line)) { |
| 376 | $second[$i] = $line; |
| 377 | $first[$i] = ' '; |
| 378 | $cnum++; |
| 379 | } else if (eregi("^[ |\t]", $line)) { |
| 380 | $second[$i] = $line; |
| 381 | $first[$i] = ''; |
| 382 | } else if (eregi("^([^:]+):(.+)", $line, $regs)) { |
| 383 | $first[$i] = $regs[1] . ':'; |
| 384 | $second[$i] = $regs[2]; |
| 385 | $cnum++; |
| 386 | } else { |
| 387 | $second[$i] = trim($line); |
| 388 | $first[$i] = ''; |
| 389 | } |
| 390 | } |
| 391 | for ($i=0; $i < count($second); $i = $j) { |
| 392 | if (isset($first[$i])) { |
| 393 | $f = $first[$i]; |
| 394 | } |
| 395 | if (isset($second[$i])) { |
| 396 | $s = nl2br($second[$i]); |
| 397 | } |
| 398 | $j = $i + 1; |
| 399 | while (($first[$j] == '') && ($j < count($first))) { |
| 400 | $s .= ' ' . nl2br($second[$j]); |
| 401 | $j++; |
| 402 | } |
| 403 | parseEmail($s); |
| 404 | if (isset($f)) { |
| 405 | echo "<nobr><tt><b>$f</b>$s</tt></nobr>"; |
| 406 | } |
| 407 | } |
| 408 | echo "</td></tr></table>\n" . |
| 409 | '</body></html>'; |
| 410 | sqimap_logout($imapConnection); |
| 411 | exit; |
| 412 | } |
| 413 | |
| 414 | if (isset($msgs)) { |
| 415 | $currentArrayIndex = $passed_id; |
| 416 | } else { |
| 417 | $currentArrayIndex = -1; |
| 418 | } |
| 419 | |
| 420 | for ($i = 0; $i < count($msgs); $i++) { |
| 421 | if ($msgs[$i]['ID'] == $passed_id) { |
| 422 | $msgs[$i]['FLAG_SEEN'] = true; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // $message contains all information about the message |
| 427 | // including header and body |
| 428 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
| 429 | |
| 430 | /** translate the subject and mailbox into url-able text **/ |
| 431 | $url_subj = urlencode(trim($message->header->subject)); |
| 432 | $urlMailbox = urlencode($mailbox); |
| 433 | $url_replyto = ''; |
| 434 | if (isset($message->header->replyto)) { |
| 435 | $url_replyto = urlencode($message->header->replyto); |
| 436 | } |
| 437 | |
| 438 | $url_replytoall = $url_replyto; |
| 439 | |
| 440 | // If we are replying to all, then find all other addresses and |
| 441 | // add them to the list. Remove duplicates. |
| 442 | // This is somewhat messy, so I'll explain: |
| 443 | // 1) Take all addresses (from, to, cc) (avoid nasty join errors here) |
| 444 | $url_replytoall_extra_addrs = array_merge( |
| 445 | array($message->header->from), |
| 446 | $message->header->to, |
| 447 | $message->header->cc |
| 448 | ); |
| 449 | |
| 450 | // 2) Make one big string out of them |
| 451 | $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs); |
| 452 | |
| 453 | // 3) Parse that into an array of addresses |
| 454 | $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs); |
| 455 | |
| 456 | // 4) Make them unique -- weed out duplicates |
| 457 | // (Coded for PHP 4.0.0) |
| 458 | $url_replytoall_extra_addrs = |
| 459 | array_keys(array_flip($url_replytoall_extra_addrs)); |
| 460 | |
| 461 | // 5) Remove the addresses we'll be sending the message 'to' |
| 462 | $url_replytoall_avoid_addrs = ''; |
| 463 | if (isset($message->header->replyto)) { |
| 464 | $url_replytoall_avoid_addrs = $message->header->replyto; |
| 465 | } |
| 466 | |
| 467 | $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs); |
| 468 | foreach ($url_replytoall_avoid_addrs as $addr) { |
| 469 | RemoveAddress($url_replytoall_extra_addrs, $addr); |
| 470 | } |
| 471 | |
| 472 | // 6) Remove our identities from the CC list (they still can be in the |
| 473 | // TO list) only if $include_self_reply_all is turned off |
| 474 | if (!$include_self_reply_all) { |
| 475 | RemoveAddress($url_replytoall_extra_addrs, |
| 476 | getPref($data_dir, $username, 'email_address')); |
| 477 | $idents = getPref($data_dir, $username, 'identities'); |
| 478 | if ($idents != '' && $idents > 1) { |
| 479 | for ($i = 1; $i < $idents; $i ++) { |
| 480 | $cur_email_address = getPref($data_dir, $username, 'email_address' . $i); |
| 481 | RemoveAddress($url_replytoall_extra_addrs, $cur_email_address); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | // 7) Smoosh back into one nice line |
| 487 | $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs); |
| 488 | |
| 489 | // 8) urlencode() it |
| 490 | $url_replytoallcc = urlencode($url_replytoallcc); |
| 491 | |
| 492 | $dateString = getLongDateString($message->header->date); |
| 493 | |
| 494 | // What do we reply to -- text only, if possible |
| 495 | $ent_num = findDisplayEntity($message); |
| 496 | |
| 497 | /** TEXT STRINGS DEFINITIONS **/ |
| 498 | $echo_more = _("more"); |
| 499 | $echo_less = _("less"); |
| 500 | |
| 501 | if (!isset($show_more_cc)) { |
| 502 | $show_more_cc = FALSE; |
| 503 | } |
| 504 | |
| 505 | if (!isset($show_more_bcc)) { |
| 506 | $show_more_bcc = FALSE; |
| 507 | } |
| 508 | |
| 509 | /** FORMAT THE TO STRING **/ |
| 510 | $to = formatRecipientString($message->header->to, "to"); |
| 511 | $to_string = $to['str']; |
| 512 | $url_to_string = $to['url_str']; |
| 513 | |
| 514 | |
| 515 | /** FORMAT THE CC STRING **/ |
| 516 | |
| 517 | $cc = formatRecipientString($message->header->cc, "cc"); |
| 518 | $cc_string = $cc['str']; |
| 519 | $url_cc_string = $cc['url_str']; |
| 520 | |
| 521 | /** FORMAT THE BCC STRING **/ |
| 522 | |
| 523 | $bcc = formatRecipientString($message->header->bcc, "bcc"); |
| 524 | $bcc_string = $bcc['str']; |
| 525 | $url_bcc_string = $bcc['url_str']; |
| 526 | |
| 527 | if ($default_use_priority) { |
| 528 | $priority_level = substr($message->header->priority,0,1); |
| 529 | |
| 530 | switch($priority_level) { |
| 531 | /* check for a higher then normal priority. */ |
| 532 | case '1': |
| 533 | case '2': |
| 534 | $priority_string = _("High"); |
| 535 | break; |
| 536 | |
| 537 | /* check for a lower then normal priority. */ |
| 538 | case '4': |
| 539 | case '5': |
| 540 | $priority_string = _("Low"); |
| 541 | break; |
| 542 | |
| 543 | /* check for a normal priority. */ |
| 544 | case '3': |
| 545 | default: |
| 546 | $priority_level = '3'; |
| 547 | $priority_string = _("Normal"); |
| 548 | break; |
| 549 | |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /** make sure everything will display in HTML format **/ |
| 554 | $from_name = decodeHeader(htmlspecialchars($message->header->from)); |
| 555 | $subject = decodeHeader(htmlspecialchars($message->header->subject)); |
| 556 | |
| 557 | do_hook('read_body_top'); |
| 558 | echo '<BR>' . |
| 559 | '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . |
| 560 | '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' . |
| 561 | '<TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' . |
| 562 | '<TR>' . |
| 563 | '<TD ALIGN="LEFT" WIDTH="33%">' . |
| 564 | '<SMALL>' . |
| 565 | '<A HREF="' . $base_uri . 'src/'; |
| 566 | |
| 567 | if ($where && $what) { |
| 568 | if( $pos == '' ) { |
| 569 | $pos = 0; |
| 570 | } |
| 571 | echo "search.php?where$pos=".urlencode($where)."&pos=$pos&what$pos=".urlencode($what)."&mailbox=$urlMailbox\">"; |
| 572 | } else { |
| 573 | echo "right_main.php?sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">"; |
| 574 | } |
| 575 | echo _("Message List") . |
| 576 | '</A> | ' . |
| 577 | '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&message=$passed_id&"; |
| 578 | if ($where && $what) { |
| 579 | echo 'where=' . urlencode($where) . '&what=' . urlencode($what) . '">'; |
| 580 | } else { |
| 581 | echo "sort=$sort&startMessage=$startMessage\">"; |
| 582 | } |
| 583 | echo _("Delete") . '</A> '; |
| 584 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
| 585 | echo '| <A HREF="' . $base_uri . |
| 586 | "src/compose.php?mailbox=$mailbox&send_to=$url_to_string&send_to_cc=$url_cc_string&send_to_bcc=$url_bcc_string&subject=$url_subj&draft_id=$passed_id&ent_num=$ent_num" . '"'; |
| 587 | if ($compose_new_win == '1') { |
| 588 | echo 'TARGET="compose_window" onClick="comp_in_new()"'; |
| 589 | } |
| 590 | echo '>'. |
| 591 | _("Resume Draft") . '</a>'; |
| 592 | } |
| 593 | |
| 594 | echo ' ' . |
| 595 | '</SMALL>' . |
| 596 | '</TD>' . |
| 597 | '<TD WIDTH="33%" ALIGN="CENTER">' . |
| 598 | '<SMALL>'; |
| 599 | |
| 600 | if ( !($where && $what) ) { |
| 601 | |
| 602 | if ($currentArrayIndex == -1) { |
| 603 | echo 'Previous | Next'; |
| 604 | } else { |
| 605 | $prev = findPreviousMessage(); |
| 606 | $next = findNextMessage(); |
| 607 | |
| 608 | if ($prev != -1) { |
| 609 | echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | "; |
| 610 | } else { |
| 611 | echo _("Previous") . ' | '; |
| 612 | } |
| 613 | |
| 614 | if ($next != -1) { |
| 615 | echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>"; |
| 616 | } else { |
| 617 | echo _("Next"); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | echo '</SMALL>' . |
| 623 | '</TD><TD WIDTH="33%" ALIGN="RIGHT">' . |
| 624 | '<SMALL>' . |
| 625 | '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&forward_subj=$url_subj&". |
| 626 | ($default_use_priority?"mailprio=$priority_level&":'') |
| 627 | ."mailbox=$urlMailbox&ent_num=$ent_num\""; |
| 628 | if ($compose_new_win == '1') { |
| 629 | echo 'TARGET="compose_window" onClick="comp_in_new()"'; |
| 630 | } |
| 631 | echo '>'. |
| 632 | _("Forward") . |
| 633 | '</A> | ' . |
| 634 | '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&reply_subj=$url_subj&". |
| 635 | ($default_use_priority?"mailprio=$priority_level&":''). |
| 636 | "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\""; |
| 637 | if ($compose_new_win == '1') { |
| 638 | echo 'TARGET="compose_window" onClick="comp_in_new()"'; |
| 639 | } |
| 640 | echo '>'. |
| 641 | _("Reply") . |
| 642 | '</A> | ' . |
| 643 | '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&". |
| 644 | ($default_use_priority?"mailprio=$priority_level&":''). |
| 645 | "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\""; |
| 646 | if ($compose_new_win == '1') { |
| 647 | echo 'TARGET="compose_window" onClick="comp_in_new()"'; |
| 648 | } |
| 649 | echo '>'. |
| 650 | _("Reply All") . |
| 651 | '</A> ' . |
| 652 | '</SMALL>' . |
| 653 | '</TD>' . |
| 654 | '</TR>' . |
| 655 | '</TABLE>' . |
| 656 | '</TD></TR>' . |
| 657 | '<TR><TD WIDTH="100%">' . |
| 658 | '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" . |
| 659 | '<TR>' . "\n"; |
| 660 | |
| 661 | /** subject **/ |
| 662 | echo "<TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" . |
| 663 | _("Subject:") . |
| 664 | "</TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" . |
| 665 | "<B>$subject</B> \n" . |
| 666 | "</TD>\n" . |
| 667 | '<TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] . |
| 668 | '" ALIGN=right VALIGN=top NOWRAP><small>'. |
| 669 | '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&"; |
| 670 | |
| 671 | /* From a search... */ |
| 672 | if ($where && $what) { |
| 673 | echo 'where=' . urlencode($where) . '&what=' . urlencode($what) . |
| 674 | "&view_hdr=1\">" . _("View Full Header") . "</A>\n"; |
| 675 | } else { |
| 676 | echo "startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" . |
| 677 | _("View Full Header") . "</A>\n"; |
| 678 | } |
| 679 | |
| 680 | /* Output the printer friendly link if we are in subtle mode. */ |
| 681 | if ($pf_subtle_link) { |
| 682 | echo printer_friendly_link(true); |
| 683 | } |
| 684 | |
| 685 | do_hook("read_body_header_right"); |
| 686 | echo '</small></TD>' . |
| 687 | ' </TR>'; |
| 688 | |
| 689 | /** from **/ |
| 690 | echo '<TR>' . |
| 691 | '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . |
| 692 | _("From:") . |
| 693 | '</TD><TD BGCOLOR="' . $color[0] . '">' . |
| 694 | "<B>$from_name</B> \n" . |
| 695 | '</TD>' . |
| 696 | '</TR>'; |
| 697 | /** date **/ |
| 698 | echo '<TR>' . "\n" . |
| 699 | '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" . |
| 700 | _("Date:") . |
| 701 | "</TD><TD BGCOLOR=\"$color[0]\">\n" . |
| 702 | "<B>$dateString</B> \n" . |
| 703 | '</TD>' . "\n" . |
| 704 | '</TR>' . "\n"; |
| 705 | |
| 706 | /** to **/ |
| 707 | echo "<TR>\n" . |
| 708 | "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" . |
| 709 | _("To:") . |
| 710 | '</TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" . |
| 711 | "<B>$to_string</B> \n" . |
| 712 | '</TD>' . "\n" . |
| 713 | '</TR>' . "\n"; |
| 714 | /** cc **/ |
| 715 | if (isset($cc_string) && $cc_string <> '') { |
| 716 | echo '<TR>' . |
| 717 | "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 718 | 'Cc:' . |
| 719 | "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" . |
| 720 | "<B>$cc_string</B> " . |
| 721 | '</TD>' . |
| 722 | '</TR>' . "\n"; |
| 723 | } |
| 724 | |
| 725 | /** bcc **/ |
| 726 | if (isset($bcc_string) && $bcc_string <> '') { |
| 727 | echo '<TR>'. |
| 728 | "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 729 | 'Bcc:' . |
| 730 | "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" . |
| 731 | "<B>$bcc_string</B> " . |
| 732 | '</TD>' . |
| 733 | '</TR>' . "\n"; |
| 734 | } |
| 735 | if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) { |
| 736 | echo '<TR>' . |
| 737 | "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 738 | _("Priority") . ': '. |
| 739 | "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" . |
| 740 | "<B>$priority_string</B> " . |
| 741 | '</TD>' . |
| 742 | "</TR>" . "\n"; |
| 743 | } |
| 744 | |
| 745 | if ($show_xmailer_default) { |
| 746 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]", true, |
| 747 | $response, $readmessage); |
| 748 | $mailer = substr($read[1], strpos($read[1], " ")); |
| 749 | if (trim($mailer)) { |
| 750 | echo '<TR>' . |
| 751 | "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 752 | _("Mailer") . ': '. |
| 753 | "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" . |
| 754 | "<B>$mailer</B> " . |
| 755 | '</TD>' . |
| 756 | "</TR>" . "\n"; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | /* Output the printer friendly link if we are not in subtle mode. */ |
| 761 | if (!$pf_subtle_link) { |
| 762 | echo printer_friendly_link(true); |
| 763 | } |
| 764 | |
| 765 | if ($default_use_mdn) { |
| 766 | if ($mdn_user_support) { |
| 767 | |
| 768 | // debug gives you the capability to remove mdn-flags |
| 769 | // $MDNDebug = false; |
| 770 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true, |
| 771 | $response, $readmessage); |
| 772 | $MDN_to = substr($read[1], strpos($read[1], ' ')); |
| 773 | $MDN_flag_present = false; |
| 774 | |
| 775 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true, |
| 776 | $response, $readmessage); |
| 777 | |
| 778 | $MDN_flag_present = preg_match( '/.*\$MDNSent/i', $read[0]); |
| 779 | |
| 780 | if (trim($MDN_to) && |
| 781 | (!isset( $sendreceipt ) || $sendreceipt == '' ) ) { |
| 782 | |
| 783 | if ( $MDN_flag_present && $supportMDN) { |
| 784 | $sendreceipt = 'removeMDN'; |
| 785 | $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; |
| 786 | $sendreceipt=''; |
| 787 | /* |
| 788 | if ($MDNDebug ) { |
| 789 | echo '<TR>' . |
| 790 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 791 | _("Read receipt") . ': ' . |
| 792 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 793 | '<B>' . |
| 794 | _("send") . |
| 795 | "</B> <a href=$url>[" . _("Remove MDN flag") . '] </a>' . |
| 796 | '</TD>' . |
| 797 | '</TR>' . "\n"; |
| 798 | } else { |
| 799 | */ |
| 800 | echo '<TR>' . |
| 801 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 802 | _("Read receipt") . ': ' . |
| 803 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 804 | '<B>'._("send").'</B>'. |
| 805 | '</TD>' . |
| 806 | '</TR>' . "\n"; |
| 807 | /* |
| 808 | } |
| 809 | */ |
| 810 | |
| 811 | } // when deleted or draft flag is set don't offer to send a MDN response |
| 812 | else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) { |
| 813 | echo '<TR>' . |
| 814 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 815 | _("Read receipt") . ': '. |
| 816 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 817 | '<B>' . _("requested") . "</B>" . |
| 818 | '</TD>' . |
| 819 | '</TR>' . "\n"; |
| 820 | } |
| 821 | // if no MDNsupport don't use the annoying popup messages |
| 822 | else if ( !$FirstTimeSee ) { |
| 823 | $sendreceipt = 'send'; |
| 824 | $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; |
| 825 | echo '<TR>' . |
| 826 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 827 | _("Read receipt") . ': ' . |
| 828 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 829 | '<B>' . _("requested") . |
| 830 | "</B> <a href=$url>[" . _("Send read receipt now") . "]</a>" . |
| 831 | '</TD>' . |
| 832 | '</TR>' . "\n"; |
| 833 | $sendreceipt=''; |
| 834 | } |
| 835 | else { |
| 836 | $sendreceipt = 'send'; |
| 837 | $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; |
| 838 | if ($javascript_on) { |
| 839 | echo "<script language=\"javascript\" type=\"text/javascript\"> \n" . |
| 840 | '<!-- ' . "\n" . |
| 841 | " if (window.confirm(\"" . |
| 842 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
| 843 | "\")) { \n" . |
| 844 | " window.location=($url); \n" . |
| 845 | ' window.reload()' . "\n" . |
| 846 | ' }' . "\n" . |
| 847 | '// -->' . "\n" . |
| 848 | '</script>' . "\n"; |
| 849 | } |
| 850 | echo '<TR>' . |
| 851 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 852 | _("Read receipt") . ': ' . |
| 853 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 854 | '<B>' . _("requested") . "  </B><a href=$url>" . '[' . |
| 855 | _("Send read receipt now") . '] </a>' ." \n" . |
| 856 | '</TD>' . |
| 857 | '</TR>' . "\n"; |
| 858 | $sendreceipt = ''; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | if ( !isset( $sendreceipt ) || $sendreceipt == '' ) { |
| 863 | } else if ( $sendreceipt == 'send' ) { |
| 864 | if ( !$MDN_flag_present) { |
| 865 | if (isset($identity) ) { |
| 866 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
| 867 | } else { |
| 868 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 869 | } |
| 870 | |
| 871 | $final_recipient = trim($final_recipient); |
| 872 | if ($final_recipient == '' ) { |
| 873 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
| 874 | } |
| 875 | |
| 876 | if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN ) { |
| 877 | ToggleMDNflag( true); |
| 878 | } |
| 879 | } |
| 880 | $sendreceipt = 'removeMDN'; |
| 881 | $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; |
| 882 | $sendreceipt=''; |
| 883 | /* |
| 884 | if ($MDNDebug && $supportMDN) { |
| 885 | echo " <TR>\n" . |
| 886 | " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" . |
| 887 | " "._("Read receipt").": \n". |
| 888 | " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" . |
| 889 | ' <B>'._("send").'</B>'." <a href=$url>" . '[' . _("Remove MDN flag") . '] </a>' . "\n" . |
| 890 | ' </TD>' . "\n" . |
| 891 | ' </TR>' . "\n"; |
| 892 | } else { |
| 893 | */ |
| 894 | echo " <TR>\n" . |
| 895 | " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" . |
| 896 | " "._("Read receipt").": \n". |
| 897 | " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" . |
| 898 | ' <B>'._("send").'</B>'. "\n" . |
| 899 | ' </TD>' . "\n" . |
| 900 | ' </TR>' . "\n"; |
| 901 | /* |
| 902 | } |
| 903 | */ |
| 904 | } |
| 905 | elseif ($sendreceipt == 'removeMDN' ) { |
| 906 | ToggleMDNflag ( false ); |
| 907 | |
| 908 | $sendreceipt = 'send'; |
| 909 | $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; |
| 910 | echo '<TR>'. |
| 911 | "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" . |
| 912 | _("Read receipt") . ': ' . |
| 913 | "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" . |
| 914 | '<B>' . _("requested") . |
| 915 | "</B> <a href=$url>[" . _("Send read receipt now") . "]</a>" . |
| 916 | '</TD>' . |
| 917 | '</TR>' . "\n"; |
| 918 | $sendreceipt = ''; |
| 919 | |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | do_hook('read_body_header'); |
| 925 | |
| 926 | echo '</TABLE>' . |
| 927 | ' </TD></TR>' . |
| 928 | '</TABLE>'; |
| 929 | flush(); |
| 930 | |
| 931 | echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" . |
| 932 | " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" . |
| 933 | '<BR>'. |
| 934 | formatBody($imapConnection, $message, $color, $wrap_at). |
| 935 | '</TD></TR></TABLE>' . |
| 936 | '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" . |
| 937 | " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>" . |
| 938 | '</TABLE>' . "\n"; |
| 939 | |
| 940 | /* show attached images inline -- if pref'fed so */ |
| 941 | if (($attachment_common_show_images) && |
| 942 | is_array($attachment_common_show_images_list)) { |
| 943 | |
| 944 | foreach ($attachment_common_show_images_list as $img) { |
| 945 | $imgurl = '../src/download.php' . |
| 946 | '?' . |
| 947 | 'passed_id=' . urlencode($img['passed_id']) . |
| 948 | '&mailbox=' . urlencode($mailbox) . |
| 949 | '&passed_ent_id=' . urlencode($img['ent_id']) . |
| 950 | '&absolute_dl=true'; |
| 951 | |
| 952 | echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" . |
| 953 | '<TR>' . |
| 954 | '<TD>' . |
| 955 | "<img src=\"$imgurl\">\n" . |
| 956 | "</TD>\n" . |
| 957 | "</TR>\n" . |
| 958 | "</TABLE>\n"; |
| 959 | |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | |
| 964 | do_hook('read_body_bottom'); |
| 965 | do_hook('html_bottom'); |
| 966 | sqimap_logout($imapConnection); |
| 967 | ?> |
| 968 | </body> |
| 969 | </html> |