5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This file is used for reading the msgs array and displaying
9 ** the resulting emails in the right frame.
14 if (!isset($config_php))
15 include("../config/config.php");
16 if (!isset($strings_php))
17 include("../functions/strings.php");
18 if (!isset($page_header_php))
19 include("../functions/page_header.php");
20 if (!isset($imap_php))
21 include("../functions/imap.php");
22 if (!isset($mime_php))
23 include("../functions/mime.php");
24 if (!isset($date_php))
25 include("../functions/date.php");
26 if (!isset($url_parser_php))
27 include("../functions/url_parser.php");
29 include("../src/load_prefs.php");
30 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
31 sqimap_mailbox_select($imapConnection, $mailbox);
33 displayPageHeader($color, $mailbox);
36 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
37 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
40 echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n";
41 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
42 if ($where && $what) {
43 // Got here from a search
44 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
46 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
48 echo ""._("View message") . "</a></b></center></td></tr></table>\n";
49 echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
52 for ($i=1; $i < count($read)-1; $i++
) {
53 $line = htmlspecialchars($read[$i]);
54 if (eregi("^>", $line)) {
56 $first[$i] = " ";
58 } else if (eregi("^[ |\t]", $line)) {
61 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
62 $first[$i] = $regs[1] . ":";
63 $second[$i] = $regs[2];
66 $second[$i] = trim($line);
70 for ($i=0; $i < count($second); $i = $j) {
72 $s = nl2br($second[$i]);
74 while ($first[$j] == "" && $j < count($first)) {
75 $s .= " " . nl2br($second[$j]);
79 echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
81 echo "</td></tr></table>\n";
82 echo "</body></html>";
83 sqimap_logout($imapConnection);
87 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
88 // return the index. used for finding the next and previous messages
90 // returns the index of the next valid message from the array
91 function findNextMessage() {
92 global $msort, $currentArrayIndex, $msgs, $sort;
95 if ($currentArrayIndex != 1) {
96 return $currentArrayIndex - 1;
99 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
100 if ($currentArrayIndex == $msgs[$key]["ID"]) {
104 return $msgs[$key]["ID"];
111 // returns the index of the previous message from the array
112 function findPreviousMessage() {
113 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox;
115 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
116 if ($currentArrayIndex != $numMessages) {
117 return $currentArrayIndex +
1;
120 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
121 if ($currentArrayIndex == $msgs[$key]["ID"]) {
125 return $msgs[$key]["ID"];
133 $currentArrayIndex = $passed_id;
135 for ($i=0; $i < count($msgs); $i++) {
136 if ($msgs[$i]["ID"] == $passed_id) {
137 $currentArrayIndex = $i;
143 $currentArrayIndex = -1;
146 for ($i = 0; $i < count($msgs); $i++
) {
147 if ($msgs[$i]["ID"] == $passed_id)
148 $msgs[$i]["FLAG_SEEN"] = true;
151 // $message contains all information about the message
152 // including header and body
153 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
155 /** translate the subject and mailbox into url-able text **/
156 $url_subj = urlencode(trim(sqStripSlashes($message->header
->subject
)));
157 $urlMailbox = urlencode($mailbox);
158 $url_replyto = urlencode($message->header
->replyto
);
160 $url_replytoall = urlencode($message->header
->replyto
);
161 $url_replytoallcc = getLineOfAddrs($message->header
->to
);
162 $url_replytoallcc_cc = getLineOfAddrs($message->header
->cc
);
163 if ($url_replytoallcc) {
164 if ($url_replytoallcc_cc) {
165 $url_replytoallcc .= ", " . $url_replytoallcc_cc;
168 if ($url_replytoallcc_cc) {
169 $url_replytoallcc = $url_replytoallcc_cc;
171 $url_replytoallcc = "";
174 $url_replytoallcc = urlencode($url_replytoallcc);
176 $dateString = getLongDateString($message->header
->date
);
177 $ent_num = findDisplayEntity($message);
179 /** TEXT STRINGS DEFINITIONS **/
180 $echo_more = _("more");
181 $echo_less = _("less");
183 /** FORMAT THE TO STRING **/
186 $to_ary = $message->header
->to
;
187 while ($i < count($to_ary)) {
188 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
191 $to_string = "$to_string<BR>$to_ary[$i]";
193 $to_string = "$to_ary[$i]";
196 if (count($to_ary) > 1) {
197 if ($show_more == false) {
199 if ($where && $what) {
201 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
203 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
207 } else if ($i == 1) {
208 if ($where && $what) {
210 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
212 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
218 /** FORMAT THE CC STRING **/
221 $cc_ary = $message->header
->cc
;
222 while ($i < count(decodeHeader($cc_ary))) {
223 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
225 $cc_string = "$cc_string<BR>$cc_ary[$i]";
227 $cc_string = "$cc_ary[$i]";
230 if (count($cc_ary) > 1) {
231 if ($show_more_cc == false) {
233 if ($where && $what) {
235 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
237 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
241 } else if ($i == 1) {
242 if ($where && $what) {
244 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
246 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
252 /** make sure everything will display in HTML format **/
253 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
254 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
256 do_hook("read_body_top");
259 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
260 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
261 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
263 echo " <TD ALIGN=LEFT WIDTH=33%>";
265 if ($where && $what) {
266 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
268 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
270 echo _("Message List");
271 echo "</A> | ";
272 if ($where && $what) {
273 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
275 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
278 echo "</A> ";
280 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
282 if ($where && $what) {
284 if ($currentArrayIndex == -1) {
285 echo "Previous | Next";
287 $prev = findPreviousMessage();
288 $next = findNextMessage();
290 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
292 echo _("Previous") . " | ";
294 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
300 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
302 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
304 echo "</A> | ";
305 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
307 echo "</A> | ";
308 echo " <A HREF=\"compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
310 echo "</A> ";
316 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
317 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
320 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
322 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
323 echo " <B>$subject</B> \n";
325 if ($where && $what) {
326 // Got here from a search
327 echo " <TD WIDTH=1% bgcolor=\"$color[0]\" nowrap align=right><small><a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&view_hdr=1\">" . _("View full header") . "</a></small> </td>";
329 echo " <TD WIDTH=1% bgcolor=\"$color[0]\" nowrap align=right><small><a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" . _("View full header") . "</a></small> </td>";
334 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
336 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
337 echo " <B>$from_name</B> \n";
342 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
344 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
345 echo " <B>$dateString</B> \n";
350 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
352 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
353 echo " <B>$to_string</B> \n";
357 if ($message->header
->cc
) {
359 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
361 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
362 echo " <B>$cc_string</B> \n";
369 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
371 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
374 $body = formatBody($imapConnection, $message, $color, $wrap_at);
378 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
379 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
382 do_hook("read_body_bottom");
383 do_hook("html_bottom");
384 sqimap_logout($imapConnection);