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