+ do_hook('html_top');
+ displayPageHeader($color, $mailbox);
+
+ if (isset($view_hdr)) {
+ fputs ($imapConnection, sqimap_session_id() . " FETCH $passed_id BODY[HEADER]\r\n");
+ $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $a, $b);
+
+ echo '<br>' .
+ '<table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">' . "\n" .
+ " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . '</b> - ';
+ if (isset($where) && isset($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" .
+ "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n" .
+ '<tr><td>';
+
+ $cnum = 0;
+ for ($i=1; $i < count($read); $i++) {
+ $line = htmlspecialchars($read[$i]);
+ if (eregi("^>", $line)) {
+ $second[$i] = $line;
+ $first[$i] = ' ';
+ $cnum++;
+ } else if (eregi("^[ |\t]", $line)) {
+ $second[$i] = $line;
+ $first[$i] = '';
+ } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
+ $first[$i] = $regs[1] . ':';
+ $second[$i] = $regs[2];
+ $cnum++;
+ } else {
+ $second[$i] = trim($line);
+ $first[$i] = '';
+ }
+ }
+ for ($i=0; $i < count($second); $i = $j) {
+ if (isset($first[$i]))
+ $f = $first[$i];
+ if (isset($second[$i]))
+ $s = nl2br($second[$i]);
+ $j = $i + 1;
+ while ($first[$j] == '' && $j < count($first)) {
+ $s .= ' ' . nl2br($second[$j]);
+ $j++;
+ }
+ parseEmail($s);
+ if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
+ }
+ echo "</td></tr></table>\n";
+ echo '</body></html>';
+ sqimap_logout($imapConnection);
+ 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, $sort;
+
+ if ($sort == 6) {
+ if ($currentArrayIndex != 1) {
+ return $currentArrayIndex - 1;
+ }
+ } else {
+ 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;
+ }
+
+ // Removes just one address from the list of addresses
+ function RemoveAddress(&$addr_list, $addr) {
+ if ($addr == '')
+ return;
+ foreach (array_keys($addr_list, $addr) as $key_to_delete)
+ {
+ unset($addr_list[$key_to_delete]);
+ }
+ }
+
+
+ // returns the index of the previous message from the array
+ function findPreviousMessage() {
+ global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
+ $mailbox, $data_dir, $username;
+ if ($sort == 6) {
+ $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
+ if ($currentArrayIndex != $numMessages) {
+ return $currentArrayIndex + 1;
+ }
+ } else {
+ 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;
+ }