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";
49 for ($i=1; $i < count($read)-1; $i++
) {
50 $read[$i] = htmlspecialchars($read[$i]);
51 if (substr($read[$i], 0, 1) != "\t" &&
52 substr($read[$i], 0, 1) != " " &&
53 substr($read[$i], 0, 1) != "&" &&
55 $pre = substr($read[$i], 0, strpos($read[$i], ":"));
56 $read[$i] = str_replace("$pre", "<b>$pre</b>", decodeHeader($read[$i]));
60 echo "</pre></td></tr></table>\n";
61 echo "</body></html>";
62 sqimap_mailbox_close($imapConnection);
63 sqimap_logout($imapConnection);
67 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
68 // return the index. used for finding the next and previous messages
70 // returns the index of the next valid message from the array
71 function findNextMessage() {
72 global $msort, $currentArrayIndex, $msgs;
73 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
74 if ($currentArrayIndex == $msgs[$key]["ID"]) {
78 return $msgs[$key]["ID"];
84 // returns the index of the previous message from the array
85 function findPreviousMessage() {
86 global $msort, $currentArrayIndex, $msgs;
87 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
88 if ($currentArrayIndex == $msgs[$key]["ID"]) {
92 return $msgs[$key]["ID"];
99 $currentArrayIndex = $passed_id;
101 for ($i=0; $i < count($msgs); $i++) {
102 if ($msgs[$i]["ID"] == $passed_id) {
103 $currentArrayIndex = $i;
109 $currentArrayIndex = -1;
112 for ($i = 0; $i < count($msgs); $i++
) {
113 if ($msgs[$i]["ID"] == $passed_id)
114 $msgs[$i]["FLAG_SEEN"] = true;
117 // $message contains all information about the message
118 // including header and body
119 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
121 /** translate the subject and mailbox into url-able text **/
122 $url_subj = urlencode(trim(sqStripSlashes($message->header
->subject
)));
123 $urlMailbox = urlencode($mailbox);
124 $url_replyto = urlencode($message->header
->replyto
);
126 $url_replytoall = urlencode($message->header
->replyto
);
127 $url_replytoallcc = getLineOfAddrs($message->header
->to
);
128 $url_replytoallcc_cc = getLineOfAddrs($message->header
->cc
);
129 if ($url_replytoallcc) {
130 if ($url_replytoallcc_cc) {
131 $url_replytoallcc .= ", " . $url_replytoallcc_cc;
134 if ($url_replytoallcc_cc) {
135 $url_replytoallcc = $url_replytoallcc_cc;
137 $url_replytoallcc = "";
140 $url_replytoallcc = urlencode($url_replytoallcc);
142 $dateString = getLongDateString($message->header
->date
);
143 $ent_num = findDisplayEntity($message);
145 /** TEXT STRINGS DEFINITIONS **/
146 $echo_more = _("more");
147 $echo_less = _("less");
149 /** FORMAT THE TO STRING **/
152 $to_ary = $message->header
->to
;
153 while ($i < count($to_ary)) {
154 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
157 $to_string = "$to_string<BR>$to_ary[$i]";
159 $to_string = "$to_ary[$i]";
162 if (count($to_ary) > 1) {
163 if ($show_more == false) {
165 if ($where && $what) {
167 $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>)";
169 $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>)";
173 } else if ($i == 1) {
174 if ($where && $what) {
176 $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>)";
178 $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>)";
184 /** FORMAT THE CC STRING **/
187 $cc_ary = $message->header
->cc
;
188 while ($i < count(decodeHeader($cc_ary))) {
189 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
191 $cc_string = "$cc_string<BR>$cc_ary[$i]";
193 $cc_string = "$cc_ary[$i]";
196 if (count($cc_ary) > 1) {
197 if ($show_more_cc == false) {
199 if ($where && $what) {
201 $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>)";
203 $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>)";
207 } else if ($i == 1) {
208 if ($where && $what) {
210 $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>)";
212 $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>)";
218 /** make sure everything will display in HTML format **/
219 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
220 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
222 do_hook("read_body_top");
225 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
226 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
227 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
229 echo " <TD ALIGN=LEFT WIDTH=33%>";
231 if ($where && $what) {
232 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
234 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
236 echo _("Message List");
237 echo "</A> | ";
238 if ($where && $what) {
239 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
241 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
244 echo "</A> ";
246 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
248 if ($where && $what) {
250 if ($currentArrayIndex == -1) {
251 echo "Previous | Next";
253 $prev = findPreviousMessage();
254 $next = findNextMessage();
256 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
258 echo _("Previous") . " | ";
260 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
266 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
268 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
270 echo "</A> | ";
271 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
273 echo "</A> | ";
274 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\">";
276 echo "</A> ";
282 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
283 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
286 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
288 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
289 echo " <B>$subject</B> \n";
291 if ($where && $what) {
292 // Got here from a search
293 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>";
295 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>";
300 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
302 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
303 echo " <B>$from_name</B> \n";
308 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
310 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
311 echo " <B>$dateString</B> \n";
316 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
318 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
319 echo " <B>$to_string</B> \n";
323 if ($message->header
->cc
) {
325 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
327 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
328 echo " <B>$cc_string</B> \n";
335 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
337 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
340 $body = formatBody($imapConnection, $message, $color, $wrap_at);
344 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
345 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
348 do_hook("read_body_bottom");
349 do_hook("html_bottom");
350 sqimap_logout($imapConnection);