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