Added a server-side thread sort option. disabled by default (site wide)
[squirrelmail.git] / src / read_body.php
1 <?php
2
3 /**
4 * read_body.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
11 *
12 * $Id$
13 */
14
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');
20 require_once('../functions/smtp.php');
21
22 /**
23 * Given an IMAP message id number, this will look it up in the cached
24 * and sorted msgs array and return the index. Used for finding the next
25 * and previous messages.
26 *
27 * returns the index of the next valid message from the array
28 */
29 function findNextMessage() {
30 global $msort, $currentArrayIndex, $msgs, $sort, $thread_sort_messages;
31 $result = -1;
32 if ($thread_sort_messages == 1) {
33 $sort = 0;
34 }
35 if ($sort == 6) {
36 if ($currentArrayIndex != 1) {
37 $result = $currentArrayIndex - 1;
38 }
39 } else {
40 if (!is_array($msort)) {
41 return -1;
42 }
43 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
44 if ($currentArrayIndex == $msgs[$key]['ID']) {
45 next($msort);
46 $key = key($msort);
47 if (isset($key))
48 $result = $msgs[$key]['ID'];
49 break;
50 }
51 }
52 }
53 return ($result);
54 }
55
56 /** Removes just one address from the list of addresses. */
57 function RemoveAddress(&$addr_list, $addr) {
58 if ($addr != '') {
59 foreach (array_keys($addr_list, $addr) as $key_to_delete) {
60 unset($addr_list[$key_to_delete]);
61 }
62 }
63 }
64
65 /** returns the index of the previous message from the array. */
66 function findPreviousMessage() {
67 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
68 $mailbox, $data_dir, $username, $thread_sort_messages;
69 if ($thread_sort_messages == 1) {
70 $sort = 0;
71 }
72
73 $result = -1;
74
75 if ($sort == 6) {
76 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
77 if ($currentArrayIndex != $numMessages) {
78 $result = $currentArrayIndex + 1;
79 }
80 } else {
81 if (!is_array($msort)) {
82 return -1;
83 }
84 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
85 if ($currentArrayIndex == $msgs[$key]['ID']) {
86 prev($msort);
87 $key = key($msort);
88 if (isset($key)) {
89 $result = $msgs[$key]['ID'];
90 break;
91 }
92 }
93 }
94 }
95 return ($result);
96 }
97
98 /**
99 * Displays a link to a page where the message is displayed more
100 * "printer friendly".
101 */
102 function printer_friendly_link() {
103 global $passed_id, $mailbox, $ent_num, $color,
104 $pf_subtle_link,
105 $javascript_on;
106
107 if (strlen(trim($mailbox)) < 1) {
108 $mailbox = 'INBOX';
109 }
110
111 $params = '?passed_ent_id=' . $ent_num .
112 '&mailbox=' . urlencode($mailbox) .
113 '&passed_id=' . $passed_id;
114
115 $print_text = _("View Printable Version");
116
117 if (!$pf_subtle_link) {
118 /* The link is large, on the bottom of the header panel. */
119 $result = '<tr bgcolor="' . $color[0] . '">' .
120 '<td class="medText" align="right" valign="top">' .
121 '&nbsp;' .
122 '</td><td class="medText" valign="top" colspan="2">'."\n";
123 } else {
124 /* The link is subtle, below "view full header". */
125 $result = "<BR>\n";
126 }
127
128 /* Output the link. */
129 if ($javascript_on) {
130 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
131 '<!--' . "\n" .
132 " function printFormat() {\n" .
133 ' window.open("../src/printer_friendly_main.php' .
134 $params . '","Print","width=800,height=600");' . "\n".
135 " }\n" .
136 "// -->\n" .
137 "</script>\n" .
138 "<A HREF=\"javascript:printFormat();\">$print_text</A>\n";
139 } else {
140 $result .= '<A TARGET="_blank" HREF="../src/printer_friendly_bottom.php' .
141 "$params\">$print_text</A>\n";
142 }
143
144 if (!$pf_subtle_link) {
145 /* The link is large, on the bottom of the header panel. */
146 $result .= '</td></tr>' . "\n";
147 }
148
149 return ($result);
150 }
151
152 function ServerMDNSupport( $read ) {
153 /* escaping $ doesn't work -> \x36 */
154 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
155 return ( $ret );
156 }
157
158 function SendMDN ( $recipient , $sender) {
159 global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME,
160 $version, $attachments, $identity, $data_dir, $passed_id;
161
162 $header = sqimap_get_message_header($imapConnection, $passed_id, $mailbox);
163 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
164
165 // part 1 (RFC2298)
166
167 $senton = getLongDateString( $header->date );
168 $to_array = $header->to;
169 $to = '';
170 foreach ($to_array as $line) {
171 $to .= " $line ";
172 }
173
174 $subject = $header->subject;
175 $now = getLongDateString( time() );
176
177 $body = _("Your message") . "\r\n\r\n" .
178 "\t" . _("To:") . ' ' . $to . "\r\n" .
179 "\t" . _("Subject:") . ' ' . $subject . "\r\n" .
180 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
181 "\r\n" .
182 sprintf( _("Was displayed on %s"), $now );
183
184 // part2 (RFC2298)
185
186 $original_recipient = $to;
187 $original_message_id = $header->message_id;
188
189 $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
190 if ($original_recipient != '') {
191 $part2 .= "Original-Recipient : $original_recipient\r\n";
192 }
193 $final_recipient = $sender;
194 $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" .
195 "Original-Message-ID : $original_message_id\r\n" .
196 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
197
198
199 $localfilename = GenerateRandomString(32, 'FILE', 7);
200 $full_localfilename = "$hashed_attachment_dir/$localfilename";
201
202 $fp = fopen( $full_localfilename, 'w');
203 fwrite ($fp, $part2);
204 fclose($fp);
205
206 $newAttachment = array();
207 $newAttachment['localfilename'] = $localfilename;
208 $newAttachment['type'] = "message/disposition-notification";
209 $newAttachment['session']=-1;
210 $attachments[] = $newAttachment;
211 $MDN_to = trim($recipient);
212 $reply_id = 0;
213
214 return (SendMessage($MDN_to,'','', _("Read:") . ' ' . $subject, $body,$reply_id, True, 3, -1) );
215 }
216
217
218 function ToggleMDNflag ( $set ) {
219 global $imapConnection, $passed_id, $mailbox;
220 sqimap_mailbox_select($imapConnection, $mailbox);
221
222 $sg = $set?'+':'-';
223 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
224 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
225 $readmessage);
226 }
227
228 function ClearAttachments() {
229 global $username, $attachments, $attachment_dir;
230
231 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
232
233 $rem_attachments = array();
234 foreach ($attachments as $info) {
235 if ($info->session == -1) {
236 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
237 if (file_exists($attached_file)) {
238 unlink($attached_file);
239 }
240 } else {
241 $rem_attachments[] = $info;
242 }
243 }
244 $attachments = rem_attachments;
245 }
246
247 function formatRecipientString($recipients, $item ) {
248 global $base_uri, $passed_id, $urlMailbox, $startMessage, $show_more_cc, $echo_more, $echo_less, $show_more, $show_more_bcc, $sort;
249
250 $i = 0;
251 $url_string = '';
252
253 if (isset ($recipients[0]) && trim($recipients[0])) {
254 $string = '';
255 $ary = $recipients;
256
257 switch ($item) {
258 case 'to':
259 $show = "&amp;show_more=1&amp;show_more_cc=$show_more_cc&amp;show_more_bcc=$show_more_bcc";
260 $show_n = "&amp;show_more=0&amp;show_more_cc=$show_more_cc&amp;show_more_bcc=$show_more_bcc";
261 break;
262 case 'cc':
263 $show = "&amp;show_more=$show_more&amp;show_more_cc=1&amp;show_more_bcc=$show_more_bcc";
264 $show_n = "&amp;show_more=$show_more&amp;show_more_cc=0&amp;show_more_bcc=$show_more_bcc";
265 $show_more = $show_more_cc;
266 break;
267 case 'bcc':
268 $show = "&amp;show_more=$show_more&amp;show_more_cc=$show_more_cc&amp;show_more_bcc=1";
269 $show_n = "&amp;show_more=$show_more&amp;show_more_cc=$show_more_cc&amp;show_more_bcc=0";
270 $show_more = $show_more_bcc;
271 break;
272 default:
273 $break;
274 }
275
276 while ($i < count($ary)) {
277 $ary[$i] = htmlspecialchars(decodeHeader($ary[$i]));
278 $url_string .= $ary[$i];
279 if ($string) {
280 $string = "$string<BR>$ary[$i]";
281 } else {
282 $string = "$ary[$i]";
283 }
284
285 $i++;
286 if (count($ary) > 1) {
287 if ($show_more == false) {
288 if ($i == 1) {
289 /* From a search... */
290 $string .= '&nbsp;(<A HREF="' . $base_uri .
291 "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
292 if (isset($where) && isset($what)) {
293 $string .= 'what=' . urlencode($what)."&amp;where=".urlencode($where)."$show\">$echo_more</A>)";
294 } else {
295 $string .= "sort=$sort&amp;startMessage=$startMessage"."$show\">$echo_more</A>)";
296 }
297 $i = count($ary);
298 }
299 } else if ($i == 1) {
300 /* From a search... */
301 $string .= '&nbsp;(<A HREF="' . $base_uri .
302 "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
303 if (isset($where) && isset($what)) {
304 $string .= 'what=' . urlencode($what)."&amp;where=".urlencode($where)."$show_n\">$echo_less</A>)";
305 } else {
306 $string .= "sort=$sort&amp;startMessage=$startMessage"."$show_n\">$echo_less</A>)";
307 }
308 }
309 }
310
311 }
312 }
313 else {
314 $string = '';
315 }
316 $url_string = urlencode($url_string);
317 $result = array();
318 $result['str'] = $string;
319 $result['url_str'] = $url_string;
320 return $result;
321 }
322
323
324
325 /*
326 * Main of read_boby.php --------------------------------------------------
327 */
328
329 /*
330 Urled vars
331 ----------
332 $passed_id
333 */
334
335 if ( isset( $mailbox ) ) {
336 $mailbox = urldecode( $mailbox );
337 }
338 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
339 $read = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
340
341 do_hook('html_top');
342
343 /*
344 * The following code sets necesarry stuff for the MDN thing
345 */
346 if( $default_use_mdn &&
347 ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) {
348
349 $supportMDN = ServerMDNSupport($read["PERMANENTFLAGS"]);
350 $flags = sqimap_get_flags ($imapConnection, $passed_id);
351 $FirstTimeSee = !(in_array( 'Seen', $flags ));
352 }
353
354 displayPageHeader($color, $mailbox);
355
356
357 /*
358 * The following code shows the header of the message and then exit
359 */
360 if (isset($view_hdr)) {
361 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", true, $a, $b);
362
363 echo '<BR>' .
364 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
365 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>" . _("Viewing Full Header") . '</B> - '.
366 '<a href="' . $base_uri . "src/read_body.php?mailbox=".urlencode($mailbox);
367 if (isset($where) && isset($what)) {
368 // Got here from a search
369 echo "&amp;passed_id=$passed_id&amp;where=".urlencode($where)."&amp;what=".urlencode($what).'">';
370 } else {
371 echo "&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more\">";
372 }
373 echo _("View message") . "</a></b></td></tr></table>\n" .
374 "<table width=\"99%\" cellpadding=2 cellspacing=0 border=0 align=center>\n" .
375 '<tr><td>';
376
377 $cnum = 0;
378 for ($i=1; $i < count($read); $i++) {
379 $line = htmlspecialchars($read[$i]);
380 if (eregi("^&gt;", $line)) {
381 $second[$i] = $line;
382 $first[$i] = '&nbsp;';
383 $cnum++;
384 } else if (eregi("^[ |\t]", $line)) {
385 $second[$i] = $line;
386 $first[$i] = '';
387 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
388 $first[$i] = $regs[1] . ':';
389 $second[$i] = $regs[2];
390 $cnum++;
391 } else {
392 $second[$i] = trim($line);
393 $first[$i] = '';
394 }
395 }
396 for ($i=0; $i < count($second); $i = $j) {
397 if (isset($first[$i])) {
398 $f = $first[$i];
399 }
400 if (isset($second[$i])) {
401 $s = nl2br($second[$i]);
402 }
403 $j = $i + 1;
404 while (($first[$j] == '') && ($j < count($first))) {
405 $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
406 $j++;
407 }
408 parseEmail($s);
409 if (isset($f)) {
410 echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
411 }
412 }
413 echo "</td></tr></table>\n" .
414 '</body></html>';
415 sqimap_logout($imapConnection);
416 exit;
417 }
418
419 if (isset($msgs)) {
420 $currentArrayIndex = $passed_id;
421 } else {
422 $currentArrayIndex = -1;
423 }
424
425 for ($i = 0; $i < count($msgs); $i++) {
426 if ($msgs[$i]['ID'] == $passed_id) {
427 $msgs[$i]['FLAG_SEEN'] = true;
428 }
429 }
430
431 // $message contains all information about the message
432 // including header and body
433 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
434
435 /** translate the subject and mailbox into url-able text **/
436 $url_subj = urlencode(trim($message->header->subject));
437 $urlMailbox = urlencode($mailbox);
438 $url_replyto = '';
439 if (isset($message->header->replyto)) {
440 $url_replyto = urlencode($message->header->replyto);
441 }
442
443 $url_replytoall = $url_replyto;
444
445 // If we are replying to all, then find all other addresses and
446 // add them to the list. Remove duplicates.
447 // This is somewhat messy, so I'll explain:
448 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
449 $url_replytoall_extra_addrs = array_merge(
450 array($message->header->from),
451 $message->header->to,
452 $message->header->cc
453 );
454
455 // 2) Make one big string out of them
456 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
457
458 // 3) Parse that into an array of addresses
459 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
460
461 // 4) Make them unique -- weed out duplicates
462 // (Coded for PHP 4.0.0)
463 $url_replytoall_extra_addrs =
464 array_keys(array_flip($url_replytoall_extra_addrs));
465
466 // 5) Remove the addresses we'll be sending the message 'to'
467 $url_replytoall_avoid_addrs = '';
468 if (isset($message->header->replyto)) {
469 $url_replytoall_avoid_addrs = $message->header->replyto;
470 }
471
472 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
473 foreach ($url_replytoall_avoid_addrs as $addr) {
474 RemoveAddress($url_replytoall_extra_addrs, $addr);
475 }
476
477 // 6) Remove our identities from the CC list (they still can be in the
478 // TO list) only if $include_self_reply_all is turned off
479 if (!$include_self_reply_all) {
480 RemoveAddress($url_replytoall_extra_addrs,
481 getPref($data_dir, $username, 'email_address'));
482 $idents = getPref($data_dir, $username, 'identities');
483 if ($idents != '' && $idents > 1) {
484 for ($i = 1; $i < $idents; $i ++) {
485 $cur_email_address = getPref($data_dir, $username, 'email_address' . $i);
486 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
487 }
488 }
489 }
490
491 // 7) Smoosh back into one nice line
492 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
493
494 // 8) urlencode() it
495 $url_replytoallcc = urlencode($url_replytoallcc);
496
497 $dateString = getLongDateString($message->header->date);
498
499 // What do we reply to -- text only, if possible
500 $ent_num = findDisplayEntity($message);
501
502 /** TEXT STRINGS DEFINITIONS **/
503 $echo_more = _("more");
504 $echo_less = _("less");
505
506 if (!isset($show_more_cc)) {
507 $show_more_cc = FALSE;
508 }
509
510 if (!isset($show_more_bcc)) {
511 $show_more_bcc = FALSE;
512 }
513
514 /** FORMAT THE TO STRING **/
515 $to = formatRecipientString($message->header->to, "to");
516 $to_string = $to['str'];
517 $url_to_string = $to['url_str'];
518
519
520 /** FORMAT THE CC STRING **/
521
522 $cc = formatRecipientString($message->header->cc, "cc");
523 $cc_string = $cc['str'];
524 $url_cc_string = $cc['url_str'];
525
526 /** FORMAT THE BCC STRING **/
527
528 $bcc = formatRecipientString($message->header->bcc, "bcc");
529 $bcc_string = $bcc['str'];
530 $url_bcc_string = $bcc['url_str'];
531
532 if ($default_use_priority) {
533 $priority_level = substr($message->header->priority,0,1);
534
535 switch($priority_level) {
536 /* check for a higher then normal priority. */
537 case '1':
538 case '2':
539 $priority_string = _("High");
540 break;
541
542 /* check for a lower then normal priority. */
543 case '4':
544 case '5':
545 $priority_string = _("Low");
546 break;
547
548 /* check for a normal priority. */
549 case '3':
550 default:
551 $priority_level = '3';
552 $priority_string = _("Normal");
553 break;
554
555 }
556 }
557
558 /** make sure everything will display in HTML format **/
559 $from_name = decodeHeader(htmlspecialchars($message->header->from));
560 $subject = decodeHeader(htmlspecialchars($message->header->subject));
561
562 do_hook('read_body_top');
563 echo '<BR>' .
564 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' .
565 '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' .
566 '<TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' .
567 '<TR>' .
568 '<TD ALIGN="LEFT" WIDTH="33%">' .
569 '<SMALL>' .
570 '<A HREF="' . $base_uri . 'src/';
571
572 if ($where && $what) {
573 if( $pos == '' ) {
574 $pos = 0;
575 }
576 echo "search.php?where$pos=".urlencode($where)."&amp;pos=$pos&amp;what$pos=".urlencode($what)."&amp;mailbox=$urlMailbox\">";
577 } else {
578 echo "right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox\">";
579 }
580 echo _("Message List") .
581 '</A>&nbsp;|&nbsp;' .
582 '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&amp;message=$passed_id&amp;";
583 if ($where && $what) {
584 echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) . '">';
585 } else {
586 echo "sort=$sort&amp;startMessage=$startMessage\">";
587 }
588 echo _("Delete") . '</A>&nbsp;';
589 if (($mailbox == $draft_folder) && ($save_as_draft)) {
590 echo '|&nbsp;<A HREF="' . $base_uri .
591 "src/compose.php?mailbox=$mailbox&amp;send_to=$url_to_string&amp;send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;subject=$url_subj&amp;draft_id=$passed_id&amp;ent_num=$ent_num" . '"';
592 if ($compose_new_win == '1') {
593 echo 'TARGET="compose_window" onClick="comp_in_new()"';
594 }
595 echo '>'.
596 _("Resume Draft") . '</a>';
597 }
598
599 echo '&nbsp;&nbsp;' .
600 '</SMALL>' .
601 '</TD>' .
602 '<TD WIDTH="33%" ALIGN="CENTER">' .
603 '<SMALL>';
604
605 if ( !($where && $what) ) {
606
607 if ($currentArrayIndex == -1) {
608 echo 'Previous&nbsp;|&nbsp;Next';
609 } else {
610 $prev = findPreviousMessage();
611 $next = findNextMessage();
612
613 if ($prev != -1) {
614 echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$prev&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
615 } else {
616 echo _("Previous") . '&nbsp;|&nbsp;';
617 }
618
619 if ($next != -1) {
620 echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Next") . "</A>";
621 } else {
622 echo _("Next");
623 }
624 }
625 }
626
627 echo '</SMALL>' .
628 '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
629 '<SMALL>' .
630 '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&amp;forward_subj=$url_subj&amp;".
631 ($default_use_priority?"mailprio=$priority_level&amp;":'')
632 ."mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
633 if ($compose_new_win == '1') {
634 echo 'TARGET="compose_window" onClick="comp_in_new()"';
635 }
636 echo '>'.
637 _("Forward") .
638 '</A>&nbsp;|&nbsp;' .
639 '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&amp;reply_subj=$url_subj&amp;".
640 ($default_use_priority?"mailprio=$priority_level&amp;":'').
641 "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
642 if ($compose_new_win == '1') {
643 echo 'TARGET="compose_window" onClick="comp_in_new()"';
644 }
645 echo '>'.
646 _("Reply") .
647 '</A>&nbsp;|&nbsp;' .
648 '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&amp;send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
649 ($default_use_priority?"mailprio=$priority_level&amp;":'').
650 "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
651 if ($compose_new_win == '1') {
652 echo 'TARGET="compose_window" onClick="comp_in_new()"';
653 }
654 echo '>'.
655 _("Reply All") .
656 '</A>&nbsp;&nbsp;' .
657 '</SMALL>' .
658 '</TD>' .
659 '</TR>' .
660 '</TABLE>' .
661 '</TD></TR>' .
662 '<TR><TD WIDTH="100%">' .
663 '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
664 '<TR>' . "\n";
665
666 /** subject **/
667 echo "<TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
668 _("Subject:") .
669 "</TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
670 "<B>$subject</B>&nbsp;\n" .
671 "</TD>\n" .
672 '<TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] .
673 '" ALIGN=right VALIGN=top NOWRAP><small>'.
674 '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
675
676 /* From a search... */
677 if ($where && $what) {
678 echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) .
679 "&amp;view_hdr=1\">" . _("View Full Header") . "</A>\n";
680 } else {
681 echo "startMessage=$startMessage&amp;show_more=$show_more&amp;view_hdr=1\">" .
682 _("View Full Header") . "</A>\n";
683 }
684
685 /* Output the printer friendly link if we are in subtle mode. */
686 if ($pf_subtle_link) {
687 echo printer_friendly_link(true);
688 }
689
690 do_hook("read_body_header_right");
691 echo '</small></TD>' .
692 ' </TR>';
693
694 /** from **/
695 echo '<TR>' .
696 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' .
697 _("From:") .
698 '</TD><TD BGCOLOR="' . $color[0] . '">' .
699 "<B>$from_name</B>&nbsp;\n" .
700 '</TD>' .
701 '</TR>';
702 /** date **/
703 echo '<TR>' . "\n" .
704 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
705 _("Date:") .
706 "</TD><TD BGCOLOR=\"$color[0]\">\n" .
707 "<B>$dateString</B>&nbsp;\n" .
708 '</TD>' . "\n" .
709 '</TR>' . "\n";
710
711 /** to **/
712 echo "<TR>\n" .
713 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
714 _("To:") .
715 '</TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
716 "<B>$to_string</B>&nbsp;\n" .
717 '</TD>' . "\n" .
718 '</TR>' . "\n";
719 /** cc **/
720 if (isset($cc_string) && $cc_string <> '') {
721 echo '<TR>' .
722 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
723 'Cc:' .
724 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
725 "<B>$cc_string</B>&nbsp;" .
726 '</TD>' .
727 '</TR>' . "\n";
728 }
729
730 /** bcc **/
731 if (isset($bcc_string) && $bcc_string <> '') {
732 echo '<TR>'.
733 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
734 'Bcc:' .
735 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
736 "<B>$bcc_string</B>&nbsp;" .
737 '</TD>' .
738 '</TR>' . "\n";
739 }
740 if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) {
741 echo '<TR>' .
742 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
743 _("Priority") . ': '.
744 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
745 "<B>$priority_string</B>&nbsp;" .
746 '</TD>' .
747 "</TR>" . "\n";
748 }
749
750 if ($show_xmailer_default) {
751 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]", true,
752 $response, $readmessage);
753 $mailer = substr($read[1], strpos($read[1], " "));
754 if (trim($mailer)) {
755 echo '<TR>' .
756 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
757 _("Mailer") . ': '.
758 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
759 "<B>$mailer</B>&nbsp;" .
760 '</TD>' .
761 "</TR>" . "\n";
762 }
763 }
764
765 /* Output the printer friendly link if we are not in subtle mode. */
766 if (!$pf_subtle_link) {
767 echo printer_friendly_link(true);
768 }
769
770 if ($default_use_mdn) {
771 if ($mdn_user_support) {
772
773 // debug gives you the capability to remove mdn-flags
774 // $MDNDebug = false;
775 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true,
776 $response, $readmessage);
777 $MDN_to = substr($read[1], strpos($read[1], ' '));
778 $MDN_flag_present = false;
779
780 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true,
781 $response, $readmessage);
782
783 $MDN_flag_present = preg_match( '/.*\$MDNSent/i', $read[0]);
784
785 if (trim($MDN_to) &&
786 (!isset( $sendreceipt ) || $sendreceipt == '' ) ) {
787
788 if ( $MDN_flag_present && $supportMDN) {
789 $sendreceipt = 'removeMDN';
790 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
791 $sendreceipt='';
792 /*
793 if ($MDNDebug ) {
794 echo '<TR>' .
795 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
796 _("Read receipt") . ': ' .
797 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
798 '<B>' .
799 _("send") .
800 "</B> <a href=$url>[" . _("Remove MDN flag") . '] </a>' .
801 '</TD>' .
802 '</TR>' . "\n";
803 } else {
804 */
805 echo '<TR>' .
806 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
807 _("Read receipt") . ': ' .
808 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
809 '<B>'._("send").'</B>'.
810 '</TD>' .
811 '</TR>' . "\n";
812 /*
813 }
814 */
815
816 } // when deleted or draft flag is set don't offer to send a MDN response
817 else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) {
818 echo '<TR>' .
819 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
820 _("Read receipt") . ': '.
821 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
822 '<B>' . _("requested") . "</B>" .
823 '</TD>' .
824 '</TR>' . "\n";
825 }
826 // if no MDNsupport don't use the annoying popup messages
827 else if ( !$FirstTimeSee ) {
828 $sendreceipt = 'send';
829 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
830 echo '<TR>' .
831 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
832 _("Read receipt") . ': ' .
833 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
834 '<B>' . _("requested") .
835 "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
836 '</TD>' .
837 '</TR>' . "\n";
838 $sendreceipt='';
839 }
840 else {
841 $sendreceipt = 'send';
842 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
843 if ($javascript_on) {
844 echo "<script language=\"javascript\" type=\"text/javascript\"> \n" .
845 '<!-- ' . "\n" .
846 " if (window.confirm(\"" .
847 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
848 "\")) { \n" .
849 " window.location=($url); \n" .
850 ' window.reload()' . "\n" .
851 ' }' . "\n" .
852 '// -->' . "\n" .
853 '</script>' . "\n";
854 }
855 echo '<TR>' .
856 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
857 _("Read receipt") . ': ' .
858 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
859 '<B>' . _("requested") . "&nbsp&nbsp</B><a href=$url>" . '[' .
860 _("Send read receipt now") . '] </a>' ." \n" .
861 '</TD>' .
862 '</TR>' . "\n";
863 $sendreceipt = '';
864 }
865 }
866
867 if ( !isset( $sendreceipt ) || $sendreceipt == '' ) {
868 } else if ( $sendreceipt == 'send' ) {
869 if ( !$MDN_flag_present) {
870 if (isset($identity) ) {
871 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
872 } else {
873 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
874 }
875
876 $final_recipient = trim($final_recipient);
877 if ($final_recipient == '' ) {
878 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
879 }
880
881 if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN ) {
882 ToggleMDNflag( true);
883 }
884 }
885 $sendreceipt = 'removeMDN';
886 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
887 $sendreceipt='';
888 /*
889 if ($MDNDebug && $supportMDN) {
890 echo " <TR>\n" .
891 " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" .
892 " "._("Read receipt").": \n".
893 " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
894 ' <B>'._("send").'</B>'." <a href=$url>" . '[' . _("Remove MDN flag") . '] </a>' . "\n" .
895 ' </TD>' . "\n" .
896 ' </TR>' . "\n";
897 } else {
898 */
899 echo " <TR>\n" .
900 " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" .
901 " "._("Read receipt").": \n".
902 " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
903 ' <B>'._("send").'</B>'. "\n" .
904 ' </TD>' . "\n" .
905 ' </TR>' . "\n";
906 /*
907 }
908 */
909 }
910 elseif ($sendreceipt == 'removeMDN' ) {
911 ToggleMDNflag ( false );
912
913 $sendreceipt = 'send';
914 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
915 echo '<TR>'.
916 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
917 _("Read receipt") . ': ' .
918 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
919 '<B>' . _("requested") .
920 "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
921 '</TD>' .
922 '</TR>' . "\n";
923 $sendreceipt = '';
924
925 }
926 }
927 }
928
929 do_hook('read_body_header');
930
931 echo '</TABLE>' .
932 ' </TD></TR>' .
933 '</TABLE>';
934 flush();
935
936 echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
937 " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" .
938 '<BR>'.
939 formatBody($imapConnection, $message, $color, $wrap_at).
940 '</TD></TR></TABLE>' .
941 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
942 " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>" .
943 '</TABLE>' . "\n";
944
945 /* show attached images inline -- if pref'fed so */
946 if (($attachment_common_show_images) &&
947 is_array($attachment_common_show_images_list)) {
948
949 foreach ($attachment_common_show_images_list as $img) {
950 $imgurl = '../src/download.php' .
951 '?' .
952 'passed_id=' . urlencode($img['passed_id']) .
953 '&amp;mailbox=' . urlencode($mailbox) .
954 '&amp;passed_ent_id=' . urlencode($img['ent_id']) .
955 '&amp;absolute_dl=true';
956
957 echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
958 '<TR>' .
959 '<TD>' .
960 "<img src=\"$imgurl\">\n" .
961 "</TD>\n" .
962 "</TR>\n" .
963 "</TABLE>\n";
964
965 }
966 }
967
968
969 do_hook('read_body_bottom');
970 do_hook('html_bottom');
971 sqimap_logout($imapConnection);
972 ?>
973 </body>
974 </html>