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