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