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