applied the patch that uses redirect.php for login
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
ef870322 2 /**
3 ** read_body.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** This file is used for reading the msgs array and displaying
9 ** the resulting emails in the right frame.
10 **/
11
2a32fc83 12 session_start();
13
d068c0ec 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");
be69e508 26
c36ed9cf 27 include("../src/load_prefs.php");
28 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
29 sqimap_mailbox_select($imapConnection, $mailbox);
441f2d33 30 do_hook("html_top");
c36ed9cf 31 displayPageHeader($color, $mailbox);
32
33 if ($view_hdr) {
34 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
35 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
36
37 echo "<br>";
e9f8ea4e 38 echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n";
c36ed9cf 39 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
f4991a86 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)."\">";
8ae331c2 43 } else {
f4991a86 44 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
45 }
e9f8ea4e 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";
5c54e435 48 echo "<tr><td>";
49
50 echo "<table width=100% cellpadding=0 cellspacing=0 border=0>";
c36ed9cf 51 for ($i=1; $i < count($read)-1; $i++) {
5c54e435 52 $line = htmlspecialchars($read[$i]);
53 if (eregi("^[ |\t]", $line)) {
54 $second = $line;
55 $first = "";
56 } else if (eregi("^([^:|^\s]+):(.+)", $line, $regs)) {
57 $first = $regs[1];
58 $second = $regs[2];
59 } else {
60 $second = trim($line);
61 $first = "";
c36ed9cf 62 }
5c54e435 63 echo "<tr><td align=right valign=top>";
64 if ($first) echo "<tt><b>$first:</b></tt>";
65 else echo " ";
66 echo "</td><td valign=top nowrap><tt>$second</tt></td></tr>";
c36ed9cf 67 }
5c54e435 68 echo "</table>";
69 echo "</td></tr></table>\n";
c36ed9cf 70 echo "</body></html>";
a2790a61 71 sqimap_mailbox_close($imapConnection);
eabc2883 72 sqimap_logout($imapConnection);
c36ed9cf 73 exit;
74 }
75
90033b64 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
78
79 // returns the index of the next valid message from the array
80 function findNextMessage() {
5c54e435 81 global $msort, $currentArrayIndex, $msgs, $sort;
82
83 if ($sort == 6) {
84 if ($currentArrayIndex != 1) {
85 return $currentArrayIndex - 1;
86 }
87 } else {
88 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
89 if ($currentArrayIndex == $msgs[$key]["ID"]) {
90 next($msort);
91 $key = key($msort);
92 if (isset($key))
93 return $msgs[$key]["ID"];
94 }
95 }
96 }
90033b64 97 return -1;
98 }
99
100 // returns the index of the previous message from the array
101 function findPreviousMessage() {
5c54e435 102 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox;
103 if ($sort == 6) {
104 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
105 if ($currentArrayIndex != $numMessages) {
106 return $currentArrayIndex + 1;
107 }
108 } else {
109 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
110 if ($currentArrayIndex == $msgs[$key]["ID"]) {
111 prev($msort);
112 $key = key($msort);
113 if (isset($key))
114 return $msgs[$key]["ID"];
115 }
116 }
117 }
90033b64 118 return -1;
119 }
120
121 if (isset($msgs)) {
8ae331c2 122 $currentArrayIndex = $passed_id;
53524fa0 123 /*
90033b64 124 for ($i=0; $i < count($msgs); $i++) {
125 if ($msgs[$i]["ID"] == $passed_id) {
126 $currentArrayIndex = $i;
127 break;
128 }
129 }
53524fa0 130 */
90033b64 131 } else {
132 $currentArrayIndex = -1;
133 }
134
1108e8bb 135 for ($i = 0; $i < count($msgs); $i++) {
136 if ($msgs[$i]["ID"] == $passed_id)
137 $msgs[$i]["FLAG_SEEN"] = true;
138 }
139
f7fb20fe 140 // $message contains all information about the message
141 // including header and body
813eba2f 142 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
31f3d7c0 143
f7fb20fe 144 /** translate the subject and mailbox into url-able text **/
7aaa81fc 145 $url_subj = urlencode(trim(sqStripSlashes($message->header->subject)));
8467bf00 146 $urlMailbox = urlencode($mailbox);
8beafbbc 147 $url_replyto = urlencode($message->header->replyto);
be69e508 148
8beafbbc 149 $url_replytoall = urlencode($message->header->replyto);
b676ba7e 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;
155 }
156 } else {
157 if ($url_replytoallcc_cc) {
158 $url_replytoallcc = $url_replytoallcc_cc;
159 } else {
160 $url_replytoallcc = "";
161 }
162 }
163 $url_replytoallcc = urlencode($url_replytoallcc);
4bfed9f3 164
8beafbbc 165 $dateString = getLongDateString($message->header->date);
429f8906 166 $ent_num = findDisplayEntity($message);
31f3d7c0 167
b581fa60 168 /** TEXT STRINGS DEFINITIONS **/
169 $echo_more = _("more");
170 $echo_less = _("less");
171
078a40a4 172 /** FORMAT THE TO STRING **/
2844086d 173 $i = 0;
174 $to_string = "";
8beafbbc 175 $to_ary = $message->header->to;
2844086d 176 while ($i < count($to_ary)) {
99fa2b21 177 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
be8e07f8 178
2844086d 179 if ($to_string)
180 $to_string = "$to_string<BR>$to_ary[$i]";
181 else
182 $to_string = "$to_ary[$i]";
183
184 $i++;
185 if (count($to_ary) > 1) {
186 if ($show_more == false) {
187 if ($i == 1) {
f4991a86 188 if ($where && $what) {
189 // from a search
190 $to_string = "$to_string&nbsp;(<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>)";
191 } else {
192 $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>)";
193 }
2844086d 194 $i = count($to_ary);
195 }
196 } else if ($i == 1) {
f4991a86 197 if ($where && $what) {
198 // from a search
199 $to_string = "$to_string&nbsp;(<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>)";
200 } else {
201 $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>)";
202 }
2844086d 203 }
204 }
205 }
206
078a40a4 207 /** FORMAT THE CC STRING **/
208 $i = 0;
209 $cc_string = "";
8beafbbc 210 $cc_ary = $message->header->cc;
99fa2b21 211 while ($i < count(decodeHeader($cc_ary))) {
f7fb20fe 212 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 213 if ($cc_string)
214 $cc_string = "$cc_string<BR>$cc_ary[$i]";
215 else
216 $cc_string = "$cc_ary[$i]";
217
218 $i++;
219 if (count($cc_ary) > 1) {
220 if ($show_more_cc == false) {
221 if ($i == 1) {
f4991a86 222 if ($where && $what) {
223 // from a search
224 $cc_string = "$cc_string&nbsp;(<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>)";
225 } else {
226 $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>)";
227 }
078a40a4 228 $i = count($cc_ary);
229 }
230 } else if ($i == 1) {
f4991a86 231 if ($where && $what) {
232 // from a search
233 $cc_string = "$cc_string&nbsp;(<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>)";
234 } else {
235 $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>)";
236 }
078a40a4 237 }
238 }
239 }
240
f7fb20fe 241 /** make sure everything will display in HTML format **/
8beafbbc 242 $from_name = decodeHeader(htmlspecialchars($message->header->from));
7aaa81fc 243 $subject = decodeHeader(htmlspecialchars($message->header->subject));
078a40a4 244
06ad27a2 245 do_hook("read_body_top");
8467bf00 246 echo "<BR>";
8ae331c2 247
d68a3926 248 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
c36ed9cf 249 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
4809f489 250 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
31f3d7c0 251 echo " <TR>";
90033b64 252 echo " <TD ALIGN=LEFT WIDTH=33%>";
aae41ae9 253 echo " <SMALL>";
1809bad8 254 if ($where && $what) {
255 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
256 } else {
257 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
258 }
b581fa60 259 echo _("Message List");
260 echo "</A>&nbsp;|&nbsp;";
1809bad8 261 if ($where && $what) {
99fa2b21 262 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
1809bad8 263 } else {
d36f3e63 264 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
1809bad8 265 }
b581fa60 266 echo _("Delete");
267 echo "</A>&nbsp;&nbsp;";
aae41ae9 268 echo " </SMALL>";
90033b64 269 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
270 echo " <SMALL>\n";
1809bad8 271 if ($where && $what) {
90033b64 272 } else {
1809bad8 273 if ($currentArrayIndex == -1) {
274 echo "Previous&nbsp;|&nbsp;Next";
275 } else {
276 $prev = findPreviousMessage();
277 $next = findNextMessage();
278 if ($prev != -1)
279 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
280 else
281 echo _("Previous") . "&nbsp;|&nbsp;";
282 if ($next != -1)
283 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
284 else
285 echo _("Next");
286 }
287 }
90033b64 288 echo " </SMALL>\n";
289 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
aae41ae9 290 echo " <SMALL>";
429f8906 291 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 292 echo _("Forward");
293 echo "</A>&nbsp;|&nbsp;";
429f8906 294 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 295 echo _("Reply");
296 echo "</A>&nbsp;|&nbsp;";
429f8906 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\">";
b581fa60 298 echo _("Reply All");
299 echo "</A>&nbsp;&nbsp;";
aae41ae9 300 echo " </SMALL>";
31f3d7c0 301 echo " </TD>";
302 echo " </TR>";
303 echo " </TABLE>";
8467bf00 304 echo " </TD></TR>";
4809f489 305 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
97afcee9 306 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
be69e508 307 echo " <TR>\n";
308 /** subject **/
c36ed9cf 309 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 310 echo _("Subject:");
c36ed9cf 311 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
c221adce 312 echo " <B>$subject</B>&nbsp;\n";
be69e508 313 echo " </TD>\n";
f4991a86 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>&nbsp;&nbsp;</td>";
317 } else {
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>&nbsp;&nbsp;</td>";
319 }
be69e508 320 echo " </TR>\n";
321 /** from **/
322 echo " <TR>\n";
c36ed9cf 323 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 324 echo _("From:");
c36ed9cf 325 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
c221adce 326 echo " <B>$from_name</B>&nbsp;\n";
be69e508 327 echo " </TD>\n";
328 echo " </TR>\n";
329 /** date **/
330 echo " <TR>\n";
c36ed9cf 331 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
32c7898c 332 echo _("Date:");
c36ed9cf 333 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
c221adce 334 echo " <B>$dateString</B>&nbsp;\n";
be69e508 335 echo " </TD>\n";
336 echo " </TR>\n";
2844086d 337 /** to **/
338 echo " <TR>\n";
c36ed9cf 339 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
b581fa60 340 echo _("To:");
c36ed9cf 341 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
c221adce 342 echo " <B>$to_string</B>&nbsp;\n";
2844086d 343 echo " </TD>\n";
344 echo " </TR>\n";
078a40a4 345 /** cc **/
8beafbbc 346 if ($message->header->cc) {
078a40a4 347 echo " <TR>\n";
c36ed9cf 348 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
aae41ae9 349 echo " Cc:\n";
c36ed9cf 350 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
c221adce 351 echo " <B>$cc_string</B>&nbsp;\n";
078a40a4 352 echo " </TD>\n";
353 echo " </TR>\n";
354 }
4809f489 355 echo "</TABLE>";
356 echo " </TD></TR>";
d68a3926 357 echo "</table>";
a48fbf9b 358 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
be69e508 359
f8f9bed9 360 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
4809f489 361 echo "<BR>";
9297917e 362
363 $body = formatBody($imapConnection, $message, $color, $wrap_at);
5c55c295 364
441f2d33 365 echo $body;
366
d68a3926 367 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
7831268e 368 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
be69e508 369 echo "</TABLE>\n";
370
06ad27a2 371 do_hook("read_body_bottom");
441f2d33 372 do_hook("html_bottom");
1195c340 373 sqimap_logout($imapConnection);
b581fa60 374?>