2d6dc5553f05088dc3a78710fb1c8b8d91775bca
[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 parseEmail($s);
474 if (isset($f)) {
475 echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
476 }
477 }
478 echo "</td></tr></table>\n" .
479 '</body></html>';
480 sqimap_logout($imapConnection);
481 exit;
482 }
483
484 if (isset($msgs)) {
485 $currentArrayIndex = $passed_id;
486 } else {
487 $currentArrayIndex = -1;
488 }
489
490 for ($i = 0; $i < count($msgs); $i++) {
491 if ($msgs[$i]['ID'] == $passed_id) {
492 $msgs[$i]['FLAG_SEEN'] = true;
493 }
494 }
495
496 /**
497 * $message contains all information about the message
498 * including header and body
499 */
500 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
501
502 /** translate the subject and mailbox into url-able text **/
503 $url_subj = urlencode(trim($message->header->subject));
504 $urlMailbox = urlencode($mailbox);
505 $url_replyto = '';
506 if (isset($message->header->replyto)) {
507 $url_replyto = urlencode($message->header->replyto);
508 }
509
510 $url_replytoall = $url_replyto;
511
512 /**
513 * If we are replying to all, then find all other addresses and
514 * add them to the list. Remove duplicates.
515 * This is somewhat messy, so I'll explain:
516 * 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
517 */
518 $url_replytoall_extra_addrs = array_merge(
519 array($message->header->from),
520 $message->header->to,
521 $message->header->cc
522 );
523
524 /**
525 * 2) Make one big string out of them
526 */
527 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
528
529 /**
530 * 3) Parse that into an array of addresses
531 */
532 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
533
534 /**
535 * 4) Make them unique -- weed out duplicates
536 * (Coded for PHP 4.0.0)
537 */
538 $url_replytoall_extra_addrs =
539 array_keys(array_flip($url_replytoall_extra_addrs));
540
541 /**
542 * 5) Remove the addresses we'll be sending the message 'to'
543 */
544 $url_replytoall_avoid_addrs = '';
545 if (isset($message->header->replyto)) {
546 $url_replytoall_avoid_addrs = $message->header->replyto;
547 }
548
549 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
550 foreach ($url_replytoall_avoid_addrs as $addr) {
551 RemoveAddress($url_replytoall_extra_addrs, $addr);
552 }
553
554 /**
555 * 6) Remove our identities from the CC list (they still can be in the
556 * TO list) only if $include_self_reply_all is turned off
557 */
558 if (!$include_self_reply_all) {
559 RemoveAddress($url_replytoall_extra_addrs,
560 getPref($data_dir, $username, 'email_address'));
561 $idents = getPref($data_dir, $username, 'identities');
562 if ($idents != '' && $idents > 1) {
563 for ($i = 1; $i < $idents; $i ++) {
564 $cur_email_address = getPref($data_dir, $username,
565 'email_address' . $i);
566 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
567 }
568 }
569 }
570
571 /**
572 * 7) Smoosh back into one nice line
573 */
574 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
575
576 /**
577 * 8) urlencode() it
578 */
579 $url_replytoallcc = urlencode($url_replytoallcc);
580
581 $dateString = getLongDateString($message->header->date);
582
583 /**
584 * What do we reply to -- text only, if possible
585 */
586 $ent_ar = findDisplayEntity($message);
587 /* first step in displaying multiple entities */
588 $ent_num = $ent_ar[0];
589
590 /** TEXT STRINGS DEFINITIONS **/
591 $echo_more = _("more");
592 $echo_less = _("less");
593
594 if (!isset($show_more_cc)) {
595 $show_more_cc = FALSE;
596 }
597
598 if (!isset($show_more_bcc)) {
599 $show_more_bcc = FALSE;
600 }
601
602 /** FORMAT THE TO STRING **/
603 $to = formatRecipientString($message->header->to, "to");
604 $to_string = $to['str'];
605 $url_to_string = $to['url_str'];
606
607
608 /** FORMAT THE CC STRING **/
609
610 $cc = formatRecipientString($message->header->cc, "cc");
611 $cc_string = $cc['str'];
612 $url_cc_string = $cc['url_str'];
613
614 /** FORMAT THE BCC STRING **/
615
616 $bcc = formatRecipientString($message->header->bcc, "bcc");
617 $bcc_string = $bcc['str'];
618 $url_bcc_string = $bcc['url_str'];
619
620 if ($default_use_priority) {
621 $priority_level = substr($message->header->priority,0,1);
622
623 switch($priority_level) {
624 /* check for a higher then normal priority. */
625 case '1':
626 case '2':
627 $priority_string = _("High");
628 break;
629
630 /* check for a lower then normal priority. */
631 case '4':
632 case '5':
633 $priority_string = _("Low");
634 break;
635
636 /* check for a normal priority. */
637 case '3':
638 default:
639 $priority_level = '3';
640 $priority_string = _("Normal");
641 break;
642
643 }
644 }
645
646 /** make sure everything will display in HTML format **/
647 $from_name = decodeHeader(htmlspecialchars($message->header->from));
648 $subject = decodeHeader(htmlspecialchars($message->header->subject));
649 $identity = '';
650 $idents = getPref($data_dir, $username, 'identities');
651 if (!empty($idents) && $idents > 1) {
652 for ($i = 1; $i < $idents; $i++) {
653 $enc_from_name = '"'.
654 encodeHeader(getPref($data_dir,
655 $username,
656 'full_name' . $i)) .
657 '" <' . getPref($data_dir, $username,
658 'email_address' . $i) . '>';
659 if (htmlspecialchars($enc_from_name) == $from_name) {
660 $identity = $i;
661 break;
662 }
663 }
664 }
665
666 do_hook('read_body_top');
667 echo '<BR>' .
668 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' .
669 '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' .
670 '<TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' .
671 '<TR>' .
672 '<TD ALIGN="LEFT" WIDTH="33%">' .
673 '<SMALL>' .
674 '<A HREF="' . $base_uri . 'src/';
675
676 if ($where && $what) {
677 if ($pos == '') {
678 $pos=0;
679 }
680 echo "search.php?where=".urlencode($where)."&amp;pos=$pos&amp;what=".urlencode($what)."&amp;mailbox=$urlMailbox\">";
681 } else {
682 echo "right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox\">";
683 }
684 echo _("Message List") .
685 '</A>&nbsp;|&nbsp;' .
686 '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&amp;message=$passed_id&amp;";
687 if ($where && $what) {
688 echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) . '">';
689 } else {
690 echo "sort=$sort&amp;startMessage=$startMessage\">";
691 }
692 echo _("Delete") . '</A>&nbsp;';
693 if (($mailbox == $draft_folder) && ($save_as_draft)) {
694 $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
695 "identity=$identity&amp;send_to=$url_to_string&amp;".
696 "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
697 "subject=$url_subj&amp;mailprio=$priority_level&amp;".
698 "draft_id=$passed_id&amp;ent_num=$ent_num";
699
700 if ($compose_new_win == '1') {
701 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
702 } else {
703 echo '|&nbsp;<A HREF="' . $comp_uri .'"';
704 }
705 echo '>'.
706 _("Resume Draft") . '</a>';
707 }
708 if ($mailbox == $sent_folder) {
709 $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
710 "identity=$identity&amp;send_to=$url_to_string&amp;".
711 "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
712 "subject=$url_subj&amp;mailprio=$priority_level&amp;".
713 "ent_num=$ent_num&amp;passed_id=$passed_id&amp;edit_as_new=1";
714
715 if ($compose_new_win == '1') {
716 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
717 } else {
718 echo '|&nbsp;<A HREF="' . $comp_uri .'"';
719 }
720 echo '>'.
721 _("Edit Message as New") . '</a>';
722 }
723
724 echo '&nbsp;&nbsp;' .
725 '</SMALL>' .
726 '</TD>' .
727 '<TD WIDTH="33%" ALIGN="CENTER">' .
728 '<SMALL>';
729
730 if ( !($where && $what) ) {
731 if ($currentArrayIndex == -1) {
732 echo 'Previous&nbsp;|&nbsp;Next';
733 } else {
734 $prev = findPreviousMessage();
735 $next = findNextMessage();
736
737 if ($prev != -1) {
738 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;";
739 } else {
740 echo _("Previous") . '&nbsp;|&nbsp;';
741 }
742
743 if ($next != -1) {
744 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>";
745 } else {
746 echo _("Next");
747 }
748 }
749 }
750
751 echo '</SMALL>' .
752 '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
753 '<SMALL>' ;
754
755 $comp_uri = $base_uri . "src/compose.php?forward_id=$passed_id&amp;".
756 "forward_subj=$url_subj&amp;".
757 ($default_use_priority?"mailprio=$priority_level&amp;":'').
758 "mailbox=$urlMailbox&amp;ent_num=$ent_num";
759
760 if ($compose_new_win == '1') {
761 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
762 } else {
763 echo '|&nbsp;<A HREF="' . $comp_uri .'"';
764 }
765
766 echo '>'.
767 _("Forward") .
768 '</A>&nbsp;|&nbsp;';
769
770 $comp_uri = $base_uri . "src/compose.php?send_to=$url_replyto&amp;".
771 "reply_subj=$url_subj&amp;".
772 ($default_use_priority?"mailprio=$priority_level&amp;":'').
773 "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
774
775 if ($compose_new_win == '1') {
776 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
777 } else {
778 echo '|&nbsp;<A HREF="' . $comp_uri .'"';
779 }
780
781 echo '>'.
782 _("Reply") .
783 '</A>&nbsp;|&nbsp;';
784
785 $comp_uri = $base_uri . "src/compose.php?send_to=$url_replytoall&amp;".
786 "send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
787 ($default_use_priority?"mailprio=$priority_level&amp;":'').
788 "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
789
790 if ($compose_new_win == '1') {
791 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
792 } else {
793 echo '|&nbsp;<A HREF="' . $comp_uri .'"';
794 }
795
796 echo '>'.
797 _("Reply All") .
798 '</A>&nbsp;&nbsp;' .
799 '</SMALL>' .
800 '</TD>' .
801 '</TR>' .
802 '</TABLE>' .
803 '</TD></TR>' .
804 '<TR><TD WIDTH="100%">' .
805 '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
806 '<TR>' . "\n";
807
808 /** subject **/
809 echo "<TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
810 _("Subject:") .
811 "</TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
812 "<B>$subject</B>&nbsp;\n" .
813 "</TD>\n" .
814 '<TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] .
815 '" ALIGN=right VALIGN=top NOWRAP><small>'.
816 '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
817
818 /* From a search... */
819 if ($where && $what) {
820 echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) .
821 "&amp;view_hdr=1\">" . _("View Full Header") . "</A>\n";
822 } else {
823 echo "startMessage=$startMessage&amp;show_more=$show_more&amp;view_hdr=1\">" .
824 _("View Full Header") . "</A>\n";
825 }
826
827 /* Output the printer friendly link if we are in subtle mode. */
828 if ($pf_subtle_link) {
829 echo printer_friendly_link(true);
830 }
831
832 do_hook("read_body_header_right");
833 echo '</small></TD>' .
834 ' </TR>';
835
836 /** from **/
837 echo '<TR>' .
838 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' .
839 _("From:") .
840 '</TD><TD BGCOLOR="' . $color[0] . '">' .
841 "<B>$from_name</B>&nbsp;\n" .
842 '</TD>' .
843 '</TR>';
844 /** date **/
845 echo '<TR>' . "\n" .
846 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
847 _("Date:") .
848 "</TD><TD BGCOLOR=\"$color[0]\">\n" .
849 "<B>$dateString</B>&nbsp;\n" .
850 '</TD>' . "\n" .
851 '</TR>' . "\n";
852
853 /** to **/
854 echo "<TR>\n" .
855 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
856 _("To:") .
857 '</TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
858 "<B>$to_string</B>&nbsp;\n" .
859 '</TD>' . "\n" .
860 '</TR>' . "\n";
861 /** cc **/
862 if (isset($cc_string) && $cc_string <> '') {
863 echo '<TR>' .
864 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
865 'Cc:' .
866 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
867 "<B>$cc_string</B>&nbsp;" .
868 '</TD>' .
869 '</TR>' . "\n";
870 }
871
872 /** bcc **/
873 if (isset($bcc_string) && $bcc_string <> '') {
874 echo '<TR>'.
875 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
876 'Bcc:' .
877 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
878 "<B>$bcc_string</B>&nbsp;" .
879 '</TD>' .
880 '</TR>' . "\n";
881 }
882 if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) {
883 echo '<TR>' .
884 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
885 _("Priority") . ': '.
886 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
887 "<B>$priority_string</B>&nbsp;" .
888 '</TD>' .
889 "</TR>" . "\n";
890 }
891
892 if ($show_xmailer_default) {
893 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]", true,
894 $response, $readmessage);
895 $mailer = substr($read[1], strpos($read[1], " "));
896 if (trim($mailer)) {
897 echo '<TR>' .
898 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
899 _("Mailer") . ': '.
900 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
901 "<B>$mailer</B>&nbsp;" .
902 '</TD>' .
903 "</TR>" . "\n";
904 }
905 }
906
907 /* Output the printer friendly link if we are not in subtle mode. */
908 if (!$pf_subtle_link) {
909 echo printer_friendly_link(true);
910 }
911
912 if ($default_use_mdn) {
913 if ($mdn_user_support) {
914
915 // debug gives you the capability to remove mdn-flags
916 // $MDNDebug = false;
917 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true,
918 $response, $readmessage);
919 $MDN_to = substr($read[1], strpos($read[1], ' '));
920 $MDN_flag_present = false;
921
922 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true,
923 $response, $readmessage);
924 $MDN_flag_present = preg_match( '/.*\$MDNSent/i', $read[0]);
925
926 if (trim($MDN_to) &&
927 (!isset( $sendreceipt ) || $sendreceipt == '' ) ) {
928
929 if ( $MDN_flag_present && $supportMDN) {
930 $sendreceipt = 'removeMDN';
931 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
932 $sendreceipt='';
933 /*
934 if ($MDNDebug ) {
935 echo '<TR>' .
936 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
937 _("Read receipt") . ': ' .
938 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
939 '<B>' .
940 _("send") .
941 "</B> <a href=$url>[" . _("Remove MDN flag") . '] </a>' .
942 '</TD>' .
943 '</TR>' . "\n";
944 } else {
945 */
946 echo '<TR>' .
947 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
948 _("Read receipt") . ': ' .
949 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
950 '<B>'._("send").'</B>'.
951 '</TD>' .
952 '</TR>' . "\n";
953 /*
954 }
955 */
956
957 } // when deleted or draft flag is set don't offer to send a MDN response
958 else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) {
959 echo '<TR>' .
960 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
961 _("Read receipt") . ': '.
962 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
963 '<B>' . _("requested") . "</B>" .
964 '</TD>' .
965 '</TR>' . "\n";
966 }
967 // if no MDNsupport don't use the annoying popup messages
968 else if ( !$FirstTimeSee ) {
969 $sendreceipt = 'send';
970 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
971 echo '<TR>' .
972 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
973 _("Read receipt") . ': ' .
974 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
975 '<B>' . _("requested") .
976 "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
977 '</TD>' .
978 '</TR>' . "\n";
979 $sendreceipt='';
980 }
981 else {
982 $sendreceipt = 'send';
983 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
984 if ($javascript_on) {
985 echo "<script language=\"javascript\" type=\"text/javascript\"> \n" .
986 '<!-- ' . "\n" .
987 " if (window.confirm(\"" .
988 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
989 "\")) { \n" .
990 ' window.open('.$url.',"right");' . "\n" .
991 ' }' . "\n" .
992 '// -->' . "\n" .
993 '</script>' . "\n";
994 }
995 echo '<TR>' .
996 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
997 _("Read receipt") . ': ' .
998 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
999 '<B>' . _("requested") . "&nbsp&nbsp</B><a href=$url>" . '[' .
1000 _("Send read receipt now") . '] </a>' ." \n" .
1001 '</TD>' .
1002 '</TR>' . "\n";
1003 $sendreceipt = '';
1004 }
1005 }
1006
1007 if ( !isset( $sendreceipt ) || $sendreceipt == '' ) {
1008 } else if ( $sendreceipt == 'send' ) {
1009 if ( !$MDN_flag_present) {
1010 if (isset($identity) ) {
1011 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
1012 } else {
1013 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
1014 }
1015
1016 $final_recipient = trim($final_recipient);
1017 if ($final_recipient == '' ) {
1018 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
1019 }
1020
1021 if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN ) {
1022 ToggleMDNflag( true);
1023 }
1024 ClearAttachments();
1025 }
1026 $sendreceipt = 'removeMDN';
1027 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
1028 $sendreceipt='';
1029 /*
1030 if ($MDNDebug && $supportMDN) {
1031 echo " <TR>\n" .
1032 " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" .
1033 " "._("Read receipt").": \n".
1034 " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
1035 ' <B>'._("send").'</B>'." <a href=$url>" . '[' . _("Remove MDN flag") . '] </a>' . "\n" .
1036 ' </TD>' . "\n" .
1037 ' </TR>' . "\n";
1038 } else {
1039 */
1040 echo " <TR>\n" .
1041 " <TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>\n" .
1042 " "._("Read receipt").": \n".
1043 " </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
1044 ' <B>'._("send").'</B>'. "\n" .
1045 ' </TD>' . "\n" .
1046 ' </TR>' . "\n";
1047 /*
1048 }
1049 */
1050 }
1051 elseif ($sendreceipt == 'removeMDN' ) {
1052 ToggleMDNflag ( false );
1053
1054 $sendreceipt = 'send';
1055 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
1056 echo '<TR>'.
1057 "<TD BGCOLOR=\"$color[9]\" ALIGN=RIGHT VALIGN=TOP>" .
1058 _("Read receipt") . ': ' .
1059 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
1060 '<B>' . _("requested") .
1061 "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
1062 '</TD>' .
1063 '</TR>' . "\n";
1064 $sendreceipt = '';
1065
1066 }
1067 }
1068 }
1069
1070 do_hook('read_body_header');
1071
1072 echo '</TABLE>' .
1073 ' </TD></TR>' .
1074 '</TABLE>';
1075 flush();
1076 echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
1077 " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" .
1078 '<BR>'.
1079 formatBody($imapConnection, $message, $color, $wrap_at, $ent_num).
1080 '</TD></TR></TABLE>' .
1081 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
1082 " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>" .
1083 '</TABLE>' . "\n";
1084
1085 /* show attached images inline -- if pref'fed so */
1086 if (($attachment_common_show_images) &&
1087 is_array($attachment_common_show_images_list)) {
1088
1089 foreach ($attachment_common_show_images_list as $img) {
1090 $imgurl = '../src/download.php' .
1091 '?' .
1092 'passed_id=' . urlencode($img['passed_id']) .
1093 '&amp;mailbox=' . urlencode($mailbox) .
1094 '&amp;passed_ent_id=' . urlencode($img['ent_id']) .
1095 '&amp;absolute_dl=true';
1096
1097 echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
1098 '<TR>' .
1099 '<TD>' .
1100 "<img src=\"$imgurl\">\n" .
1101 "</TD>\n" .
1102 "</TR>\n" .
1103 "</TABLE>\n";
1104
1105 }
1106 }
1107
1108
1109 do_hook('read_body_bottom');
1110 do_hook('html_bottom');
1111 sqimap_logout($imapConnection);
1112 ?>
1113 </body>
1114 </html>