05462549a88987a26c702247754b207f4e615640
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");
27 include("../src/load_prefs.php");
28 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
29 sqimap_mailbox_select($imapConnection, $mailbox);
31 displayPageHeader($color, $mailbox);
34 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
35 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
38 echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n";
39 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
40 if ($where && $what) {
41 // Got here from a search
42 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
44 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
46 echo ""._("View message") . "</a></b></center></td></tr></table>\n";
47 echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
50 echo "<table width=100% cellpadding=0 cellspacing=0 border=0>";
51 for ($i=1; $i < count($read)-1; $i++
) {
52 $line = htmlspecialchars($read[$i]);
53 if (eregi("^[ |\t]", $line)) {
56 } else if (eregi("^([^:|^\s]+):(.+)", $line, $regs)) {
60 $second = trim($line);
63 echo "<tr><td align=right valign=top>";
64 if ($first) echo "<tt><b>$first:</b></tt>";
66 echo "</td><td valign=top nowrap><tt>$second</tt></td></tr>";
69 echo "</td></tr></table>\n";
70 echo "</body></html>";
71 sqimap_mailbox_close($imapConnection);
72 sqimap_logout($imapConnection);
76 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
77 // return the index. used for finding the next and previous messages
79 // returns the index of the next valid message from the array
80 function findNextMessage() {
81 global $msort, $currentArrayIndex, $msgs, $sort;
84 if ($currentArrayIndex != 1) {
85 return $currentArrayIndex - 1;
88 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
89 if ($currentArrayIndex == $msgs[$key]["ID"]) {
93 return $msgs[$key]["ID"];
100 // returns the index of the previous message from the array
101 function findPreviousMessage() {
102 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox;
104 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
105 if ($currentArrayIndex != $numMessages) {
106 return $currentArrayIndex +
1;
109 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
110 if ($currentArrayIndex == $msgs[$key]["ID"]) {
114 return $msgs[$key]["ID"];
122 $currentArrayIndex = $passed_id;
124 for ($i=0; $i < count($msgs); $i++) {
125 if ($msgs[$i]["ID"] == $passed_id) {
126 $currentArrayIndex = $i;
132 $currentArrayIndex = -1;
135 for ($i = 0; $i < count($msgs); $i++
) {
136 if ($msgs[$i]["ID"] == $passed_id)
137 $msgs[$i]["FLAG_SEEN"] = true;
140 // $message contains all information about the message
141 // including header and body
142 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
144 /** translate the subject and mailbox into url-able text **/
145 $url_subj = urlencode(trim(sqStripSlashes($message->header
->subject
)));
146 $urlMailbox = urlencode($mailbox);
147 $url_replyto = urlencode($message->header
->replyto
);
149 $url_replytoall = urlencode($message->header
->replyto
);
150 $url_replytoallcc = getLineOfAddrs($message->header
->to
);
151 $url_replytoallcc_cc = getLineOfAddrs($message->header
->cc
);
152 if ($url_replytoallcc) {
153 if ($url_replytoallcc_cc) {
154 $url_replytoallcc .= ", " . $url_replytoallcc_cc;
157 if ($url_replytoallcc_cc) {
158 $url_replytoallcc = $url_replytoallcc_cc;
160 $url_replytoallcc = "";
163 $url_replytoallcc = urlencode($url_replytoallcc);
165 $dateString = getLongDateString($message->header
->date
);
166 $ent_num = findDisplayEntity($message);
168 /** TEXT STRINGS DEFINITIONS **/
169 $echo_more = _("more");
170 $echo_less = _("less");
172 /** FORMAT THE TO STRING **/
175 $to_ary = $message->header
->to
;
176 while ($i < count($to_ary)) {
177 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
180 $to_string = "$to_string<BR>$to_ary[$i]";
182 $to_string = "$to_ary[$i]";
185 if (count($to_ary) > 1) {
186 if ($show_more == false) {
188 if ($where && $what) {
190 $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>)";
192 $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>)";
196 } else if ($i == 1) {
197 if ($where && $what) {
199 $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>)";
201 $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>)";
207 /** FORMAT THE CC STRING **/
210 $cc_ary = $message->header
->cc
;
211 while ($i < count(decodeHeader($cc_ary))) {
212 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
214 $cc_string = "$cc_string<BR>$cc_ary[$i]";
216 $cc_string = "$cc_ary[$i]";
219 if (count($cc_ary) > 1) {
220 if ($show_more_cc == false) {
222 if ($where && $what) {
224 $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>)";
226 $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>)";
230 } else if ($i == 1) {
231 if ($where && $what) {
233 $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>)";
235 $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>)";
241 /** make sure everything will display in HTML format **/
242 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
243 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
245 do_hook("read_body_top");
248 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
249 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
250 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
252 echo " <TD ALIGN=LEFT WIDTH=33%>";
254 if ($where && $what) {
255 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
257 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
259 echo _("Message List");
260 echo "</A> | ";
261 if ($where && $what) {
262 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
264 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
267 echo "</A> ";
269 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
271 if ($where && $what) {
273 if ($currentArrayIndex == -1) {
274 echo "Previous | Next";
276 $prev = findPreviousMessage();
277 $next = findNextMessage();
279 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
281 echo _("Previous") . " | ";
283 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
289 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
291 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
293 echo "</A> | ";
294 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
296 echo "</A> | ";
297 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\">";
299 echo "</A> ";
305 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
306 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
309 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
311 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
312 echo " <B>$subject</B> \n";
314 if ($where && $what) {
315 // Got here from a search
316 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>";
318 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>";
323 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
325 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
326 echo " <B>$from_name</B> \n";
331 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
333 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
334 echo " <B>$dateString</B> \n";
339 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
341 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
342 echo " <B>$to_string</B> \n";
346 if ($message->header
->cc
) {
348 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
350 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
351 echo " <B>$cc_string</B> \n";
358 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
360 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
363 $body = formatBody($imapConnection, $message, $color, $wrap_at);
367 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
368 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
371 do_hook("read_body_bottom");
372 do_hook("html_bottom");
373 sqimap_logout($imapConnection);