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