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