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