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