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