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