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