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.
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($page_header_php))
24 include("../functions/page_header.php");
25 if (!isset($imap_php))
26 include("../functions/imap.php");
27 if (!isset($mime_php))
28 include("../functions/mime.php");
29 if (!isset($date_php))
30 include("../functions/date.php");
32 include("../src/load_prefs.php");
33 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
34 sqimap_mailbox_select($imapConnection, $mailbox);
35 displayPageHeader($color, $mailbox);
38 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
39 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
42 echo "<table width=95% cellpadding=2 cellspacing=0 border=0 align=center>\n";
43 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
44 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
45 echo ""._("View message") . "</a></b></center></td></tr>\n";
47 for ($i=1; $i < count($read)-1; $i++
) {
48 $read[$i] = htmlspecialchars($read[$i]);
49 if (substr($read[$i], 0, 1) != "\t" &&
50 substr($read[$i], 0, 1) != " " &&
51 substr($read[$i], 0, 1) != "&" &&
53 $pre = substr($read[$i], 0, strpos($read[$i], ":"));
54 $read[$i] = str_replace("$pre", "<b>$pre</b>", $read[$i]);
58 echo "</pre></td></tr></table>\n";
59 echo "</body></html>";
63 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
64 // return the index. used for finding the next and previous messages
66 // returns the index of the next valid message from the array
67 function findNextMessage() {
68 global $msort, $currentArrayIndex, $msgs;
69 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
70 if ($currentArrayIndex == $msgs[$key]["ID"]) {
74 return $msgs[$key]["ID"];
80 // returns the index of the previous message from the array
81 function findPreviousMessage() {
82 global $msort, $currentArrayIndex, $msgs;
83 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
84 if ($currentArrayIndex == $msgs[$key]["ID"]) {
88 return $msgs[$key]["ID"];
95 $currentArrayIndex = $passed_id;
97 for ($i=0; $i < count($msgs); $i++) {
98 if ($msgs[$i]["ID"] == $passed_id) {
99 $currentArrayIndex = $i;
105 $currentArrayIndex = -1;
108 for ($i = 0; $i < count($msgs); $i++
) {
109 if ($msgs[$i]["ID"] == $passed_id)
110 $msgs[$i]["FLAG_SEEN"] = true;
113 // $message contains all information about the message
114 // including header and body
115 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
117 /** translate the subject and mailbox into url-able text **/
118 $url_subj = urlencode(trim(stripslashes($message->header
->subject
)));
119 $urlMailbox = urlencode($mailbox);
120 $url_replyto = urlencode($message->header
->replyto
);
122 $url_replytoall = urlencode($message->header
->replyto
);
123 $url_replytoallcc = urlencode(getLineOfAddrs($message->header
->to
) . ", " . getLineOfAddrs($message->header
->cc
));
125 $dateString = getLongDateString($message->header
->date
);
126 $ent_num = findDisplayEntity($message);
128 /** TEXT STRINGS DEFINITIONS **/
129 $echo_more = _("more");
130 $echo_less = _("less");
132 /** FORMAT THE TO STRING **/
135 $to_ary = $message->header
->to
;
136 while ($i < count($to_ary)) {
137 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
140 $to_string = "$to_string<BR>$to_ary[$i]";
142 $to_string = "$to_ary[$i]";
145 if (count($to_ary) > 1) {
146 if ($show_more == false) {
148 $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>)";
151 } else if ($i == 1) {
152 $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>)";
157 /** FORMAT THE CC STRING **/
160 $cc_ary = $message->header
->cc
;
161 while ($i < count($cc_ary)) {
162 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
164 $cc_string = "$cc_string<BR>$cc_ary[$i]";
166 $cc_string = "$cc_ary[$i]";
169 if (count($cc_ary) > 1) {
170 if ($show_more_cc == false) {
172 $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>)";
175 } else if ($i == 1) {
176 $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>)";
181 /** make sure everything will display in HTML format **/
182 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
183 $subject = decodeHeader(htmlspecialchars(stripslashes($message->header
->subject
)));
186 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
187 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
188 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
190 echo " <TD ALIGN=LEFT WIDTH=33%>";
192 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
193 echo _("Message List");
194 echo "</A> | ";
195 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
197 echo "</A> ";
199 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
201 if ($currentArrayIndex == -1) {
202 echo "Previous | Next";
204 $prev = findPreviousMessage();
205 $next = findNextMessage();
207 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
209 echo _("Previous") . " | ";
211 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
216 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
218 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
220 echo "</A> | ";
221 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
223 echo "</A> | ";
224 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\">";
226 echo "</A> ";
232 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
233 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
236 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
238 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
239 echo " <B>$subject</B>\n";
241 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>";
245 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
247 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
248 echo " <B>$from_name</B>\n";
253 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
255 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
256 echo " <B>$dateString</B>\n";
261 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
263 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
264 echo " <B>$to_string</B>\n";
268 if ($message->header
->cc
) {
270 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
272 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
273 echo " <B>$cc_string</B>\n";
280 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
281 $body = formatBody($message, $color, $wrap_at);
286 echo " </TD></TR>\n";
287 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";