"Kent B. Hansen" <kent@tpv.dk> & r2l by Yoav
[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 = html_tag( 'tr', '', '', $color[0] ) .
160 html_tag( 'td', '&nbsp;', 'right', '', 'class="medText" valign="top"' ) .
161 html_tag( 'td', '', 'left', '', 'class="medText" valign="top" colspan="2"' ) . "\n";
162 } else {
163 /* The link is subtle, below "view full header". */
164 $result = "<br>\n";
165 }
166
167 /* Output the link. */
168 if ($javascript_on) {
169 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
170 '<!--' . "\n" .
171 " function printFormat() {\n" .
172 ' window.open("../src/printer_friendly_main.php' .
173 $params . '","Print","width=800,height=600");' . "\n".
174 " }\n" .
175 "// -->\n" .
176 "</script>\n" .
177 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
178 } else {
179 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
180 "$params\">$print_text</a>\n";
181 }
182
183 if (!$pf_subtle_link) {
184 /* The link is large, on the bottom of the header panel. */
185 $result .= '</td></tr>' . "\n";
186 }
187
188 return ($result);
189 }
190
191 function ServerMDNSupport( $read ) {
192 /* escaping $ doesn't work -> \x36 */
193 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
194 return ( $ret );
195 }
196
197 function SendMDN ( $recipient , $sender) {
198 global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME,
199 $version, $attachments, $identity, $data_dir, $passed_id;
200
201 $header = sqimap_get_message_header($imapConnection, $passed_id, $mailbox);
202 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
203
204 // part 1 (RFC2298)
205
206 $senton = getLongDateString( $header->date );
207 $to_array = $header->to;
208 $to = '';
209 foreach ($to_array as $line) {
210 $to .= " $line ";
211 }
212
213 $subject = $header->subject;
214 $now = getLongDateString( time() );
215
216 set_my_charset();
217
218 $body = _("Your message") . "\r\n\r\n" .
219 "\t" . _("To:") . ' ' . $to . "\r\n" .
220 "\t" . _("Subject:") . ' ' . $subject . "\r\n" .
221 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
222 "\r\n" .
223 sprintf( _("Was displayed on %s"), $now );
224
225 // part2 (RFC2298)
226
227 $original_recipient = $to;
228 $original_message_id = $header->message_id;
229
230 $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
231 if ($original_recipient != '') {
232 $part2 .= "Original-Recipient : $original_recipient\r\n";
233 }
234 $final_recipient = $sender;
235 $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" .
236 "Original-Message-ID : $original_message_id\r\n" .
237 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
238
239
240 $localfilename = GenerateRandomString(32, 'FILE', 7);
241 $full_localfilename = "$hashed_attachment_dir/$localfilename";
242
243 $fp = fopen( $full_localfilename, 'w');
244 fwrite ($fp, $part2);
245 fclose($fp);
246
247 $newAttachment = array();
248 $newAttachment['localfilename'] = $localfilename;
249 $newAttachment['type'] = "message/disposition-notification";
250 $newAttachment['session']=-1;
251 $attachments[] = $newAttachment;
252 $MDN_to = trim($recipient);
253 $reply_id = 0;
254
255 return (SendMessage($MDN_to, '', '', _("Read:") . ' ' . $subject,
256 $body, $reply_id, True, 3, -1) );
257 }
258
259
260 function ToggleMDNflag ( $set ) {
261 global $imapConnection, $passed_id, $mailbox;
262 sqimap_mailbox_select($imapConnection, $mailbox);
263 $sg = $set?'+':'-';
264 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
265 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
266 $readmessage);
267 }
268
269 function ClearAttachments() {
270 global $username, $attachments, $attachment_dir;
271
272 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
273
274 $rem_attachments = array();
275 foreach ($attachments as $info) {
276 if ($info['session'] == -1) {
277 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
278 if (file_exists($attached_file)) {
279 unlink($attached_file);
280 }
281 } else {
282 $rem_attachments[] = $info;
283 }
284 }
285 $attachments = $rem_attachments;
286 }
287
288 function formatRecipientString($recipients, $item ) {
289 global $base_uri, $passed_id, $urlMailbox, $startMessage, $show_more_cc,
290 $echo_more, $echo_less, $show_more, $show_more_bcc, $sort;
291
292 $i = 0;
293 $url_string = '';
294
295 if (isset ($recipients[0]) && trim($recipients[0])) {
296 $string = '';
297 $ary = $recipients;
298
299 switch ($item) {
300 case 'to':
301 $show = "&amp;show_more=1&amp;show_more_cc=$show_more_cc&amp;".
302 "show_more_bcc=$show_more_bcc";
303 $show_n = "&amp;show_more=0&amp;show_more_cc=$show_more_cc&amp;".
304 "show_more_bcc=$show_more_bcc";
305 break;
306 case 'cc':
307 $show = "&amp;show_more=$show_more&amp;show_more_cc=1&amp;".
308 "show_more_bcc=$show_more_bcc";
309 $show_n = "&amp;show_more=$show_more&amp;show_more_cc=0&amp;".
310 "show_more_bcc=$show_more_bcc";
311 $show_more = $show_more_cc;
312 break;
313 case 'bcc':
314 $show = "&amp;show_more=$show_more&amp;show_more_cc=$show_more_cc".
315 "&amp;show_more_bcc=1";
316 $show_n = "&amp;show_more=$show_more&amp;show_more_cc=".
317 "$show_more_cc&amp;show_more_bcc=0";
318 $show_more = $show_more_bcc;
319 break;
320 default:
321 $break;
322 }
323
324 while ($i < count($ary)) {
325 $ary[$i] = decodeHeader(htmlspecialchars($ary[$i]));
326 $url_string .= $ary[$i];
327 if ($string) {
328 $string = "$string<BR>$ary[$i]";
329 } else {
330 $string = "$ary[$i]";
331 }
332
333 $i++;
334 if (count($ary) > 1) {
335 if ($show_more == false) {
336 if ($i == 1) {
337 /* From a search... */
338 $string .= '&nbsp;(<a href="' . $base_uri .
339 "src/read_body.php?mailbox=$urlMailbox&amp;".
340 "passed_id=$passed_id&amp;";
341 if (isset($where) && isset($what)) {
342 $string .= 'what=' . urlencode($what).
343 "&amp;where=".urlencode($where).
344 "$show\">$echo_more</a>)";
345 } else {
346 $string .= "sort=$sort&amp;startMessage=".
347 "$startMessage"."$show\">$echo_more</a>)";
348 }
349 $i = count($ary);
350 }
351 } else if ($i == 1) {
352 /* From a search... */
353 $string .= '&nbsp;(<a href="' . $base_uri .
354 "src/read_body.php?mailbox=$urlMailbox&amp;".
355 "passed_id=$passed_id&amp;";
356 if (isset($where) && isset($what)) {
357 $string .= 'what=' . urlencode($what).
358 "&amp;where=".urlencode($where).
359 "$show_n\">$echo_less</a>)";
360 } else {
361 $string .= "sort=$sort&amp;startMessage=$startMessage".
362 "$show_n\">$echo_less</a>)";
363 }
364 }
365 }
366 }
367 }
368 else {
369 $string = '';
370 }
371 $url_string = urlencode($url_string);
372 $result = array();
373 $result['str'] = $string;
374 $result['url_str'] = $url_string;
375 return $result;
376 }
377
378
379
380 /*
381 * Main of read_boby.php --------------------------------------------------
382 */
383
384 /*
385 Urled vars
386 ----------
387 $passed_id
388 */
389
390 if (isset($mailbox)){
391 $mailbox = urldecode( $mailbox );
392 }
393 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
394 $imapPort, 0);
395 $read = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
396
397 do_hook('html_top');
398
399 /*
400 * The following code sets necesarry stuff for the MDN thing
401 */
402 if($default_use_mdn &&
403 ($mdn_user_support = getPref($data_dir, $username, 'mdn_user_support',
404 $default_use_mdn))) {
405
406 $supportMDN = ServerMDNSupport($read["PERMANENTFLAGS"]);
407 $flags = sqimap_get_flags ($imapConnection, $passed_id);
408 $FirstTimeSee = !(in_array( 'Seen', $flags ));
409 }
410
411 displayPageHeader($color, $mailbox);
412
413
414 /*
415 * The following code shows the header of the message and then exit
416 */
417 if (isset($view_hdr)) {
418 $read=sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]",
419 true, $a, $b);
420
421 echo '<br>' .
422 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" .
423 html_tag( 'tr' ) .
424 html_tag( 'td', '', 'center', $color[9], 'width="100%"' ) .
425 '<b>' . _("Viewing Full Header") . '</b> - '.
426 '<a href="' . $base_uri . 'src/read_body.php?mailbox='.
427 urlencode($mailbox);
428 if (isset($where) && isset($what)) {
429 // Got here from a search
430 echo "&amp;passed_id=$passed_id&amp;where=".urlencode($where).
431 "&amp;what=".urlencode($what).'">';
432 } else {
433 echo "&amp;passed_id=$passed_id&amp;startMessage=$startMessage".
434 "&amp;show_more=$show_more\">";
435 }
436 echo _("View message") . "</a></b></td></tr></table>\n".
437 html_tag( 'table', '', 'center', '', 'width="99%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" .
438 html_tag( 'tr' ) .
439 html_tag( 'td' ) .
440
441 $cnum = 0;
442 for ($i=1; $i < count($read); $i++) {
443 $line = htmlspecialchars($read[$i]);
444 if (eregi("^&gt;", $line)) {
445 $second[$i] = $line;
446 $first[$i] = '&nbsp;';
447 $cnum++;
448 } else if (eregi("^[ |\t]", $line)) {
449 $second[$i] = $line;
450 $first[$i] = '';
451 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
452 $first[$i] = $regs[1] . ':';
453 $second[$i] = $regs[2];
454 $cnum++;
455 } else {
456 $second[$i] = trim($line);
457 $first[$i] = '';
458 }
459 }
460 for ($i=0; $i < count($second); $i = $j) {
461 if (isset($first[$i])) {
462 $f = $first[$i];
463 }
464 if (isset($second[$i])) {
465 $s = nl2br($second[$i]);
466 }
467 $j = $i + 1;
468 while (($first[$j] == '') && ($j < count($first))) {
469 $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
470 $j++;
471 }
472 if(strtolower($f) != 'message-id:') {
473 parseEmail($s); /* Find and linkify emailaddresses except msgid */
474 }
475 if (isset($f)) {
476 echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
477 }
478 }
479 echo "</td></tr></table>\n" .
480 '</body></html>';
481 sqimap_logout($imapConnection);
482 exit;
483 }
484
485 if (isset($msgs)) {
486 $currentArrayIndex = $passed_id;
487 } else {
488 $currentArrayIndex = -1;
489 }
490
491 for ($i = 0; $i < count($msgs); $i++) {
492 if ($msgs[$i]['ID'] == $passed_id) {
493 $msgs[$i]['FLAG_SEEN'] = true;
494 }
495 }
496
497 /**
498 * $message contains all information about the message
499 * including header and body
500 */
501 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
502
503 /** translate the subject and mailbox into url-able text **/
504 $url_subj = urlencode(trim($message->header->subject));
505 $urlMailbox = urlencode($mailbox);
506 $url_replyto = '';
507 if (isset($message->header->replyto)) {
508 $url_replyto = urlencode($message->header->replyto);
509 }
510
511 $url_replytoall = $url_replyto;
512
513 /**
514 * If we are replying to all, then find all other addresses and
515 * add them to the list. Remove duplicates.
516 * This is somewhat messy, so I'll explain:
517 * 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
518 */
519 $url_replytoall_extra_addrs = array_merge(
520 array($message->header->from),
521 $message->header->to,
522 $message->header->cc
523 );
524
525 /**
526 * 2) Make one big string out of them
527 */
528 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
529
530 /**
531 * 3) Parse that into an array of addresses
532 */
533 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
534
535 /**
536 * 4) Make them unique -- weed out duplicates
537 * (Coded for PHP 4.0.0)
538 */
539 $url_replytoall_extra_addrs =
540 array_keys(array_flip($url_replytoall_extra_addrs));
541
542 /**
543 * 5) Remove the addresses we'll be sending the message 'to'
544 */
545 $url_replytoall_avoid_addrs = '';
546 if (isset($message->header->replyto)) {
547 $url_replytoall_avoid_addrs = $message->header->replyto;
548 }
549
550 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
551 foreach ($url_replytoall_avoid_addrs as $addr) {
552 RemoveAddress($url_replytoall_extra_addrs, $addr);
553 }
554
555 /**
556 * 6) Remove our identities from the CC list (they still can be in the
557 * TO list) only if $include_self_reply_all is turned off
558 */
559 if (!$include_self_reply_all) {
560 RemoveAddress($url_replytoall_extra_addrs,
561 getPref($data_dir, $username, 'email_address'));
562 $idents = getPref($data_dir, $username, 'identities');
563 if ($idents != '' && $idents > 1) {
564 for ($i = 1; $i < $idents; $i ++) {
565 $cur_email_address = getPref($data_dir, $username,
566 'email_address' . $i);
567 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
568 }
569 }
570 }
571
572 /**
573 * 7) Smoosh back into one nice line
574 */
575 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
576
577 /**
578 * 8) urlencode() it
579 */
580 $url_replytoallcc = urlencode($url_replytoallcc);
581
582 $dateString = getLongDateString($message->header->date);
583
584 /** TEXT STRINGS DEFINITIONS **/
585 $echo_more = _("more");
586 $echo_less = _("less");
587
588 if (!isset($show_more_cc)) {
589 $show_more_cc = FALSE;
590 }
591
592 if (!isset($show_more_bcc)) {
593 $show_more_bcc = FALSE;
594 }
595
596 /** FORMAT THE TO STRING **/
597 $to = formatRecipientString($message->header->to, "to");
598 $to_string = $to['str'];
599 $url_to_string = $to['url_str'];
600
601
602 /** FORMAT THE CC STRING **/
603
604 $cc = formatRecipientString($message->header->cc, "cc");
605 $cc_string = $cc['str'];
606 $url_cc_string = $cc['url_str'];
607
608 /** FORMAT THE BCC STRING **/
609
610 $bcc = formatRecipientString($message->header->bcc, "bcc");
611 $bcc_string = $bcc['str'];
612 $url_bcc_string = $bcc['url_str'];
613
614 if ($default_use_priority) {
615 $priority_level = substr($message->header->priority,0,1);
616
617 switch($priority_level) {
618 /* check for a higher then normal priority. */
619 case '1':
620 case '2':
621 $priority_string = _("High");
622 break;
623
624 /* check for a lower then normal priority. */
625 case '4':
626 case '5':
627 $priority_string = _("Low");
628 break;
629
630 /* check for a normal priority. */
631 case '3':
632 default:
633 $priority_level = '3';
634 $priority_string = _("Normal");
635 break;
636
637 }
638 }
639
640 /** make sure everything will display in HTML format **/
641 $from_name = decodeHeader(htmlspecialchars($message->header->from));
642 $subject = decodeHeader(htmlspecialchars($message->header->subject));
643 $identity = '';
644 $idents = getPref($data_dir, $username, 'identities');
645 if (!empty($idents) && $idents > 1) {
646 for ($i = 1; $i < $idents; $i++) {
647 $enc_from_name = '"'.
648 encodeHeader(getPref($data_dir,
649 $username,
650 'full_name' . $i)) .
651 '" <' . getPref($data_dir, $username,
652 'email_address' . $i) . '>';
653 if (htmlspecialchars($enc_from_name) == $from_name) {
654 $identity = $i;
655 break;
656 }
657 }
658 }
659
660 do_hook('read_body_top');
661 /**
662 * What do we reply to -- text only, if possible
663 */
664
665 $body = '';
666
667 /* experimental */
668 /*
669 if ($message->header->type0 == 'multipart' && $message->header->type1 == 'digest') {
670 listEntities($message);
671 for ($i = 0; $i < count($message->entities); $i++) {
672
673 $msg = $message->entities[$i];
674 $body .= $msg->header->type0 .'/'.$msg->header->type1 .'<BR>';
675
676 $msg->header->type0 = 'message';
677 $msg->header->type1 = 'rfc822';
678 $ent_ar = findDisplayEntity($msg, false);
679 for ($i = 0; $i < count($ent_ar); $i++) {
680 $body .= formatBody($imapConnection, $msg, $color, $wrap_at, $ent_ar[$i]);
681 }
682 $i++;
683 }
684 } else {
685 */
686 $ent_ar = findDisplayEntity($message, false);
687 $i = 0;
688 for ($i = 0; $i < count($ent_ar); $i++) {
689 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i]);
690 }
691 /*
692 }
693 */
694
695 /* first step in displaying multiple entities */
696 $ent_ar = findDisplayEntity($message,true);
697
698 $ent_num = $ent_ar[0];
699 for ($i = 1 ; $i < count($ent_ar); $i++) {
700 $ent_num .= '_'.$ent_ar[$i];
701 }
702 echo '<br>' .
703 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="0" cellspacing="0" border="0"' ) . "\n" .
704 html_tag( 'tr' ) .
705 html_tag( 'td', '', 'left', $color[9], 'width="100%"' ) .
706 html_tag( 'table', '', '', '', 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
707 html_tag( 'tr' ) .
708 html_tag( 'td', '', '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 html_tag( 'td', '', 'center', '', 'width="33%"' ) .
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>' .
789 html_tag( 'td', '', 'right', '', 'width="33%"' ) .
790 '<small>' ;
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 html_tag( 'tr' ) .
841 html_tag( 'td', '', 'left', '', 'width="100%"' ) .
842 html_tag( 'table', '', '', '', 'width="100%" border="0" cellspacing="0" cellpadding="3"' ) .
843 html_tag( 'tr' ) . "\n";
844
845 /** subject **/
846 echo html_tag( 'td', _("Subject:"), 'right', $color[0], 'width="10%" valign="top"' ) .
847 html_tag( 'td', '<b>' . $subject . '</b>&nbsp;' . "\n", 'left', $color[0], 'width="80%" valign="top"' ) .
848 html_tag( 'td', '', 'right', $color[0], 'rowspan="4" width="10%" valign="top" nowrap' ) .
849 '<a href="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
850
851 /* From a search... */
852 if ($where && $what) {
853 echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) .
854 "&amp;view_hdr=1\">" . _("View Full Header") . "</a>\n";
855 } else {
856 echo "startMessage=$startMessage&amp;show_more=$show_more&amp;view_hdr=1\">" .
857 _("View Full Header") . "</a>\n";
858 }
859
860 /* Output the printer friendly link if we are in subtle mode. */
861 if ($pf_subtle_link) {
862 echo printer_friendly_link(true);
863 }
864
865 do_hook("read_body_header_right");
866 echo '</small></td>' .
867 ' </tr>';
868
869 /** from **/
870 echo html_tag( 'tr', "\n" .
871 html_tag( 'td', _("From:"), 'right', $color[0], 'valign="top"' ) .
872 html_tag( 'td',
873 '<b>' . $from_name . '</b>&nbsp;' . "\n" ,
874 'left', $color[0] )
875 ) . "\n";
876 do_hook("read_body_after_from");
877 /** date **/
878 echo html_tag( 'tr', "\n" .
879 html_tag( 'td', _("Date:"), 'right', $color[0], 'valign="top"' ) .
880 html_tag( 'td',
881 '<b>' . $dateString . '</b>&nbsp;' . "\n" ,
882 'left', $color[0] )
883 ) . "\n";
884 /** to **/
885 echo html_tag( 'tr', "\n" .
886 html_tag( 'td', _("To:"), 'right', $color[0], 'valign="top"' ) .
887 html_tag( 'td',
888 '<b>' . $to_string . '</b>&nbsp;' . "\n" ,
889 'left', $color[0] )
890 ) . "\n";
891 /** cc **/
892 if (isset($cc_string) && $cc_string <> '') {
893 echo html_tag( 'tr', "\n" .
894 html_tag( 'td', _("Cc:"), 'right', $color[0], 'valign="top"' ) .
895 html_tag( 'td',
896 '<b>' . $cc_string . '</b>&nbsp;' . "\n" ,
897 'left', $color[0], 'colspan="2" valign="top"' )
898 ) . "\n";
899 }
900
901 /** bcc **/
902 if (isset($bcc_string) && $bcc_string <> '') {
903 echo html_tag( 'tr', "\n" .
904 html_tag( 'td', _("Bcc:"), 'right', $color[0], 'valign="top"' ) .
905 html_tag( 'td',
906 '<b>' . $bcc_string . '</b>&nbsp;' . "\n" ,
907 'left', $color[0], 'colspan="2" valign="top"' )
908 ) . "\n";
909 }
910 if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) {
911 echo html_tag( 'tr', "\n" .
912 html_tag( 'td', _("Priority") . ':', 'right', $color[0], 'valign="top"' ) .
913 html_tag( 'td',
914 '<b>' . $priority_string . '</b>&nbsp;' . "\n" ,
915 'left', $color[0], 'colspan="2" valign="top"' )
916 ) . "\n";
917 }
918
919 if ($show_xmailer_default) {
920 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]", true,
921 $response, $readmessage);
922 $mailer = substr($read[1], strpos($read[1], " "));
923 if (trim($mailer)) {
924 echo html_tag( 'tr', "\n" .
925 html_tag( 'td', _("Mailer") . ':', 'right', $color[0], 'valign="top"' ) .
926 html_tag( 'td',
927 '<b>' . $mailer . '</b>&nbsp;' ,
928 'left', $color[0], 'colspan="2" valign="top"' )
929 ) . "\n";
930 }
931 }
932
933 /* Output the printer friendly link if we are not in subtle mode. */
934 if (!$pf_subtle_link) {
935 echo printer_friendly_link(true);
936 }
937
938 if ($default_use_mdn) {
939 if ($mdn_user_support) {
940
941 // debug gives you the capability to remove mdn-flags
942 // $MDNDebug = false;
943 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true,
944 $response, $readmessage);
945 $MDN_to = substr($read[1], strpos($read[1], ' '));
946 $MDN_flag_present = false;
947
948 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true,
949 $response, $readmessage);
950 $MDN_flag_present = preg_match( '/.*\$MDNSent/i', $read[0]);
951
952 if (trim($MDN_to) &&
953 (!isset( $sendreceipt ) || $sendreceipt == '' ) ) {
954
955 if ( $MDN_flag_present && $supportMDN) {
956 $sendreceipt = 'removeMDN';
957 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
958 $sendreceipt='';
959 /*
960 if ($MDNDebug ) {
961 echo html_tag( 'tr', "\n" .
962 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
963 html_tag( 'td',
964 '<b>' . _("send") . '</b>&nbsp;<a href="' . $url . '">[' . _("Remove MDN flag") . '] </a>&nbsp;' ,
965 'left', $color[9], 'colspan="2" valign="top"' )
966 ) . "\n";
967 } else {
968 */
969 echo html_tag( 'tr', "\n" .
970 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
971 html_tag( 'td',
972 '<b>' . _("send") . '</b>&nbsp;' ,
973 'left', $color[9], 'colspan="2" valign="top"' )
974 ) . "\n";
975 /*
976 }
977 */
978
979 } // when deleted or draft flag is set don't offer to send a MDN response
980 else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) {
981 echo html_tag( 'tr', "\n" .
982 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
983 html_tag( 'td',
984 '<b>' . _("requested") . '</b>&nbsp;' ,
985 'left', $color[9], 'colspan="2" valign="top"' )
986 ) . "\n";
987 }
988 // if no MDNsupport don't use the annoying popup messages
989 else if ( !$FirstTimeSee ) {
990 $sendreceipt = 'send';
991 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
992 echo html_tag( 'tr', "\n" .
993 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
994 html_tag( 'td',
995 '<b>' . _("requested") . '</b> &nbsp; <a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
996 'left', $color[9], 'colspan="2" valign="top"' )
997 ) . "\n";
998 $sendreceipt='';
999 }
1000 else {
1001 $sendreceipt = 'send';
1002 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
1003 if ($javascript_on) {
1004 echo "<script language=\"javascript\" type=\"text/javascript\"> \n" .
1005 '<!-- ' . "\n" .
1006 " if (window.confirm(\"" .
1007 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
1008 "\")) { \n" .
1009 ' window.open('.$url.',"right");' . "\n" .
1010 ' }' . "\n" .
1011 '// -->' . "\n" .
1012 '</script>' . "\n";
1013 }
1014 echo html_tag( 'tr', "\n" .
1015 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
1016 html_tag( 'td',
1017 '<b>' . _("requested") . '</b>&nbsp&nbsp<a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
1018 'left', $color[9], 'colspan="2" valign="top"' )
1019 ) . "\n";
1020 $sendreceipt = '';
1021 }
1022 }
1023
1024 if ( !isset( $sendreceipt ) || $sendreceipt == '' ) {
1025 } else if ( $sendreceipt == 'send' ) {
1026 if ( !$MDN_flag_present) {
1027 if (isset($identity) ) {
1028 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
1029 } else {
1030 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
1031 }
1032
1033 $final_recipient = trim($final_recipient);
1034 if ($final_recipient == '' ) {
1035 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
1036 }
1037
1038 if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN ) {
1039 ToggleMDNflag( true);
1040 }
1041 ClearAttachments();
1042 }
1043 $sendreceipt = 'removeMDN';
1044 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
1045 $sendreceipt='';
1046 /*
1047 if ($MDNDebug && $supportMDN) {
1048 echo html_tag( 'tr', "\n" .
1049 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
1050 html_tag( 'td',
1051 '<b>' . _("send") . '</b>&nbsp&nbsp<a href="' . $url . '">[' . _("Remove MDN flag") . ']</a>',
1052 'left', $color[9], 'colspan="2" valign="top"' )
1053 ) . "\n";
1054 } else {
1055 */
1056 echo html_tag( 'tr', "\n" .
1057 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
1058 html_tag( 'td',
1059 '<b>' . _("send") . '</b>&nbsp',
1060 'left', $color[9], 'colspan="2" valign="top"' )
1061 ) . "\n";
1062 /*
1063 }
1064 */
1065 }
1066 elseif ($sendreceipt == 'removeMDN' ) {
1067 ToggleMDNflag ( false );
1068
1069 $sendreceipt = 'send';
1070 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
1071 echo html_tag( 'tr', "\n" .
1072 html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
1073 html_tag( 'td',
1074 '<b>' . _("requested") . '</b> &nbsp; <a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
1075 'left', $color[9], 'colspan="2" valign="top"' )
1076 ) . "\n";
1077 $sendreceipt = '';
1078
1079 }
1080 }
1081 }
1082
1083 do_hook('read_body_header');
1084
1085 echo '</table>' .
1086 ' </td></tr>' .
1087 '</table>';
1088 flush();
1089 echo html_tag( 'table', "\n" .
1090 html_tag( 'tr', "\n" .
1091 html_tag( 'td', '<br>' . "\n" . $body . "\n", 'left', $color[4]
1092 )
1093 ) ,
1094 'center', '', 'cellspacing=0 width="97%" border="0" cellpadding="0"') .
1095
1096 html_tag( 'table', "\n" .
1097 html_tag( 'tr', "\n" .
1098 html_tag( 'td', '&nbsp;', 'left', $color[9]
1099 )
1100 ) ,
1101 'center', '', 'cellspacing=0 width="100%" border="0" cellpadding="0"');
1102
1103 /* show attached images inline -- if pref'fed so */
1104 if (($attachment_common_show_images) &&
1105 is_array($attachment_common_show_images_list)) {
1106
1107 foreach ($attachment_common_show_images_list as $img) {
1108 $imgurl = '../src/download.php' .
1109 '?' .
1110 'passed_id=' . urlencode($img['passed_id']) .
1111 '&amp;mailbox=' . urlencode($mailbox) .
1112 '&amp;passed_ent_id=' . urlencode($img['ent_id']) .
1113 '&amp;absolute_dl=true';
1114
1115 echo html_tag( 'table', "\n" .
1116 html_tag( 'tr', "\n" .
1117 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
1118 )
1119 ) ,
1120 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
1121 }
1122 }
1123
1124
1125 do_hook('read_body_bottom');
1126 do_hook('html_bottom');
1127 sqimap_logout($imapConnection);
1128 ?>
1129 </body>
1130 </html>