fixed bugs in next/previous
[squirrelmail.git] / src / read_body.php
1 <?php
2 session_start();
3
4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($imap_php))
11 include("../functions/imap.php");
12 if (!isset($mime_php))
13 include("../functions/mime.php");
14 if (!isset($date_php))
15 include("../functions/date.php");
16
17 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
18 // return the index. used for finding the next and previous messages
19
20 // returns the index of the next valid message from the array
21 function findNextMessage() {
22 global $msort, $currentArrayIndex, $msgs;
23 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
24 if ($currentArrayIndex == $msgs[$key]["ID"]) {
25 next($msort);
26 $key = key($msort);
27 if (isset($key))
28 return $msgs[$key]["ID"];
29 }
30 }
31 return -1;
32 }
33
34 // returns the index of the previous message from the array
35 function findPreviousMessage() {
36 global $msort, $currentArrayIndex, $msgs;
37 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
38 if ($currentArrayIndex == $msgs[$key]["ID"]) {
39 prev($msort);
40 $key = key($msort);
41 if (isset($key))
42 return $msgs[$key]["ID"];
43 }
44 }
45 return -1;
46 }
47
48 if (isset($msgs)) {
49 $currentArrayIndex = $passed_id;
50 /*
51 for ($i=0; $i < count($msgs); $i++) {
52 if ($msgs[$i]["ID"] == $passed_id) {
53 $currentArrayIndex = $i;
54 break;
55 }
56 }
57 */
58 } else {
59 $currentArrayIndex = -1;
60 }
61
62 include("../src/load_prefs.php");
63 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
64 sqimap_mailbox_select($imapConnection, $mailbox);
65
66 // $message contains all information about the message
67 // including header and body
68 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
69
70 echo "<HTML>";
71 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
72 displayPageHeader($color, $mailbox);
73
74 /** translate the subject and mailbox into url-able text **/
75 $url_subj = urlencode(trim(stripslashes($message["HEADER"]["SUBJECT"])));
76 $urlMailbox = urlencode($mailbox);
77 $url_replyto = urlencode($message["HEADER"]["REPLYTO"]);
78
79 $url_replytoall = urlencode($message["HEADER"]["REPLYTO"]);
80 $url_replytoallcc = urlencode(getLineOfAddrs($message["HEADER"]["TO"]) . ", " . getLineOfAddrs($message["HEADER"]["CC"]));
81
82 $dateString = getLongDateString($message["HEADER"]["DATE"]);
83
84 /** TEXT STRINGS DEFINITIONS **/
85 $echo_more = _("more");
86 $echo_less = _("less");
87
88 /** FORMAT THE TO STRING **/
89 $i = 0;
90 $to_string = "";
91 $to_ary = $message["HEADER"]["TO"];
92 while ($i < count($to_ary)) {
93 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
94 if ($to_string)
95 $to_string = "$to_string<BR>$to_ary[$i]";
96 else
97 $to_string = "$to_ary[$i]";
98
99 $i++;
100 if (count($to_ary) > 1) {
101 if ($show_more == false) {
102 if ($i == 1) {
103 $to_string = "$to_string&nbsp;(<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>)";
104 $i = count($to_ary);
105 }
106 } else if ($i == 1) {
107 $to_string = "$to_string&nbsp;(<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>)";
108 }
109 }
110 }
111
112 /** FORMAT THE CC STRING **/
113 $i = 0;
114 $cc_string = "";
115 $cc_ary = $message["HEADER"]["CC"];
116 while ($i < count($cc_ary)) {
117 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
118 if ($cc_string)
119 $cc_string = "$cc_string<BR>$cc_ary[$i]";
120 else
121 $cc_string = "$cc_ary[$i]";
122
123 $i++;
124 if (count($cc_ary) > 1) {
125 if ($show_more_cc == false) {
126 if ($i == 1) {
127 $cc_string = "$cc_string&nbsp;(<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>)";
128 $i = count($cc_ary);
129 }
130 } else if ($i == 1) {
131 $cc_string = "$cc_string&nbsp;(<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>)";
132 }
133 }
134 }
135
136 /** make sure everything will display in HTML format **/
137 $from_name = decodeHeader(htmlspecialchars($message["HEADER"]["FROM"]));
138 $subject = decodeHeader(htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"])));
139
140 echo "<BR>";
141 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
142 echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
143 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
144 echo " <TR>";
145 echo " <TD ALIGN=LEFT WIDTH=33%>";
146 echo " <SMALL>";
147 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
148 echo _("Message List");
149 echo "</A>&nbsp;|&nbsp;";
150 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
151 echo _("Delete");
152 echo "</A>&nbsp;&nbsp;";
153 echo " </SMALL>";
154 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
155 echo " <SMALL>\n";
156 if ($currentArrayIndex == -1) {
157 echo "Previous&nbsp;|&nbspNext";
158 } else {
159 $prev = findPreviousMessage();
160 $next = findNextMessage();
161 if ($prev != -1)
162 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
163 else
164 echo _("Previous") . "&nbsp;|&nbsp;";
165 if ($next != -1)
166 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
167 else
168 echo _("Next");
169 }
170 echo " </SMALL>\n";
171 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
172 echo " <SMALL>";
173 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">";
174 echo _("Forward");
175 echo "</A>&nbsp;|&nbsp;";
176 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
177 echo _("Reply");
178 echo "</A>&nbsp;|&nbsp;";
179 echo " <A HREF=\"compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
180 echo _("Reply All");
181 echo "</A>&nbsp;&nbsp;";
182 echo " </SMALL>";
183 echo " </TD>";
184 echo " </TR>";
185 echo " </TABLE>";
186 echo " </TD></TR>";
187 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
188 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
189 echo " <TR>\n";
190 /** subject **/
191 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
192 echo _("Subject:");
193 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
194 echo " <B>$subject</B>\n";
195 echo " </TD>\n";
196 echo " </TR>\n";
197 /** from **/
198 echo " <TR>\n";
199 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
200 echo _("From:");
201 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
202 echo " <B>$from_name</B>\n";
203 echo " </TD>\n";
204 echo " </TR>\n";
205 /** date **/
206 echo " <TR>\n";
207 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
208 echo _("Date:");
209 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
210 echo " <B>$dateString</B>\n";
211 echo " </TD>\n";
212 echo " </TR>\n";
213 /** to **/
214 echo " <TR>\n";
215 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
216 echo _("To:");
217 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
218 echo " <B>$to_string</B>\n";
219 echo " </TD>\n";
220 echo " </TR>\n";
221 /** cc **/
222 if ($message["HEADER"]["CC"][0]) {
223 echo " <TR>\n";
224 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
225 echo " Cc:\n";
226 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
227 echo " <B>$cc_string</B>\n";
228 echo " </TD>\n";
229 echo " </TR>\n";
230 }
231 echo "</TABLE>";
232 echo " </TD></TR>";
233
234 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
235 $body = formatBody($message, $color, $wrap_at);
236 echo "<BR>";
237
238 echo "$body";
239
240 echo " </TD></TR>\n";
241 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
242 echo "</TABLE>\n";
243
244 ?>