5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This file is used for reading the msgs array and displaying
9 ** the resulting emails in the right frame.
14 include("../src/validate.php");
15 include('../functions/strings.php');
16 include('../config/config.php');
17 include('../functions/page_header.php');
18 include('../functions/imap.php');
19 include('../functions/mime.php');
20 include('../functions/date.php');
21 include('../functions/url_parser.php');
22 include('../src/load_prefs.php');
24 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
25 sqimap_mailbox_select($imapConnection, $mailbox);
27 displayPageHeader($color, $mailbox);
29 if (isset($view_hdr)) {
30 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
31 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
34 echo '<table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">' . "\n";
35 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . '</b> - ';
36 if (isset($where) && isset($what)) {
37 // Got here from a search
38 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
40 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
42 echo ''._("View message") . "</a></b></center></td></tr></table>\n";
43 echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
47 for ($i=1; $i < count($read)-1; $i++
) {
48 $line = htmlspecialchars($read[$i]);
49 if (eregi("^>", $line)) {
51 $first[$i] = ' ';
53 } else if (eregi("^[ |\t]", $line)) {
56 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
57 $first[$i] = $regs[1] . ':';
58 $second[$i] = $regs[2];
61 $second[$i] = trim($line);
65 for ($i=0; $i < count($second); $i = $j) {
66 if (isset($first[$i]))
68 if (isset($second[$i]))
69 $s = nl2br($second[$i]);
71 while ($first[$j] == '' && $j < count($first)) {
72 $s .= ' ' . nl2br($second[$j]);
76 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
78 echo "</td></tr></table>\n";
79 echo '</body></html>';
80 sqimap_logout($imapConnection);
84 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
85 // return the index. used for finding the next and previous messages
87 // returns the index of the next valid message from the array
88 function findNextMessage() {
89 global $msort, $currentArrayIndex, $msgs, $sort;
92 if ($currentArrayIndex != 1) {
93 return $currentArrayIndex - 1;
96 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
97 if ($currentArrayIndex == $msgs[$key]['ID']) {
101 return $msgs[$key]['ID'];
108 // returns the index of the previous message from the array
109 function findPreviousMessage() {
110 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox;
112 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
113 if ($currentArrayIndex != $numMessages) {
114 return $currentArrayIndex +
1;
117 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
118 if ($currentArrayIndex == $msgs[$key]['ID']) {
122 return $msgs[$key]['ID'];
130 $currentArrayIndex = $passed_id;
132 for ($i=0; $i < count($msgs); $i++) {
133 if ($msgs[$i]["ID"] == $passed_id) {
134 $currentArrayIndex = $i;
140 $currentArrayIndex = -1;
143 for ($i = 0; $i < count($msgs); $i++
) {
144 if ($msgs[$i]['ID'] == $passed_id)
145 $msgs[$i]['FLAG_SEEN'] = true;
148 // $message contains all information about the message
149 // including header and body
150 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
152 /** translate the subject and mailbox into url-able text **/
153 $url_subj = urlencode(trim($message->header
->subject
));
154 $urlMailbox = urlencode($mailbox);
155 $url_replyto = urlencode($message->header
->replyto
);
157 $url_replytoall = urlencode($message->header
->replyto
);
159 // If we are replying to all, then find all other addresses and
160 // add them to the list. Remove duplicates.
161 // This is somewhat messy, so I'll explain:
162 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
163 $url_replytoall_extra_addrs = array_merge(array($message->header
->from
),
164 $message->header
->to
, $message->header
->cc
);
166 // 2) Make one big string out of them
167 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
169 // 3) Parse that into an array of addresses
170 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
172 // 4) Make them unique -- weed out duplicates
173 // (Coded for PHP 4.0.0)
174 $url_replytoall_extra_addrs =
175 array_keys(array_flip($url_replytoall_extra_addrs));
177 // 5) Remove the addresses we'll be sending the message 'to'
178 $url_replytoall_avoid_addrs = parseAddrs($message->header
->replyto
);
179 foreach ($url_replytoall_avoid_addrs as $addr)
181 foreach (array_keys($url_replytoall_extra_addrs, $addr) as $key_to_delete)
183 unset($url_replytoall_extra_addrs[$key_to_delete]);
187 // 6) Smoosh back into one nice line
188 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
191 $url_replytoallcc = urlencode($url_replytoallcc);
193 $dateString = getLongDateString($message->header
->date
);
195 // What do we reply to -- text only, if possible
196 $ent_num = findDisplayEntity($message);
198 /** TEXT STRINGS DEFINITIONS **/
199 $echo_more = _("more");
200 $echo_less = _("less");
202 if (!isset($show_more_cc)) $show_more_cc = false;
204 /** FORMAT THE TO STRING **/
207 $to_ary = $message->header
->to
;
208 while ($i < count($to_ary)) {
209 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
212 $to_string = "$to_string<BR>$to_ary[$i]";
214 $to_string = "$to_ary[$i]";
217 if (count($to_ary) > 1) {
218 if ($show_more == false) {
220 if (isset($where) && isset($what)) {
222 $to_string = "$to_string (<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>)";
224 $to_string = "$to_string (<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>)";
228 } else if ($i == 1) {
229 if (isset($where) && isset($what)) {
231 $to_string = "$to_string (<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>)";
233 $to_string = "$to_string (<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>)";
239 /** FORMAT THE CC STRING **/
241 if (isset ($message->header
->cc
[0]) && trim($message->header
->cc
[0])){
243 $cc_ary = $message->header
->cc
;
244 while ($i < count(decodeHeader($cc_ary))) {
245 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
247 $cc_string = "$cc_string<BR>$cc_ary[$i]";
249 $cc_string = "$cc_ary[$i]";
252 if (count($cc_ary) > 1) {
253 if ($show_more_cc == false) {
255 if (isset($where) && isset($what)) {
257 $cc_string = "$cc_string (<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>)";
259 $cc_string = "$cc_string (<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>)";
263 } else if ($i == 1) {
264 if (isset($where) && isset($what)) {
266 $cc_string = "$cc_string (<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>)";
268 $cc_string = "$cc_string (<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>)";
274 /** make sure everything will display in HTML format **/
275 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
276 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
278 do_hook('read_body_top');
281 echo '<TABLE COLS="1" CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n";
282 echo ' <TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">';
283 echo ' <TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" COLS="2" CELLPADDING="3">';
285 echo ' <TD ALIGN="LEFT" WIDTH="33%">';
287 if ($where && $what) {
288 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
290 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
292 echo _("Message List");
293 echo '</A> | ';
294 if ($where && $what) {
295 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
297 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
300 echo '</A> ';
302 echo ' </TD><TD WIDTH="33%" ALIGN="CENTER">';
303 echo ' <SMALL>' . "\n";
304 if ($where && $what) {
306 if ($currentArrayIndex == -1) {
307 echo 'Previous | Next';
309 $prev = findPreviousMessage();
310 $next = findNextMessage();
312 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
314 echo _("Previous") . ' | ';
316 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
321 echo ' </SMALL>' . "\n";
322 echo ' </TD><TD WIDTH="33%" ALIGN="RIGHT">';
324 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
326 echo '</A> | ';
327 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
329 echo '</A> | ';
330 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\">";
332 echo '</A> ';
338 echo ' <TR><TD CELLSPACING="0" WIDTH="100%">';
339 echo ' <TABLE COLS="2" WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n";
342 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
344 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
345 echo " <B>$subject</B> \n";
347 if ($where && $what) {
348 // Got here from a search
349 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> </td>";
351 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> </td>";
356 echo ' <TD BGCOLOR="' . $color[0] . '" WIDTH="15%" ALIGN="RIGHT">' . "\n";
358 echo ' </TD><TD BGCOLOR="' . $color[0] . '" WIDTH="85%" colspan="2">' . "\n";
359 echo " <B>$from_name</B> \n";
360 echo ' </TD>' . "\n";
361 echo ' </TR>' . "\n";
364 echo ' <TD BGCOLOR="' . $color[0] . '" WIDTH="15%" ALIGN="RIGHT">' . "\n";
366 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
367 echo " <B>$dateString</B> \n";
368 echo ' </TD>' . "\n";
369 echo ' </TR>' . "\n";
372 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
374 echo ' </TD><TD BGCOLOR="' . $color[0] . '" WIDTH="85%" VALIGN="TOP" colspan="2">' . "\n";
375 echo " <B>$to_string</B> \n";
376 echo ' </TD>' . "\n";
377 echo ' </TR>' . "\n";
379 if (isset($cc_string)) {
381 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
383 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
384 echo " <B>$cc_string</B> \n";
385 echo ' </TD>' . "\n";
386 echo ' </TR>' . "\n";
388 do_hook("read_body_header");
392 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
394 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
397 $body = formatBody($imapConnection, $message, $color, $wrap_at);
401 echo '<TABLE COLS="1" CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n";
402 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
403 echo '</TABLE>' . "\n";
405 do_hook('read_body_bottom');
406 do_hook('html_bottom');
407 sqimap_logout($imapConnection);