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