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