-<?
- include("../config/config.php");
- include("../functions/strings.php");
- include("../functions/page_header.php");
- include("../functions/imap.php");
- include("../functions/mailbox.php");
- include("../functions/date.php");
-
- $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
- selectMailbox($imapConnection, $mailbox, $numMessages);
-
- echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">\n";
- displayPageHeader($mailbox);
- $body = fetchBody($imapConnection, $passed_id);
- getMessageHeaders($imapConnection, $passed_id, $passed_id, $f, $s, $d);
-// setMessageFlag($imapConnection, $passed_id, $passed_id, "Seen");
-
- $subject = $s[0];
- $d[0] = ereg_replace(" ", " ", $d[0]);
-// $date = explode(" ", trim($d[0]));
-// $date = getDateString($date);
- $date = $d[0];
- $from_name = getSenderName($f[0]);
+<?php
+ /**
+ ** read_body.php
+ **
+ ** Copyright (c) 1999-2000 The SquirrelMail development team
+ ** Licensed under the GNU GPL. For full terms see the file COPYING.
+ **
+ ** This file is used for reading the msgs array and displaying
+ ** the resulting emails in the right frame.
+ **/
+
+ session_start();
+
+ if (!isset($config_php))
+ include("../config/config.php");
+ if (!isset($strings_php))
+ include("../functions/strings.php");
+ if (!isset($page_header_php))
+ include("../functions/page_header.php");
+ if (!isset($imap_php))
+ include("../functions/imap.php");
+ if (!isset($mime_php))
+ include("../functions/mime.php");
+ if (!isset($date_php))
+ include("../functions/date.php");
+
+ include("../src/load_prefs.php");
+ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+ sqimap_mailbox_select($imapConnection, $mailbox);
+ displayPageHeader($color, $mailbox);
+
+ if ($view_hdr) {
+ fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
+ $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
+
+ echo "<br>";
+ echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n";
+ echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
+ if ($where && $what) {
+ // Got here from a search
+ echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
+ } else {
+ echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
+ }
+ echo ""._("View message") . "</a></b></center></td></tr></table>\n";
+ echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
+ echo "<tr><td><pre>";
+ for ($i=1; $i < count($read)-1; $i++) {
+ $read[$i] = htmlspecialchars($read[$i]);
+ if (substr($read[$i], 0, 1) != "\t" &&
+ substr($read[$i], 0, 1) != " " &&
+ substr($read[$i], 0, 1) != "&" &&
+ trim($read[$i])) {
+ $pre = substr($read[$i], 0, strpos($read[$i], ":"));
+ $read[$i] = str_replace("$pre", "<b>$pre</b>", decodeHeader($read[$i]));
+ }
+ echo "$read[$i]";
+ }
+ echo "</pre></td></tr></table>\n";
+ echo "</body></html>";
+ exit;
+ }
+
+ // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
+ // return the index. used for finding the next and previous messages
+
+ // returns the index of the next valid message from the array
+ function findNextMessage() {
+ global $msort, $currentArrayIndex, $msgs;
+ for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
+ if ($currentArrayIndex == $msgs[$key]["ID"]) {
+ next($msort);
+ $key = key($msort);
+ if (isset($key))
+ return $msgs[$key]["ID"];
+ }
+ }
+ return -1;
+ }
+
+ // returns the index of the previous message from the array
+ function findPreviousMessage() {
+ global $msort, $currentArrayIndex, $msgs;
+ for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
+ if ($currentArrayIndex == $msgs[$key]["ID"]) {
+ prev($msort);
+ $key = key($msort);
+ if (isset($key))
+ return $msgs[$key]["ID"];
+ }
+ }
+ return -1;
+ }
+
+ if (isset($msgs)) {
+ $currentArrayIndex = $passed_id;
+ /*
+ for ($i=0; $i < count($msgs); $i++) {
+ if ($msgs[$i]["ID"] == $passed_id) {
+ $currentArrayIndex = $i;
+ break;
+ }
+ }
+ */
+ } else {
+ $currentArrayIndex = -1;
+ }
+
+ for ($i = 0; $i < count($msgs); $i++) {
+ if ($msgs[$i]["ID"] == $passed_id)
+ $msgs[$i]["FLAG_SEEN"] = true;
+ }
+
+ // $message contains all information about the message
+ // including header and body
+ $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+
+ /** translate the subject and mailbox into url-able text **/
+ $url_subj = urlencode(trim(stripslashes($message->header->subject)));