5 * Copyright (c) 1999-2001 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 require_once('../src/validate.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/mime.php');
17 require_once('../functions/date.php');
18 require_once('../functions/url_parser.php');
20 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
21 sqimap_mailbox_select($imapConnection, $mailbox);
23 displayPageHeader($color, $mailbox);
25 if (isset($view_hdr)) {
26 fputs ($imapConnection, sqimap_session_id() . " FETCH $passed_id BODY[HEADER]\r\n");
27 $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $a, $b);
30 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
31 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><CENTER><B>" . _("Viewing Full Header") . '</B> - ';
32 if (isset($where) && isset($what)) {
33 // Got here from a search
34 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
36 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
38 echo ''._("View message") . "</a></b></center></td></tr></table>\n" .
39 "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n" .
43 for ($i=1; $i < count($read); $i++
) {
44 $line = htmlspecialchars($read[$i]);
45 if (eregi("^>", $line)) {
47 $first[$i] = ' ';
49 } else if (eregi("^[ |\t]", $line)) {
52 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
53 $first[$i] = $regs[1] . ':';
54 $second[$i] = $regs[2];
57 $second[$i] = trim($line);
61 for ($i=0; $i < count($second); $i = $j) {
62 if (isset($first[$i])) {
65 if (isset($second[$i])) {
66 $s = nl2br($second[$i]);
69 while (($first[$j] == '') && ($j < count($first))) {
70 $s .= ' ' . nl2br($second[$j]);
74 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
76 echo "</td></tr></table>\n";
77 echo '</body></html>';
78 sqimap_logout($imapConnection);
83 * Given an IMAP message id number, this will look it up in the cached
84 * and sorted msgs array and return the index. Used for finding the next
85 * and previous messages.
87 * returns the index of the next valid message from the array
89 function findNextMessage() {
90 global $msort, $currentArrayIndex, $msgs, $sort;
94 if ($currentArrayIndex != 1) {
95 $result = $currentArrayIndex - 1;
98 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
99 if ($currentArrayIndex == $msgs[$key]['ID']) {
103 $result = $msgs[$key]['ID'];
111 /** Removes just one address from the list of addresses. */
112 function RemoveAddress(&$addr_list, $addr) {
114 foreach (array_keys($addr_list, $addr) as $key_to_delete) {
115 unset($addr_list[$key_to_delete]);
120 /** returns the index of the previous message from the array. */
121 function findPreviousMessage() {
122 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection;
123 global $mailbox, $data_dir, $username;
127 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
128 if ($currentArrayIndex != $numMessages) {
129 $result = $currentArrayIndex +
1;
132 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
133 if ($currentArrayIndex == $msgs[$key]['ID']) {
137 $result = $msgs[$key]['ID'];
147 * Displays a link to a page where the message is displayed more
148 * "printer friendly".
150 function printer_friendly_link() {
151 global $passed_id, $mailbox, $ent_num, $color;
152 global $pf_subtle_link;
153 global $javascript_on;
155 if (strlen(trim($mailbox)) < 1) {
159 $params = '?passed_ent_id=' . $ent_num;
160 $params .= '&mailbox=' . urlencode($mailbox);
161 $params .= '&passed_id=' . $passed_id;
163 $print_text = _("View Printable Version");
165 if (!$pf_subtle_link) {
166 /* The link is large, on the bottom of the header panel. */
167 $result = ' <tr bgcolor="' . $color[0] . '">' . "\n" .
168 ' <td class="medText" align="right" valign="top">' . "\n" .
170 ' </td><td class="medText" valign="top" colspan="2">'."\n";
172 /* The link is subtle, below "view full header". */
176 /* Output the link. */
177 if ($javascript_on) {
178 $result .= '<script language="javascript">' . "\n" .
180 " function printFormat() {\n" .
181 ' window.open("../src/printer_friendly_main.php' .
182 $params . '","Print","width=800,height=600");' . "\n".
186 "<A HREF=\"javascript:printFormat();\">$print_text</A>\n";
188 $result .= '<A TARGET="_blank" HREF="../src/printer_friendly_bottom.php' .
189 "$params\">$print_text</A>\n";
192 if (!$pf_subtle_link) {
193 /* The link is large, on the bottom of the header panel. */
194 $result .= ' </td>' . "\n" .
201 /*****************************/
202 /*** Main of read_boby.php ***/
203 /*****************************/
206 $currentArrayIndex = $passed_id;
207 /*** START OF COMMENTED OUT CODE - PHILIPPE, CAN THIS BE REMOVED?
208 for ($i=0; $i < count($msgs); $i++) {
209 if ($msgs[$i]["ID"] == $passed_id) {
210 $currentArrayIndex = $i;
214 *** END OF COMMENTED OUT CODE */
216 $currentArrayIndex = -1;
219 for ($i = 0; $i < count($msgs); $i++
) {
220 if ($msgs[$i]['ID'] == $passed_id) {
221 $msgs[$i]['FLAG_SEEN'] = true;
225 // $message contains all information about the message
226 // including header and body
227 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
229 /** translate the subject and mailbox into url-able text **/
230 $url_subj = urlencode(trim($message->header
->subject
));
231 $urlMailbox = urlencode($mailbox);
233 if (isset($message->header
->replyto
)) {
234 $url_replyto = urlencode($message->header
->replyto
);
237 $url_replytoall = $url_replyto;
239 // If we are replying to all, then find all other addresses and
240 // add them to the list. Remove duplicates.
241 // This is somewhat messy, so I'll explain:
242 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
243 $url_replytoall_extra_addrs = array_merge(
244 array($message->header
->from
),
245 $message->header
->to
,
249 // 2) Make one big string out of them
250 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
252 // 3) Parse that into an array of addresses
253 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
255 // 4) Make them unique -- weed out duplicates
256 // (Coded for PHP 4.0.0)
257 $url_replytoall_extra_addrs =
258 array_keys(array_flip($url_replytoall_extra_addrs));
260 // 5) Remove the addresses we'll be sending the message 'to'
261 $url_replytoall_avoid_addrs = '';
262 if (isset($message->header
->replyto
)) {
263 $url_replytoall_avoid_addrs = $message->header
->replyto
;
266 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
267 foreach ($url_replytoall_avoid_addrs as $addr) {
268 RemoveAddress($url_replytoall_extra_addrs, $addr);
271 // 6) Remove our identities from the CC list (they still can be in the
272 // TO list) only if $include_self_reply_all is turned off
273 if (!$include_self_reply_all) {
274 RemoveAddress($url_replytoall_extra_addrs,
275 getPref($data_dir, $username, 'email_address'));
276 $idents = getPref($data_dir, $username, 'identities');
277 if ($idents != '' && $idents > 1) {
278 for ($i = 1; $i < $idents; $i ++
) {
279 $cur_email_address = getPref($data_dir, $username, 'email_address' . $i);
280 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
285 // 7) Smoosh back into one nice line
286 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
289 $url_replytoallcc = urlencode($url_replytoallcc);
291 $dateString = getLongDateString($message->header
->date
);
293 // What do we reply to -- text only, if possible
294 $ent_num = findDisplayEntity($message);
296 /** TEXT STRINGS DEFINITIONS **/
297 $echo_more = _("more");
298 $echo_less = _("less");
300 if (!isset($show_more_cc)) $show_more_cc = false;
302 /** FORMAT THE TO STRING **/
305 $to_ary = $message->header
->to
;
306 while ($i < count($to_ary)) {
307 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
310 $to_string = "$to_string<BR>$to_ary[$i]";
312 $to_string = "$to_ary[$i]";
316 if (count($to_ary) > 1) {
317 if ($show_more == false) {
319 /* From a search... */
320 if (isset($where) && isset($what)) {
321 $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>)";
323 $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>)";
327 } else if ($i == 1) {
328 /* From a search... */
329 if (isset($where) && isset($what)) {
330 $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>)";
332 $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>)";
338 /** FORMAT THE CC STRING **/
340 if (isset ($message->header
->cc
[0]) && trim($message->header
->cc
[0])) {
342 $cc_ary = $message->header
->cc
;
343 while ($i < count(decodeHeader($cc_ary))) {
344 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
346 $cc_string = "$cc_string<BR>$cc_ary[$i]";
348 $cc_string = "$cc_ary[$i]";
352 if (count($cc_ary) > 1) {
353 if ($show_more_cc == false) {
355 /* From a search... */
356 if (isset($where) && isset($what)) {
357 $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>)";
359 $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>)";
363 } else if ($i == 1) {
364 /* From a search... */
365 if (isset($where) && isset($what)) {
366 $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>)";
368 $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>)";
375 /** FORMAT THE BCC STRING **/
377 if (isset ($message->header
->bcc
[0]) && trim($message->header
->bcc
[0])){
379 $bcc_ary = $message->header
->bcc
;
380 while ($i < count(decodeHeader($bcc_ary))) {
381 $bcc_ary[$i] = htmlspecialchars($bcc_ary[$i]);
383 $bcc_string = "$bcc_string<BR>$bcc_ary[$i]";
385 $bcc_string = "$bcc_ary[$i]";
389 if (count($bcc_ary) > 1) {
390 if ($show_more_cc == false) {
392 /* From a search... */
393 if (isset($where) && isset($what)) {
394 $bcc_string = "$bcc_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>)";
396 $bcc_string = "$bcc_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>)";
398 $i = count($bcc_ary);
400 } else if ($i == 1) {
401 /* From a search... */
402 if (isset($where) && isset($what)) {
403 $bcc_string = "$bcc_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>)";
405 $bcc_string = "$bcc_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>)";
412 if ($default_use_priority) {
413 switch(substr($message->header
->priority
,0,1)) {
414 /* First, check for a higher then normal priority. */
416 case "2": $priority_string = _("High"); break;
418 /* Second, check for a normal priority. */
419 case "3": $priority_string = _("Normal"); break;
421 /* Last, check for a lower then normal priority. */
423 case "5": $priority_string = _("Low"); break;
427 /** make sure everything will display in HTML format **/
428 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
429 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
431 do_hook('read_body_top');
433 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
434 ' <TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' . "\n" .
435 ' <TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' . "\n" .
437 ' <TD ALIGN="LEFT" WIDTH="33%">' . "\n" .
439 if ($where && $what) {
440 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
442 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
444 echo _("Message List");
445 echo '</A> | ';
446 if ($where && $what) {
447 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
449 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
451 echo _("Delete") . '</A> ';
452 if (($mailbox == $draft_folder) && ($save_as_draft)) {
454 echo " <A HREF=\"compose.php?mailbox=$mailbox&send_to=$to_string&send_to_cc=$cc_string&send_to_bcc=$bcc_string&subject=$url_subj&draft_id=$passed_id&ent_num=$ent_num\">";
455 echo _("Resume Draft") . '</a>';
458 echo ' ' .
461 ' <TD WIDTH="33%" ALIGN="CENTER">' . "\n" .
464 if ($where && $what) {
466 if ($currentArrayIndex == -1) {
467 echo 'Previous | Next';
469 $prev = findPreviousMessage();
470 $next = findNextMessage();
473 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
475 echo _("Previous") . ' | ';
479 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
486 echo ' </SMALL>' . "\n" .
487 ' </TD><TD WIDTH="33%" ALIGN="RIGHT">' .
489 " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">" .
491 '</A> | ' .
492 " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
494 '</A> | ' .
495 " <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\">" .
503 ' <TR><TD CELLSPACING="0" WIDTH="100%">' .
504 ' <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
508 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
510 " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
511 " <B>$subject</B> \n" .
513 ' <TD ROWSPAN="4" width=10% BGCOLOR="'.$color[0].'" ALIGN=right VALIGN=top NOWRAP><small>' . "\n";
515 /* From a search... */
516 if ($where && $what) {
517 echo "<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&view_hdr=1\">" . _("View Full Header") . "</A>\n";
519 echo "<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" . _("View Full Header") . "</A>\n";
522 /* Output the printer friendly link if we are in subtle mode. */
523 if ($pf_subtle_link) {
524 echo printer_friendly_link(true);
527 do_hook("read_body_header_right");
528 echo '</small></TD>' . "\n" .
532 echo ' <TR>' . "\n" .
533 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
535 ' </TD><TD BGCOLOR="' . $color[0] . '">' . "\n" .
536 " <B>$from_name</B> \n" .
540 echo ' <TR>' . "\n" .
541 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
543 " </TD><TD BGCOLOR=\"$color[0]\">\n" .
544 " <B>$dateString</B> \n" .
550 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
552 ' </TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
553 " <B>$to_string</B> \n" .
557 if (isset($cc_string)) {
559 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
561 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
562 " <B>$cc_string</B> \n" .
568 if (isset($bcc_string)) {
570 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
572 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
573 " <B>$bcc_string</B> \n" .
577 if ($default_use_priority) {
578 if (isset($priority_string)) {
580 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
581 " "._("Priority").": \n".
582 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
583 " <B>$priority_string</B> \n" .
589 if ($show_xmailer_default) {
590 fputs ($imapConnection, sqimap_session_id() .
591 " FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer)]\r\n");
592 $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true,
593 $response, $readmessage);
594 $mailer = substr($read[1], strpos($read[1], " "));
597 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
598 " "._("Mailer").": \n".
599 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
600 " <B>$mailer</B> \n" .
606 /* Output the printer friendly link if we are not in subtle mode. */
607 if (!$pf_subtle_link) {
608 echo printer_friendly_link(true);
611 do_hook("read_body_header");
616 echo "<TABLE CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
617 " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n" .
620 $body = formatBody($imapConnection, $message, $color, $wrap_at);
624 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
625 " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>" .
628 /* show attached images inline -- if pref'fed so */
629 if (($attachment_common_show_images) and
630 is_array($attachment_common_show_images_list)) {
631 foreach ($attachment_common_show_images_list as $img) {
632 echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
635 ' <img src="../src/download.php' .
636 '?passed_id=' . urlencode($img['passed_id']) .
637 '&mailbox=' . urlencode($img['mailbox']) .
638 '&passed_ent_id=' . urlencode($img['ent_id']) .
639 '&absolute_dl=true">' . "\n" .
646 do_hook('read_body_bottom');
647 do_hook('html_bottom');
648 sqimap_logout($imapConnection);