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