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 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]))
64 if (isset($second[$i]))
65 $s = nl2br($second[$i]);
67 while ($first[$j] == '' && $j < count($first)) {
68 $s .= ' ' . nl2br($second[$j]);
72 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
74 echo "</td></tr></table>\n";
75 echo '</body></html>';
76 sqimap_logout($imapConnection);
80 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
81 // return the index. used for finding the next and previous messages
83 // returns the index of the next valid message from the array
84 function findNextMessage() {
85 global $msort, $currentArrayIndex, $msgs, $sort;
88 if ($currentArrayIndex != 1) {
89 return $currentArrayIndex - 1;
92 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
93 if ($currentArrayIndex == $msgs[$key]['ID']) {
97 return $msgs[$key]['ID'];
104 // Removes just one address from the list of addresses
105 function RemoveAddress(&$addr_list, $addr) {
108 foreach (array_keys($addr_list, $addr) as $key_to_delete)
110 unset($addr_list[$key_to_delete]);
115 // returns the index of the previous message from the array
116 function findPreviousMessage() {
117 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
118 $mailbox, $data_dir, $username;
120 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
121 if ($currentArrayIndex != $numMessages) {
122 return $currentArrayIndex +
1;
125 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
126 if ($currentArrayIndex == $msgs[$key]['ID']) {
130 return $msgs[$key]['ID'];
138 // displays a link to a page where the message is displayed
139 // more "printer friendly"
141 function printer_friendly_link($subtle) {
142 global $passed_id, $mailbox, $ent_num, $color;
143 global $pf_subtle_link;
145 if ($pf_subtle_link != $subtle) return;
147 if (strlen(trim($mailbox)) < 1)
150 $params = '?passed_ent_id=' . $ent_num . '&mailbox=' . urlencode($mailbox) .
151 '&passed_id=' . $passed_id;
152 $text = _("View printable version");
155 // the link is large, on the bottom of the header panel
156 echo ' <tr bgcolor="' . $color[0] . '">' . "\n" .
157 ' <td class="medText" align="right" valign="top">' . "\n" .
159 ' </td><td class="medText" valign="top" colspan="2">'."\n";
161 // the link is subtle, below "view full header"
166 echo ' <script language="javascript">' . "\n" .
168 ' function printFormat() {' . "\n" .
169 ' window.open("../src/printer_friendly_main.php' .
170 $params . '","Print","width=800,height=600");' . "\n".
172 ' document.write(' . "'" .
173 ' <a href="javascript:printFormat();">' . $text . '</a>' .
176 ' </script>' . "\n" .
178 ' <noscript>' . "\n" .
179 ' <a target="_blank" href="../src/printer_friendly_bottom.php' .
182 ' </noscript>' . "\n";
185 // the link is large, on the bottom of the header panel
186 echo ' </td>' . "\n" .
191 // main of read_boby.php
194 $currentArrayIndex = $passed_id;
196 for ($i=0; $i < count($msgs); $i++) {
197 if ($msgs[$i]["ID"] == $passed_id) {
198 $currentArrayIndex = $i;
204 $currentArrayIndex = -1;
207 for ($i = 0; $i < count($msgs); $i++
) {
208 if ($msgs[$i]['ID'] == $passed_id)
209 $msgs[$i]['FLAG_SEEN'] = true;
212 // $message contains all information about the message
213 // including header and body
214 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
216 /** translate the subject and mailbox into url-able text **/
217 $url_subj = urlencode(trim($message->header
->subject
));
218 $urlMailbox = urlencode($mailbox);
220 if (isset($message->header
->replyto
))
221 $url_replyto = urlencode($message->header
->replyto
);
223 $url_replytoall = $url_replyto;
225 // If we are replying to all, then find all other addresses and
226 // add them to the list. Remove duplicates.
227 // This is somewhat messy, so I'll explain:
228 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
229 $url_replytoall_extra_addrs = array_merge(array($message->header
->from
),
230 $message->header
->to
, $message->header
->cc
);
232 // 2) Make one big string out of them
233 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
235 // 3) Parse that into an array of addresses
236 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
238 // 4) Make them unique -- weed out duplicates
239 // (Coded for PHP 4.0.0)
240 $url_replytoall_extra_addrs =
241 array_keys(array_flip($url_replytoall_extra_addrs));
243 // 5) Remove the addresses we'll be sending the message 'to'
244 $url_replytoall_avoid_addrs = '';
245 if (isset($message->header
->replyto
)) {
246 $url_replytoall_avoid_addrs = $message->header
->replyto
;
249 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
250 foreach ($url_replytoall_avoid_addrs as $addr) {
251 RemoveAddress($url_replytoall_extra_addrs, $addr);
254 // 6) Remove our identities from the CC list (they still can be in the
255 // TO list) only if $include_self_reply_all is turned off
256 if (!$include_self_reply_all) {
257 RemoveAddress($url_replytoall_extra_addrs,
258 getPref($data_dir, $username, 'email_address'));
259 $idents = getPref($data_dir, $username, 'identities');
260 if ($idents != '' && $idents > 1) {
261 for ($i = 1; $i < $idents; $i ++
) {
262 RemoveAddress($url_replytoall_extra_addrs,
263 getPref($data_dir, $username, 'email_address' .
269 // 7) Smoosh back into one nice line
270 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
273 $url_replytoallcc = urlencode($url_replytoallcc);
275 $dateString = getLongDateString($message->header
->date
);
277 // What do we reply to -- text only, if possible
278 $ent_num = findDisplayEntity($message);
280 /** TEXT STRINGS DEFINITIONS **/
281 $echo_more = _("more");
282 $echo_less = _("less");
284 if (!isset($show_more_cc)) $show_more_cc = false;
286 /** FORMAT THE TO STRING **/
289 $to_ary = $message->header
->to
;
290 while ($i < count($to_ary)) {
291 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
294 $to_string = "$to_string<BR>$to_ary[$i]";
296 $to_string = "$to_ary[$i]";
299 if (count($to_ary) > 1) {
300 if ($show_more == false) {
302 if (isset($where) && isset($what)) {
304 $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>)";
306 $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>)";
310 } else if ($i == 1) {
311 if (isset($where) && isset($what)) {
313 $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>)";
315 $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>)";
321 /** FORMAT THE CC STRING **/
323 if (isset ($message->header
->cc
[0]) && trim($message->header
->cc
[0])){
325 $cc_ary = $message->header
->cc
;
326 while ($i < count(decodeHeader($cc_ary))) {
327 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
329 $cc_string = "$cc_string<BR>$cc_ary[$i]";
331 $cc_string = "$cc_ary[$i]";
334 if (count($cc_ary) > 1) {
335 if ($show_more_cc == false) {
337 if (isset($where) && isset($what)) {
339 $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>)";
341 $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>)";
345 } else if ($i == 1) {
346 if (isset($where) && isset($what)) {
348 $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>)";
350 $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>)";
356 /** FORMAT THE BCC STRING **/
358 if (isset ($message->header
->bcc
[0]) && trim($message->header
->bcc
[0])){
360 $bcc_ary = $message->header
->bcc
;
361 while ($i < count(decodeHeader($bcc_ary))) {
362 $bcc_ary[$i] = htmlspecialchars($bcc_ary[$i]);
364 $bcc_string = "$bcc_string<BR>$bcc_ary[$i]";
366 $bcc_string = "$bcc_ary[$i]";
369 if (count($bcc_ary) > 1) {
370 if ($show_more_cc == false) {
372 if (isset($where) && isset($what)) {
374 $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>)";
376 $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>)";
378 $i = count($bcc_ary);
380 } else if ($i == 1) {
381 if (isset($where) && isset($what)) {
383 $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>)";
385 $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>)";
392 if($default_use_priority) {
393 switch(substr($message->header
->priority
,0,1)) {
394 case "1" : $priority_string = _("High");
396 case "3" : $priority_string = _("Normal");
398 case "5" : $priority_string = _("Low");
402 /** make sure everything will display in HTML format **/
403 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
404 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
406 do_hook('read_body_top');
408 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
409 ' <TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' . "\n" .
410 ' <TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' . "\n" .
412 ' <TD ALIGN="LEFT" WIDTH="33%">' . "\n" .
414 if ($where && $what) {
415 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
417 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
419 echo _("Message List");
420 echo '</A> | ';
421 if ($where && $what) {
422 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
424 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
426 echo _("Delete") . '</A> ';
427 if (($mailbox == $draft_folder) && ($save_as_draft)) {
429 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\">";
430 echo _("Resume Draft") . '</a>';
432 echo ' ' .
434 ' </TD><TD WIDTH="33%" ALIGN="CENTER">' .
437 if ($where && $what) {
439 if ($currentArrayIndex == -1) {
440 echo 'Previous | Next';
442 $prev = findPreviousMessage();
443 $next = findNextMessage();
445 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
447 echo _("Previous") . ' | ';
449 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
454 echo ' </SMALL>' . "\n" .
455 ' </TD><TD WIDTH="33%" ALIGN="RIGHT">' .
457 " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">" .
459 '</A> | ' .
460 " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
462 '</A> | ' .
463 " <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\">" .
471 ' <TR><TD CELLSPACING="0" WIDTH="100%">' .
472 ' <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
475 " <TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
477 " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
478 " <B>$subject</B> \n" .
480 ' <TD ROWSPAN="4" width=10% BGCOLOR="'.$color[0].'" ALIGN=right VALIGN=top NOWRAP><small>' . "\n";
481 if ($where && $what) {
482 // Got here from a search
483 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";
485 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";
487 printer_friendly_link(1); // 1 = subtle link
488 do_hook("read_body_header_right");
489 echo '</small></TD>' . "\n" .
493 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
495 ' </TD><TD BGCOLOR="' . $color[0] . '">' . "\n" .
496 " <B>$from_name</B> \n" .
501 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
503 " </TD><TD BGCOLOR=\"$color[0]\">\n" .
504 " <B>$dateString</B> \n" .
509 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
511 ' </TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
512 " <B>$to_string</B> \n" .
516 if (isset($cc_string)) {
518 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
520 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
521 " <B>$cc_string</B> \n" .
526 if (isset($bcc_string)) {
528 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
530 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
531 " <B>$bcc_string</B> \n" .
535 if ($default_use_priority) {
536 if (isset($priority_string)) {
538 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
539 " "._("Priority").": \n".
540 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
541 " <B>$priority_string</B> \n" .
546 if ($show_xmailer_default) {
547 fputs ($imapConnection, sqimap_session_id() .
548 " FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer)]\r\n");
549 $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true,
550 $response, $readmessage);
551 $mailer = substr($read[1], strpos($read[1], " "));
554 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
555 " "._("Mailer").": \n".
556 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
557 " <B>$mailer</B> \n" .
563 printer_friendly_link(0); // 0 = unsubtle link
564 do_hook("read_body_header");
569 echo "<TABLE CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
570 " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n" .
573 $body = formatBody($imapConnection, $message, $color, $wrap_at);
577 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
578 " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>" .
581 /* show attached images inline -- if pref'fed so */
583 if (($attachment_common_show_images) and
584 is_array($attachment_common_show_images_list)) {
585 foreach ($attachment_common_show_images_list as $img) {
586 echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
589 ' <img src="../src/download.php' .
590 '?passed_id=' . urlencode($img['passed_id']) .
591 '&mailbox=' . urlencode($img['mailbox']) .
592 '&passed_ent_id=' . urlencode($img['ent_id']) .
593 '&absolute_dl=true">' . "\n" .
600 do_hook('read_body_bottom');
601 do_hook('html_bottom');
602 sqimap_logout($imapConnection);