Fixed major problems with IMAP session handling in the MIME code. This
[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);
30 displayPageHeader($color, $mailbox);
31
32 if ($view_hdr) {
33 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
34 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
35
36 echo "<br>";
37 echo "<table width=95% cellpadding=2 cellspacing=0 border=0 align=center>\n";
38 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
39 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
40 echo ""._("View message") . "</a></b></center></td></tr>\n";
41 echo "<tr><td><pre>";
42 for ($i=1; $i < count($read)-1; $i++) {
43 $read[$i] = htmlspecialchars($read[$i]);
44 if (substr($read[$i], 0, 1) != "\t" &&
45 substr($read[$i], 0, 1) != " " &&
46 substr($read[$i], 0, 1) != "&" &&
47 trim($read[$i])) {
48 $pre = substr($read[$i], 0, strpos($read[$i], ":"));
49 $read[$i] = str_replace("$pre", "<b>$pre</b>", $read[$i]);
50 }
51 echo "$read[$i]";
52 }
53 echo "</pre></td></tr></table>\n";
54 echo "</body></html>";
55 exit;
56 }
57
90033b64 58 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
59 // return the index. used for finding the next and previous messages
60
61 // returns the index of the next valid message from the array
62 function findNextMessage() {
53524fa0 63 global $msort, $currentArrayIndex, $msgs;
64 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
65 if ($currentArrayIndex == $msgs[$key]["ID"]) {
66 next($msort);
67 $key = key($msort);
68 if (isset($key))
69 return $msgs[$key]["ID"];
70 }
71 }
90033b64 72 return -1;
73 }
74
75 // returns the index of the previous message from the array
76 function findPreviousMessage() {
53524fa0 77 global $msort, $currentArrayIndex, $msgs;
78 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
79 if ($currentArrayIndex == $msgs[$key]["ID"]) {
80 prev($msort);
81 $key = key($msort);
82 if (isset($key))
83 return $msgs[$key]["ID"];
84 }
85 }
90033b64 86 return -1;
87 }
88
89 if (isset($msgs)) {
53524fa0 90 $currentArrayIndex = $passed_id;
91 /*
90033b64 92 for ($i=0; $i < count($msgs); $i++) {
93 if ($msgs[$i]["ID"] == $passed_id) {
94 $currentArrayIndex = $i;
95 break;
96 }
97 }
53524fa0 98 */
90033b64 99 } else {
100 $currentArrayIndex = -1;
101 }
102
1108e8bb 103 for ($i = 0; $i < count($msgs); $i++) {
104 if ($msgs[$i]["ID"] == $passed_id)
105 $msgs[$i]["FLAG_SEEN"] = true;
106 }
107
f7fb20fe 108 // $message contains all information about the message
109 // including header and body
813eba2f 110 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
31f3d7c0 111
f7fb20fe 112 /** translate the subject and mailbox into url-able text **/
8beafbbc 113 $url_subj = urlencode(trim(stripslashes($message->header->subject)));
8467bf00 114 $urlMailbox = urlencode($mailbox);
8beafbbc 115 $url_replyto = urlencode($message->header->replyto);
be69e508 116
8beafbbc 117 $url_replytoall = urlencode($message->header->replyto);
118 $url_replytoallcc = urlencode(getLineOfAddrs($message->header->to) . ", " . getLineOfAddrs($message->header->cc));
4bfed9f3 119
8beafbbc 120 $dateString = getLongDateString($message->header->date);
429f8906 121 $ent_num = findDisplayEntity($message);
31f3d7c0 122
b581fa60 123 /** TEXT STRINGS DEFINITIONS **/
124 $echo_more = _("more");
125 $echo_less = _("less");
126
078a40a4 127 /** FORMAT THE TO STRING **/
2844086d 128 $i = 0;
129 $to_string = "";
8beafbbc 130 $to_ary = $message->header->to;
2844086d 131 while ($i < count($to_ary)) {
f7fb20fe 132 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
be8e07f8 133
2844086d 134 if ($to_string)
135 $to_string = "$to_string<BR>$to_ary[$i]";
136 else
137 $to_string = "$to_ary[$i]";
138
139 $i++;
140 if (count($to_ary) > 1) {
141 if ($show_more == false) {
142 if ($i == 1) {
9f2215a1 143 $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>)";
2844086d 144 $i = count($to_ary);
145 }
146 } else if ($i == 1) {
9f2215a1 147 $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>)";
2844086d 148 }
149 }
150 }
151
078a40a4 152 /** FORMAT THE CC STRING **/
153 $i = 0;
154 $cc_string = "";
8beafbbc 155 $cc_ary = $message->header->cc;
078a40a4 156 while ($i < count($cc_ary)) {
f7fb20fe 157 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 158 if ($cc_string)
159 $cc_string = "$cc_string<BR>$cc_ary[$i]";
160 else
161 $cc_string = "$cc_ary[$i]";
162
163 $i++;
164 if (count($cc_ary) > 1) {
165 if ($show_more_cc == false) {
166 if ($i == 1) {
9f2215a1 167 $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>)";
078a40a4 168 $i = count($cc_ary);
169 }
170 } else if ($i == 1) {
9f2215a1 171 $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>)";
078a40a4 172 }
173 }
174 }
175
f7fb20fe 176 /** make sure everything will display in HTML format **/
8beafbbc 177 $from_name = decodeHeader(htmlspecialchars($message->header->from));
178 $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject)));
078a40a4 179
8467bf00 180 echo "<BR>";
4809f489 181 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
c36ed9cf 182 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
4809f489 183 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
31f3d7c0 184 echo " <TR>";
90033b64 185 echo " <TD ALIGN=LEFT WIDTH=33%>";
aae41ae9 186 echo " <SMALL>";
90033b64 187 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
b581fa60 188 echo _("Message List");
189 echo "</A>&nbsp;|&nbsp;";
9f2215a1 190 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
b581fa60 191 echo _("Delete");
192 echo "</A>&nbsp;&nbsp;";
aae41ae9 193 echo " </SMALL>";
90033b64 194 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
195 echo " <SMALL>\n";
196 if ($currentArrayIndex == -1) {
9988d19e 197 echo "Previous&nbsp;|&nbsp;Next";
90033b64 198 } else {
199 $prev = findPreviousMessage();
200 $next = findNextMessage();
201 if ($prev != -1)
202 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
203 else
204 echo _("Previous") . "&nbsp;|&nbsp;";
205 if ($next != -1)
206 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
207 else
208 echo _("Next");
209 }
210 echo " </SMALL>\n";
211 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
aae41ae9 212 echo " <SMALL>";
429f8906 213 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 214 echo _("Forward");
215 echo "</A>&nbsp;|&nbsp;";
429f8906 216 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 217 echo _("Reply");
218 echo "</A>&nbsp;|&nbsp;";
429f8906 219 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 220 echo _("Reply All");
221 echo "</A>&nbsp;&nbsp;";
aae41ae9 222 echo " </SMALL>";
31f3d7c0 223 echo " </TD>";
224 echo " </TR>";
225 echo " </TABLE>";
8467bf00 226 echo " </TD></TR>";
4809f489 227 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
97afcee9 228 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
be69e508 229 echo " <TR>\n";
230 /** subject **/
c36ed9cf 231 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 232 echo _("Subject:");
c36ed9cf 233 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
aae41ae9 234 echo " <B>$subject</B>\n";
be69e508 235 echo " </TD>\n";
c36ed9cf 236 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>";
be69e508 237 echo " </TR>\n";
238 /** from **/
239 echo " <TR>\n";
c36ed9cf 240 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 241 echo _("From:");
c36ed9cf 242 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
aae41ae9 243 echo " <B>$from_name</B>\n";
be69e508 244 echo " </TD>\n";
245 echo " </TR>\n";
246 /** date **/
247 echo " <TR>\n";
c36ed9cf 248 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
32c7898c 249 echo _("Date:");
c36ed9cf 250 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
aae41ae9 251 echo " <B>$dateString</B>\n";
be69e508 252 echo " </TD>\n";
253 echo " </TR>\n";
2844086d 254 /** to **/
255 echo " <TR>\n";
c36ed9cf 256 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
b581fa60 257 echo _("To:");
c36ed9cf 258 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
aae41ae9 259 echo " <B>$to_string</B>\n";
2844086d 260 echo " </TD>\n";
261 echo " </TR>\n";
078a40a4 262 /** cc **/
8beafbbc 263 if ($message->header->cc) {
078a40a4 264 echo " <TR>\n";
c36ed9cf 265 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
aae41ae9 266 echo " Cc:\n";
c36ed9cf 267 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
aae41ae9 268 echo " <B>$cc_string</B>\n";
078a40a4 269 echo " </TD>\n";
270 echo " </TR>\n";
271 }
4809f489 272 echo "</TABLE>";
273 echo " </TD></TR>";
be69e508 274
f8f9bed9 275 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
8d8ab69a 276 $body = formatBody($imapConnection, $message, $color, $wrap_at);
4809f489 277 echo "<BR>";
5c55c295 278
7831268e 279 echo "$body";
d4467150 280
7831268e 281 echo " </TD></TR>\n";
282 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
be69e508 283 echo "</TABLE>\n";
284
1195c340 285 sqimap_logout($imapConnection);
b581fa60 286?>