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