bf3ce39162558b2d18b2ba8d0be63f0f59d37f37
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/mime.php');
18 require_once('../functions/date.php');
19 require_once('../functions/url_parser.php');
22 * Given an IMAP message id number, this will look it up in the cached
23 * and sorted msgs array and return the index. Used for finding the next
24 * and previous messages.
26 * returns the index of the next valid message from the array
28 function findNextMessage() {
29 global $msort, $currentArrayIndex, $msgs, $sort;
33 if ($currentArrayIndex != 1) {
34 $result = $currentArrayIndex - 1;
37 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
38 if ($currentArrayIndex == $msgs[$key]['ID']) {
42 $result = $msgs[$key]['ID'];
50 /** Removes just one address from the list of addresses. */
51 function RemoveAddress(&$addr_list, $addr) {
53 foreach (array_keys($addr_list, $addr) as $key_to_delete) {
54 unset($addr_list[$key_to_delete]);
59 /** returns the index of the previous message from the array. */
60 function findPreviousMessage() {
61 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection;
62 global $mailbox, $data_dir, $username;
66 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
67 if ($currentArrayIndex != $numMessages) {
68 $result = $currentArrayIndex +
1;
71 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
72 if ($currentArrayIndex == $msgs[$key]['ID']) {
76 $result = $msgs[$key]['ID'];
86 * Displays a link to a page where the message is displayed more
89 function printer_friendly_link() {
90 global $passed_id, $mailbox, $ent_num, $color;
91 global $pf_subtle_link;
92 global $javascript_on;
94 if (strlen(trim($mailbox)) < 1) {
98 $params = '?passed_ent_id=' . $ent_num;
99 $params .= '&mailbox=' . urlencode($mailbox);
100 $params .= '&passed_id=' . $passed_id;
102 $print_text = _("View Printable Version");
104 if (!$pf_subtle_link) {
105 /* The link is large, on the bottom of the header panel. */
106 $result = ' <tr bgcolor="' . $color[0] . '">' . "\n" .
107 ' <td class="medText" align="right" valign="top">' . "\n" .
109 ' </td><td class="medText" valign="top" colspan="2">'."\n";
111 /* The link is subtle, below "view full header". */
115 /* Output the link. */
116 if ($javascript_on) {
117 $result .= '<script language="javascript">' . "\n" .
119 " function printFormat() {\n" .
120 ' window.open("../src/printer_friendly_main.php' .
121 $params . '","Print","width=800,height=600");' . "\n".
125 "<A HREF=\"javascript:printFormat();\">$print_text</A>\n";
127 $result .= '<A TARGET="_blank" HREF="../src/printer_friendly_bottom.php' .
128 "$params\">$print_text</A>\n";
131 if (!$pf_subtle_link) {
132 /* The link is large, on the bottom of the header panel. */
133 $result .= ' </td>' . "\n" .
140 /*****************************/
141 /*** Main of read_boby.php ***/
142 /*****************************/
144 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
145 sqimap_mailbox_select($imapConnection, $mailbox);
147 displayPageHeader($color, $mailbox);
149 if (isset($view_hdr)) {
150 fputs ($imapConnection, sqimap_session_id() . " FETCH $passed_id BODY[HEADER]\r\n");
151 $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $a, $b);
154 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
155 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\"><CENTER><B>" . _("Viewing Full Header") . '</B> - '.
156 '<a href="' . $base_uri . "src/read_body.php?mailbox=".urlencode($mailbox);
157 if (isset($where) && isset($what)) {
158 // Got here from a search
159 echo "&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
161 echo "&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
163 echo ''._("View message") . "</a></b></center></td></tr></table>\n" .
164 "<table width=\"99%\" cellpadding=2 cellspacing=0 border=0 align=center>\n" .
168 for ($i=1; $i < count($read); $i++
) {
169 $line = htmlspecialchars($read[$i]);
170 if (eregi("^>", $line)) {
172 $first[$i] = ' ';
174 } else if (eregi("^[ |\t]", $line)) {
177 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
178 $first[$i] = $regs[1] . ':';
179 $second[$i] = $regs[2];
182 $second[$i] = trim($line);
186 for ($i=0; $i < count($second); $i = $j) {
187 if (isset($first[$i])) {
190 if (isset($second[$i])) {
191 $s = nl2br($second[$i]);
194 while (($first[$j] == '') && ($j < count($first))) {
195 $s .= ' ' . nl2br($second[$j]);
199 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
201 echo "</td></tr></table>\n";
202 echo '</body></html>';
203 sqimap_logout($imapConnection);
208 $currentArrayIndex = $passed_id;
210 $currentArrayIndex = -1;
213 for ($i = 0; $i < count($msgs); $i++
) {
214 if ($msgs[$i]['ID'] == $passed_id) {
215 $msgs[$i]['FLAG_SEEN'] = true;
219 // $message contains all information about the message
220 // including header and body
221 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
223 /** translate the subject and mailbox into url-able text **/
224 $url_subj = urlencode(trim($message->header
->subject
));
225 $urlMailbox = urlencode($mailbox);
227 if (isset($message->header
->replyto
)) {
228 $url_replyto = urlencode($message->header
->replyto
);
231 $url_replytoall = $url_replyto;
233 // If we are replying to all, then find all other addresses and
234 // add them to the list. Remove duplicates.
235 // This is somewhat messy, so I'll explain:
236 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
237 $url_replytoall_extra_addrs = array_merge(
238 array($message->header
->from
),
239 $message->header
->to
,
243 // 2) Make one big string out of them
244 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
246 // 3) Parse that into an array of addresses
247 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
249 // 4) Make them unique -- weed out duplicates
250 // (Coded for PHP 4.0.0)
251 $url_replytoall_extra_addrs =
252 array_keys(array_flip($url_replytoall_extra_addrs));
254 // 5) Remove the addresses we'll be sending the message 'to'
255 $url_replytoall_avoid_addrs = '';
256 if (isset($message->header
->replyto
)) {
257 $url_replytoall_avoid_addrs = $message->header
->replyto
;
260 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
261 foreach ($url_replytoall_avoid_addrs as $addr) {
262 RemoveAddress($url_replytoall_extra_addrs, $addr);
265 // 6) Remove our identities from the CC list (they still can be in the
266 // TO list) only if $include_self_reply_all is turned off
267 if (!$include_self_reply_all) {
268 RemoveAddress($url_replytoall_extra_addrs,
269 getPref($data_dir, $username, 'email_address'));
270 $idents = getPref($data_dir, $username, 'identities');
271 if ($idents != '' && $idents > 1) {
272 for ($i = 1; $i < $idents; $i ++
) {
273 $cur_email_address = getPref($data_dir, $username, 'email_address' . $i);
274 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
279 // 7) Smoosh back into one nice line
280 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
283 $url_replytoallcc = urlencode($url_replytoallcc);
285 $dateString = getLongDateString($message->header
->date
);
287 // What do we reply to -- text only, if possible
288 $ent_num = findDisplayEntity($message);
290 /** TEXT STRINGS DEFINITIONS **/
291 $echo_more = _("more");
292 $echo_less = _("less");
294 if (!isset($show_more_cc)) $show_more_cc = false;
296 /** FORMAT THE TO STRING **/
299 $to_ary = $message->header
->to
;
300 while ($i < count($to_ary)) {
301 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
304 $to_string = "$to_string<BR>$to_ary[$i]";
306 $to_string = "$to_ary[$i]";
310 if (count($to_ary) > 1) {
311 if ($show_more == false) {
313 /* From a search... */
314 $to_string .= ' (<A HREF="' . $base_uri .
315 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
316 if (isset($where) && isset($what)) {
317 $to_string .= 'where='.urlencode($where)."&what=".urlencode($what)."&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
319 $to_string .= "sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
323 } else if ($i == 1) {
324 /* From a search... */
325 $to_string .= ' (<A HREF="' . $base_uri .
326 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
327 if (isset($where) && isset($what)) {
328 $to_string .= 'where='.urlencode($where)."&what=".urlencode($what)."&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
330 $to_string .= "sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
336 /** FORMAT THE CC STRING **/
338 if (isset ($message->header
->cc
[0]) && trim($message->header
->cc
[0])) {
340 $cc_ary = $message->header
->cc
;
341 while ($i < count(decodeHeader($cc_ary))) {
342 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
344 $cc_string = "$cc_string<BR>$cc_ary[$i]";
346 $cc_string = "$cc_ary[$i]";
350 if (count($cc_ary) > 1) {
351 if ($show_more_cc == false) {
353 /* From a search... */
354 $cc_string .= ' (<A HREF="' . $base_uri .
355 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id";
356 if (isset($where) && isset($what)) {
357 $cc_string .= '&what='.urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
359 $cc_string .= "&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 $cc_string .= ' (<A HREF="' . $base_uri .
366 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
367 if (isset($where) && isset($what)) {
368 $cc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
370 $cc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
377 /** FORMAT THE BCC STRING **/
379 if (isset ($message->header
->bcc
[0]) && trim($message->header
->bcc
[0])){
381 $bcc_ary = $message->header
->bcc
;
382 while ($i < count(decodeHeader($bcc_ary))) {
383 $bcc_ary[$i] = htmlspecialchars($bcc_ary[$i]);
385 $bcc_string = "$bcc_string<BR>$bcc_ary[$i]";
387 $bcc_string = "$bcc_ary[$i]";
391 if (count($bcc_ary) > 1) {
392 if ($show_more_cc == false) {
394 /* From a search... */
395 $bcc_string .= ' (<A HREF="' . $base_uri .
396 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
397 if (isset($where) && isset($what)) {
398 $bcc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
400 $bcc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
402 $i = count($bcc_ary);
404 } else if ($i == 1) {
405 /* From a search... */
406 $bcc_string .= ' (<A HREF="' . $base_uri .
407 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
408 if (isset($where) && isset($what)) {
409 $bcc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
411 $bcc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
418 if ($default_use_priority) {
419 $priority_level = substr($message->header
->priority
,0,1);
421 switch($priority_level) {
422 /* First, check for a higher then normal priority. */
424 case "2": $priority_string = _("High"); break;
426 /* Second, check for a normal priority. */
427 case "3": $priority_string = _("Normal"); break;
429 /* Last, check for a lower then normal priority. */
431 case "5": $priority_string = _("Low"); break;
435 /** make sure everything will display in HTML format **/
436 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
437 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
439 do_hook('read_body_top');
441 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
442 ' <TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' . "\n" .
443 ' <TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' . "\n" .
445 ' <TD ALIGN="LEFT" WIDTH="33%">' . "\n" .
447 '<A HREF="' . $base_uri . 'src/';
449 if ($where && $what) {
453 echo "search.php?where$pos=".urlencode($where)."&pos=$pos&what$pos=".urlencode($what)."&mailbox=$urlMailbox\">";
455 echo "right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
457 echo _("Message List") .
458 '</A> | ' .
459 '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&message=$passed_id&";
460 if ($where && $what) {
461 echo 'where=' . urlencode($where) . '&what=' . urlencode($what) . '">';
463 echo "sort=$sort&startMessage=$startMessage\">";
465 echo _("Delete") . '</A> ';
466 if (($mailbox == $draft_folder) && ($save_as_draft)) {
467 echo '| <A HREF="' . $base_uri .
468 "src/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\">".
469 _("Resume Draft") . '</a>';
472 echo ' ' .
475 ' <TD WIDTH="33%" ALIGN="CENTER">' . "\n" .
478 if ( !($where && $what) ) {
480 if ($currentArrayIndex == -1) {
481 echo 'Previous | Next';
483 $prev = findPreviousMessage();
484 $next = findNextMessage();
487 echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
489 echo _("Previous") . ' | ';
493 echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
500 echo ' </SMALL>' . "\n" .
501 ' </TD><TD WIDTH="33%" ALIGN="RIGHT">' .
503 ' <A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&forward_subj=$url_subj&".
504 (isset($default_use_priority)?
"mailprio=$priority_level&":"")
505 ."mailbox=$urlMailbox&ent_num=$ent_num\">" .
507 '</A> | ' .
508 ' <A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&reply_subj=$url_subj&".
509 (isset($default_use_priority)?
"mailprio=$priority_level&":"").
510 "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
512 '</A> | ' .
513 ' <A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&".
514 (isset($default_use_priority)?
"mailprio=$priority_level&":"").
515 "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
523 ' <TR><TD CELLSPACING="0" WIDTH="100%">' .
524 ' <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
528 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
530 " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
531 " <B>$subject</B> \n" .
533 ' <TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] .
534 '" ALIGN=right VALIGN=top NOWRAP><small>'.
535 '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
537 /* From a search... */
538 if ($where && $what) {
539 echo 'where=' . urlencode($where) . '&what=' . urlencode($what) .
540 "&view_hdr=1\">" . _("View Full Header") . "</A>\n";
542 echo "startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" .
543 _("View Full Header") . "</A>\n";
546 /* Output the printer friendly link if we are in subtle mode. */
547 if ($pf_subtle_link) {
548 echo printer_friendly_link(true);
551 do_hook("read_body_header_right");
552 echo '</small></TD>' . "\n" .
556 echo ' <TR>' . "\n" .
557 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
559 ' </TD><TD BGCOLOR="' . $color[0] . '">' . "\n" .
560 " <B>$from_name</B> \n" .
564 echo ' <TR>' . "\n" .
565 ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
567 " </TD><TD BGCOLOR=\"$color[0]\">\n" .
568 " <B>$dateString</B> \n" .
574 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
576 ' </TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
577 " <B>$to_string</B> \n" .
581 if (isset($cc_string)) {
583 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
585 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
586 " <B>$cc_string</B> \n" .
592 if (isset($bcc_string)) {
594 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
596 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
597 " <B>$bcc_string</B> \n" .
601 if ($default_use_priority) {
602 if (isset($priority_string)) {
604 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
605 " "._("Priority").": \n".
606 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
607 " <B>$priority_string</B> \n" .
613 if ($show_xmailer_default) {
614 fputs ($imapConnection, sqimap_session_id() .
615 " FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]\r\n");
616 $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true,
617 $response, $readmessage);
618 $mailer = substr($read[1], strpos($read[1], " "));
621 " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
622 " "._("Mailer").": \n".
623 " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n" .
624 " <B>$mailer</B> \n" .
630 /* Output the printer friendly link if we are not in subtle mode. */
631 if (!$pf_subtle_link) {
632 echo printer_friendly_link(true);
635 do_hook("read_body_header");
640 echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
641 " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" .
643 formatBody($imapConnection, $message, $color, $wrap_at).
645 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
646 " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>" .
649 /* show attached images inline -- if pref'fed so */
650 if (($attachment_common_show_images) and
651 is_array($attachment_common_show_images_list)) {
652 foreach ($attachment_common_show_images_list as $img) {
653 echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
656 ' <img src="../src/download.php' .
657 '?passed_id=' . urlencode($img['passed_id']) .
658 '&mailbox=' . urlencode($img['mailbox']) .
659 '&passed_ent_id=' . urlencode($img['ent_id']) .
660 '&absolute_dl=true">' . "\n" .
667 do_hook('read_body_bottom');
668 do_hook('html_bottom');
669 sqimap_logout($imapConnection);