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