Marc variant for the messages flags.
[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 /* 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 if ( $set ) {
211 sqimap_messages_flag ($imapConnection,$passed_id,$passed_id,"\$MDNSent");
212 } else {
213 sqimap_messages_remove_flag ($imapConnection,$passed_id,$passed_id,"\$MDNSent");
214 }
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 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
244 $read = sqimap_mailbox_select($imapConnection, $mailbox, false, true);
245
246 do_hook('html_top');
247
248 /*
249 * The following code sets necesarry stuff for the MDN thing
250 */
251 if( $default_use_mdn &&
252 ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) {
253
254 $supportMDN = ServerMDNSupport($read["PERMANENTFLAGS"]);
255 $flags = sqimap_get_flags ($imapConnection, $passed_id);
256 $FirstTimeSee = !(in_array( '\\Seen', $flags ));
257 }
258
259 displayPageHeader($color, $mailbox);
260
261
262 /*
263 * The following code shows the header of the message and then exit
264 */
265 if (isset($view_hdr)) {
266 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", true, $a, $b);
267
268 echo '<BR>' .
269 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
270 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\"><CENTER><B>" . _("Viewing Full Header") . '</B> - '.
271 '<a href="' . $base_uri . "src/read_body.php?mailbox=".urlencode($mailbox);
272 if (isset($where) && isset($what)) {
273 // Got here from a search
274 echo "&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
275 } else {
276 echo "&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
277 }
278 echo _("View message") . "</a></b></center></td></tr></table>\n" .
279 "<table width=\"99%\" cellpadding=2 cellspacing=0 border=0 align=center>\n" .
280 '<tr><td>';
281
282 $cnum = 0;
283 for ($i=1; $i < count($read); $i++) {
284 $line = htmlspecialchars($read[$i]);
285 if (eregi("^&gt;", $line)) {
286 $second[$i] = $line;
287 $first[$i] = '&nbsp;';
288 $cnum++;
289 } else if (eregi("^[ |\t]", $line)) {
290 $second[$i] = $line;
291 $first[$i] = '';
292 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
293 $first[$i] = $regs[1] . ':';
294 $second[$i] = $regs[2];
295 $cnum++;
296 } else {
297 $second[$i] = trim($line);
298 $first[$i] = '';
299 }
300 }
301 for ($i=0; $i < count($second); $i = $j) {
302 if (isset($first[$i])) {
303 $f = $first[$i];
304 }
305 if (isset($second[$i])) {
306 $s = nl2br($second[$i]);
307 }
308 $j = $i + 1;
309 while (($first[$j] == '') && ($j < count($first))) {
310 $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
311 $j++;
312 }
313 parseEmail($s);
314 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
315 }
316 echo "</td></tr></table>\n" .
317 '</body></html>';
318 sqimap_logout($imapConnection);
319 exit;
320 }
321
322 if (isset($msgs)) {
323 $currentArrayIndex = $passed_id;
324 } else {
325 $currentArrayIndex = -1;
326 }
327
328 for ($i = 0; $i < count($msgs); $i++) {
329 if ($msgs[$i]['ID'] == $passed_id) {
330 $msgs[$i]['FLAG_SEEN'] = true;
331 }
332 }
333
334 // $message contains all information about the message
335 // including header and body
336 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
337
338 /** translate the subject and mailbox into url-able text **/
339 $url_subj = urlencode(trim($message->header->subject));
340 $urlMailbox = urlencode($mailbox);
341 $url_replyto = '';
342 if (isset($message->header->replyto)) {
343 $url_replyto = urlencode($message->header->replyto);
344 }
345
346 $url_replytoall = $url_replyto;
347
348 // If we are replying to all, then find all other addresses and
349 // add them to the list. Remove duplicates.
350 // This is somewhat messy, so I'll explain:
351 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
352 $url_replytoall_extra_addrs = array_merge(
353 array($message->header->from),
354 $message->header->to,
355 $message->header->cc
356 );
357
358 // 2) Make one big string out of them
359 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
360
361 // 3) Parse that into an array of addresses
362 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
363
364 // 4) Make them unique -- weed out duplicates
365 // (Coded for PHP 4.0.0)
366 $url_replytoall_extra_addrs =
367 array_keys(array_flip($url_replytoall_extra_addrs));
368
369 // 5) Remove the addresses we'll be sending the message 'to'
370 $url_replytoall_avoid_addrs = '';
371 if (isset($message->header->replyto)) {
372 $url_replytoall_avoid_addrs = $message->header->replyto;
373 }
374
375 $url_replytoall_avoid_addrs = parseAddrs($url_replytoall_avoid_addrs);
376 foreach ($url_replytoall_avoid_addrs as $addr) {
377 RemoveAddress($url_replytoall_extra_addrs, $addr);
378 }
379
380 // 6) Remove our identities from the CC list (they still can be in the
381 // TO list) only if $include_self_reply_all is turned off
382 if (!$include_self_reply_all) {
383 RemoveAddress($url_replytoall_extra_addrs,
384 getPref($data_dir, $username, 'email_address'));
385 $idents = getPref($data_dir, $username, 'identities');
386 if ($idents != '' && $idents > 1) {
387 for ($i = 1; $i < $idents; $i ++) {
388 $cur_email_address = getPref($data_dir, $username, 'email_address' . $i);
389 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
390 }
391 }
392 }
393
394 // 7) Smoosh back into one nice line
395 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
396
397 // 8) urlencode() it
398 $url_replytoallcc = urlencode($url_replytoallcc);
399
400 $dateString = getLongDateString($message->header->date);
401
402 // What do we reply to -- text only, if possible
403 $ent_num = findDisplayEntity($message);
404
405 /** TEXT STRINGS DEFINITIONS **/
406 $echo_more = _("more");
407 $echo_less = _("less");
408
409 if (!isset($show_more_cc)) {
410 $show_more_cc = FALSE;
411 }
412
413 /** FORMAT THE TO STRING **/
414 $i = 0;
415 $to_string = '';
416 $to_ary = $message->header->to;
417 while ($i < count($to_ary)) {
418 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
419
420 if ($to_string) {
421 $to_string = "$to_string<BR>$to_ary[$i]";
422 } else {
423 $to_string = "$to_ary[$i]";
424 }
425
426 $i++;
427 if (count($to_ary) > 1) {
428 if ($show_more == false) {
429 if ($i == 1) {
430 /* From a search... */
431 $to_string .= '&nbsp;(<A HREF="' . $base_uri .
432 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
433 if (isset($where) && isset($what)) {
434 $to_string .= 'where='.urlencode($where)."&what=".urlencode($what)."&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
435 } else {
436 $to_string .= "sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
437 }
438 $i = count($to_ary);
439 }
440 } else if ($i == 1) {
441 /* From a search... */
442 $to_string .= '&nbsp;(<A HREF="' . $base_uri .
443 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
444 if (isset($where) && isset($what)) {
445 $to_string .= 'where='.urlencode($where)."&what=".urlencode($what)."&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
446 } else {
447 $to_string .= "sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
448 }
449 }
450 }
451 }
452
453 /** FORMAT THE CC STRING **/
454 $i = 0;
455 if (isset ($message->header->cc[0]) && trim($message->header->cc[0])) {
456 $cc_string = "";
457 $cc_ary = $message->header->cc;
458 while ($i < count(decodeHeader($cc_ary))) {
459 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
460 if ($cc_string) {
461 $cc_string = "$cc_string<BR>$cc_ary[$i]";
462 } else {
463 $cc_string = "$cc_ary[$i]";
464 }
465
466 $i++;
467 if (count($cc_ary) > 1) {
468 if ($show_more_cc == false) {
469 if ($i == 1) {
470 /* From a search... */
471 $cc_string .= '&nbsp;(<A HREF="' . $base_uri .
472 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id";
473 if (isset($where) && isset($what)) {
474 $cc_string .= '&what='.urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
475 } else {
476 $cc_string .= "&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
477 }
478 $i = count($cc_ary);
479 }
480 } else if ($i == 1) {
481 /* From a search... */
482 $cc_string .= '&nbsp;(<A HREF="' . $base_uri .
483 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
484 if (isset($where) && isset($what)) {
485 $cc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
486 } else {
487 $cc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
488 }
489 }
490 }
491 }
492 }
493 else {
494 $cc_string = '';
495 }
496
497 /** FORMAT THE BCC STRING **/
498 $i = 0;
499 if (isset ($message->header->bcc[0]) && trim($message->header->bcc[0])){
500 $bcc_string = "";
501 $bcc_ary = $message->header->bcc;
502 while ($i < count(decodeHeader($bcc_ary))) {
503 $bcc_ary[$i] = htmlspecialchars($bcc_ary[$i]);
504 if ($bcc_string) {
505 $bcc_string = "$bcc_string<BR>$bcc_ary[$i]";
506 } else {
507 $bcc_string = "$bcc_ary[$i]";
508 }
509
510 $i++;
511 if (count($bcc_ary) > 1) {
512 if ($show_more_cc == false) {
513 if ($i == 1) {
514 /* From a search... */
515 $bcc_string .= '&nbsp;(<A HREF="' . $base_uri .
516 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
517 if (isset($where) && isset($what)) {
518 $bcc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
519 } else {
520 $bcc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
521 }
522 $i = count($bcc_ary);
523 }
524 } else if ($i == 1) {
525 /* From a search... */
526 $bcc_string .= '&nbsp;(<A HREF="' . $base_uri .
527 "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
528 if (isset($where) && isset($what)) {
529 $bcc_string .= 'what=' . urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
530 } else {
531 $bcc_string .= "sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
532 }
533 }
534 }
535 }
536 }
537 else {
538 $bcc_string = '';
539 }
540
541 if ($default_use_priority) {
542 $priority_level = substr($message->header->priority,0,1);
543
544 switch($priority_level) {
545 /* check for a higher then normal priority. */
546 case '1':
547 case '2':
548 $priority_string = _("High");
549 break;
550
551 /* check for a lower then normal priority. */
552 case '4':
553 case '5':
554 $priority_string = _("Low");
555 break;
556
557 /* check for a normal priority. */
558 case '3':
559 default:
560 $priority_level = '3';
561 $priority_string = _("Normal");
562 break;
563
564 }
565 }
566
567 /** make sure everything will display in HTML format **/
568 $from_name = decodeHeader(htmlspecialchars($message->header->from));
569 $subject = decodeHeader(htmlspecialchars($message->header->subject));
570
571 do_hook('read_body_top');
572 echo '<BR>' .
573 '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' .
574 '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' .
575 '<TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' .
576 '<TR>' .
577 '<TD ALIGN="LEFT" WIDTH="33%">' .
578 '<SMALL>' .
579 '<A HREF="' . $base_uri . 'src/';
580
581 if ($where && $what) {
582 if( $pos == '' ) {
583 $pos = 0;
584 }
585 echo "search.php?where$pos=".urlencode($where)."&pos=$pos&what$pos=".urlencode($what)."&mailbox=$urlMailbox\">";
586 } else {
587 echo "right_main.php?sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
588 }
589 echo _("Message List") .
590 '</A>&nbsp;|&nbsp;' .
591 '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&message=$passed_id&";
592 if ($where && $what) {
593 echo 'where=' . urlencode($where) . '&what=' . urlencode($what) . '">';
594 } else {
595 echo "sort=$sort&startMessage=$startMessage\">";
596 }
597 echo _("Delete") . '</A>&nbsp;';
598 if (($mailbox == $draft_folder) && ($save_as_draft)) {
599 echo '|&nbsp;<A HREF="' . $base_uri .
600 "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\"";
601 if ($compose_new_win == '1') {
602 echo 'TARGET="compose_window" onClick="comp_in_new()"';
603 }
604 echo '>'.
605 _("Resume Draft") . '</a>';
606 }
607
608 echo '&nbsp;&nbsp;' .
609 '</SMALL>' .
610 '</TD>' .
611 '<TD WIDTH="33%" ALIGN="CENTER">' .
612 '<SMALL>';
613
614 if ( !($where && $what) ) {
615
616 if ($currentArrayIndex == -1) {
617 echo 'Previous&nbsp;|&nbsp;Next';
618 } else {
619 $prev = findPreviousMessage();
620 $next = findNextMessage();
621
622 if ($prev != -1) {
623 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;";
624 } else {
625 echo _("Previous") . '&nbsp;|&nbsp;';
626 }
627
628 if ($next != -1) {
629 echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
630 } else {
631 echo _("Next");
632 }
633 }
634 }
635
636 echo '</SMALL>' .
637 '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
638 '<SMALL>' .
639 '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&forward_subj=$url_subj&".
640 ($default_use_priority?"mailprio=$priority_level&":"")
641 ."mailbox=$urlMailbox&ent_num=$ent_num\"";
642 if ($compose_new_win == '1') {
643 echo 'TARGET="compose_window" onClick="comp_in_new()"';
644 }
645 echo '>'.
646 _("Forward") .
647 '</A>&nbsp;|&nbsp;' .
648 '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&reply_subj=$url_subj&".
649 ($default_use_priority?"mailprio=$priority_level&":"").
650 "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\"";
651 if ($compose_new_win == '1') {
652 echo 'TARGET="compose_window" onClick="comp_in_new()"';
653 }
654 echo '>'.
655 _("Reply") .
656 '</A>&nbsp;|&nbsp;' .
657 '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&".
658 ($default_use_priority?"mailprio=$priority_level&":"").
659 "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\"";
660 if ($compose_new_win == '1') {
661 echo 'TARGET="compose_window" onClick="comp_in_new()"';
662 }
663 echo '>'.
664 _("Reply All") .
665 '</A>&nbsp;&nbsp;' .
666 '</SMALL>' .
667 '</TD>' .
668 '</TR>' .
669 '</TABLE>' .
670 '</TD></TR>' .
671 '<TR><TD CELLSPACING="0" WIDTH="100%">' .
672 '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
673 '<TR>' . "\n";
674
675 /** subject **/
676 echo "<TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
677 _("Subject:") .
678 "</TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
679 "<B>$subject</B>&nbsp;\n" .
680 "</TD>\n" .
681 '<TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] .
682 '" ALIGN=right VALIGN=top NOWRAP><small>'.
683 '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&";
684
685 /* From a search... */
686 if ($where && $what) {
687 echo 'where=' . urlencode($where) . '&what=' . urlencode($what) .
688 "&view_hdr=1\">" . _("View Full Header") . "</A>\n";
689 } else {
690 echo "startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" .
691 _("View Full Header") . "</A>\n";
692 }
693
694 /* Output the printer friendly link if we are in subtle mode. */
695 if ($pf_subtle_link) {
696 echo printer_friendly_link(true);
697 }
698
699 do_hook("read_body_header_right");
700 echo '</small></TD>' .
701 ' </TR>';
702
703 /** from **/
704 echo '<TR>' .
705 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' .
706 _("From:") .
707 '</TD><TD BGCOLOR="' . $color[0] . '">' .
708 "<B>$from_name</B>&nbsp;\n" .
709 '</TD>' .
710 '</TR>';
711 /** date **/
712 echo '<TR>' . "\n" .
713 '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
714 _("Date:") .
715 "</TD><TD BGCOLOR=\"$color[0]\">\n" .
716 "<B>$dateString</B>&nbsp;\n" .
717 '</TD>' . "\n" .
718 '</TR>' . "\n";
719
720 /** to **/
721 echo "<TR>\n" .
722 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
723 _("To:") .
724 '</TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
725 "<B>$to_string</B>&nbsp;\n" .
726 '</TD>' . "\n" .
727 '</TR>' . "\n";
728 /** cc **/
729 if (isset($cc_string) && $cc_string <> '') {
730 echo '<TR>' .
731 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
732 'Cc:' .
733 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
734 "<B>$cc_string</B>&nbsp;" .
735 '</TD>' .
736 '</TR>' . "\n";
737 }
738
739 /** bcc **/
740 if (isset($bcc_string) && $bcc_string <> '') {
741 echo '<TR>'.
742 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
743 'Bcc:' .
744 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
745 "<B>$bcc_string</B>&nbsp;" .
746 '</TD>' .
747 '</TR>' . "\n";
748 }
749 if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) {
750 echo '<TR>' .
751 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
752 _("Priority") . ': '.
753 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
754 "<B>$priority_string</B>&nbsp;" .
755 '</TD>' .
756 "</TR>" . "\n";
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>