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