HTML escaping.
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
35586184 2/**
3 * read_body.php
4 *
82d304a0 5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
10 *
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
a07cd1a4 13 */
35586184 14
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
86725763 19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
8650e9e1 23require_once(SM_PATH . 'functions/global.php');
86725763 24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'functions/mime.php');
26require_once(SM_PATH . 'functions/date.php');
27require_once(SM_PATH . 'functions/url_parser.php');
28require_once(SM_PATH . 'functions/html.php');
e95c04ec 29require_once(SM_PATH . 'functions/global.php');
6d021521 30require_once(SM_PATH . 'functions/identity.php');
d6b6d221 31require_once(SM_PATH . 'functions/mailbox_display.php');
38c944cc 32
a07cd1a4 33/**
1fca12b5 34 * Given an IMAP message id number, this will look it up in the cached
1e150c97 35 * and sorted msgs array and return the index of the next message
1fca12b5 36 *
1e150c97 37 * @param int $passed_id The current message UID
1fca12b5 38 * @return the index of the next valid message from the array
39 */
c615b1da 40function findNextMessage($passed_id) {
41 global $msort, $msgs, $sort,
cf710efe 42 $thread_sort_messages, $allow_server_sort,
60a3e687 43 $server_sort_array;
2728fa19 44 if (!is_array($server_sort_array)) {
45 $thread_sort_messages = 0;
794d59c0 46 $allow_server_sort = FALSE;
2728fa19 47 }
a07cd1a4 48 $result = -1;
c615b1da 49 if ($thread_sort_messages || $allow_server_sort) {
d9c1dccc 50 $count = count($server_sort_array) - 1;
51 foreach($server_sort_array as $key=>$value) {
c615b1da 52 if ($passed_id == $value) {
d9c1dccc 53 if ($key == $count) {
60a3e687 54 break;
55 }
1fca12b5 56 $result = $server_sort_array[$key + 1];
60a3e687 57 break;
789b4d79 58 }
60a3e687 59 }
d9c1dccc 60 } else {
7e818af0 61 if (is_array($msort)) {
62 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
63 if ($passed_id == $msgs[$key]['ID']) {
64 next($msort);
65 $key = key($msort);
66 if (isset($key)){
67 $result = $msgs[$key]['ID'];
68 break;
d9c1dccc 69 }
1fca12b5 70 }
10f0ce72 71 }
72 }
10f0ce72 73 }
d9c1dccc 74 return $result;
a07cd1a4 75}
76
1e150c97 77/**
78 * Given an IMAP message id number, this will look it up in the cached
79 * and sorted msgs array and return the index of the previous message
80 *
81 * @param int $passed_id The current message UID
82 * @return the index of the next valid message from the array
83 */
c615b1da 84function findPreviousMessage($numMessages, $passed_id) {
85 global $msort, $sort, $msgs,
86 $thread_sort_messages,
60a3e687 87 $allow_server_sort, $server_sort_array;
a07cd1a4 88 $result = -1;
2728fa19 89 if (!is_array($server_sort_array)) {
90 $thread_sort_messages = 0;
794d59c0 91 $allow_server_sort = FALSE;
2728fa19 92 }
c615b1da 93 if ($thread_sort_messages || $allow_server_sort ) {
d9c1dccc 94 foreach($server_sort_array as $key=>$value) {
c615b1da 95 if ($passed_id == $value) {
8f11a776 96 if ($key != 0) {
97 $result = $server_sort_array[$key - 1];
60a3e687 98 }
60a3e687 99 break;
789b4d79 100 }
60a3e687 101 }
d9c1dccc 102 } else {
7e818af0 103 if (is_array($msort)) {
104 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
105 if ($passed_id == $msgs[$key]['ID']) {
106 prev($msort);
107 $key = key($msort);
108 if (isset($key)) {
109 $result = $msgs[$key]['ID'];
110 break;
d9c1dccc 111 }
10f0ce72 112 }
113 }
10f0ce72 114 }
a07cd1a4 115 }
d9c1dccc 116 return $result;
a07cd1a4 117}
10f0ce72 118
a07cd1a4 119/**
1fca12b5 120 * Displays a link to a page where the message is displayed more
121 * "printer friendly".
1e150c97 122 * @param string $mailbox Name of current mailbox
123 * @param int $passed_id
1fca12b5 124 */
1e150c97 125function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
126 global $javascript_on, $color;
a07cd1a4 127
164584f0 128 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
c2324b26 129 '&mailbox=' . urlencode($mailbox) .
164584f0 130 '&passed_id=' . urlencode($passed_id);
10f0ce72 131
a07cd1a4 132 $print_text = _("View Printable Version");
10f0ce72 133
c615b1da 134 $result = '';
a07cd1a4 135 /* Output the link. */
136 if ($javascript_on) {
9f42bfc8 137 $result = '<script language="javascript" type="text/javascript">' . "\n" .
138 '<!--' . "\n" .
139 " function printFormat() {\n" .
140 ' window.open("../src/printer_friendly_main.php' .
141 $params . '","Print","width=800,height=600");' . "\n".
142 " }\n" .
143 "// -->\n" .
144 "</script>\n" .
145 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
a07cd1a4 146 } else {
c2324b26 147 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
9f42bfc8 148 "$params\">$print_text</a>\n";
a07cd1a4 149 }
d9c1dccc 150 return $result;
a07cd1a4 151}
152
d9c1dccc 153function ServerMDNSupport($read) {
f69feefe 154 /* escaping $ doesn't work -> \x36 */
781b93d4 155 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
d9c1dccc 156 return $ret;
57257333 157}
158
fc224f68 159function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
e95c04ec 160 global $username, $attachment_dir,
fc224f68 161 $version, $attachments, $squirrelmail_language, $default_charset,
d9c1dccc 162 $languages, $useSendmail, $domain, $sent_folder,
163 $popuser, $data_dir, $username;
57257333 164
e95c04ec 165 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
0b97a708 166
38bca81c 167 $header = $message->rfc822_header;
57257333 168 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169
fc224f68 170 $rfc822_header = new Rfc822Header();
d9c1dccc 171 $content_type = new ContentType('multipart/report');
fc224f68 172 $content_type->properties['report-type']='disposition-notification';
d9c1dccc 173
fc224f68 174 set_my_charset();
175 if ($default_charset) {
d9c1dccc 176 $content_type->properties['charset']=$default_charset;
fc224f68 177 }
178 $rfc822_header->content_type = $content_type;
179 $rfc822_header->to[] = $header->dnt;
a20855e4 180 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
fc224f68 181
27a1d10a 182 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
183 // This merely comes from compose.php and only happens when there is no
184 // email_addr specified in user's identity (which is the startup config)
185 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
186 $popuser = $usernamedata[1];
187 $domain = $usernamedata[2];
188 unset($usernamedata);
189 } else {
190 $popuser = $username;
191 }
fc224f68 192
193 $reply_to = '';
6d021521 194 $ident = get_identities();
195 if(!isset($identity)) $identity = 0;
196 $full_name = $ident[$identity]['full_name'];
197 $from_mail = $ident[$identity]['email_address'];
198 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
199 $reply_to = $ident[$identity]['reply_to'];
200
27a1d10a 201 if (!$from_mail) {
202 $from_mail = "$popuser@$domain";
203 $from_addr = $from_mail;
fc224f68 204 }
205 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
206 if ($reply_to) {
207 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
208 }
d9c1dccc 209
57257333 210 // part 1 (RFC2298)
57257333 211 $senton = getLongDateString( $header->date );
212 $to_array = $header->to;
213 $to = '';
214 foreach ($to_array as $line) {
af568a82 215 $to .= ' '.$line->getAddress();
57257333 216 }
57257333 217 $now = getLongDateString( time() );
78db1583 218 set_my_charset();
46bb8da8 219 $body = _("Your message") . "\r\n\r\n" .
d39b7293 220 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
221 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" .
46bb8da8 222 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
223 "\r\n" .
224 sprintf( _("Was displayed on %s"), $now );
f69feefe 225
fc224f68 226 $special_encoding = '';
227 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
228 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 229 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
d9c1dccc 230 if (strtolower($default_charset) == 'iso-2022-jp') {
231 if (mb_detect_encoding($body) == 'ASCII') {
232 $special_encoding = '8bit';
233 } else {
234 $body = mb_convert_encoding($body, 'JIS');
235 $special_encoding = '7bit';
236 }
237 }
6fbd125b 238 }
fc224f68 239 $part1 = new Message();
240 $part1->setBody($body);
241 $mime_header = new MessageHeader;
242 $mime_header->type0 = 'text';
243 $mime_header->type1 = 'plain';
244 if ($special_encoding) {
245 $mime_header->encoding = $special_encoding;
d9c1dccc 246 } else {
fc224f68 247 $mime_header->encoding = 'us-ascii';
248 }
249 if ($default_charset) {
250 $mime_header->parameters['charset'] = $default_charset;
251 }
252 $part1->mime_header = $mime_header;
253
57257333 254 // part2 (RFC2298)
d9c1dccc 255 $original_recipient = $to;
57257333 256 $original_message_id = $header->message_id;
257
fc224f68 258 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
57257333 259 if ($original_recipient != '') {
fc224f68 260 $report .= "Original-Recipient : $original_recipient\r\n";
57257333 261 }
262 $final_recipient = $sender;
fc224f68 263 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
57257333 264 "Original-Message-ID : $original_message_id\r\n" .
265 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
266
fc224f68 267 $part2 = new Message();
268 $part2->setBody($report);
269 $mime_header = new MessageHeader;
270 $mime_header->type0 = 'message';
271 $mime_header->type1 = 'disposition-notification';
272 $mime_header->encoding = 'us-ascii';
273 $part2->mime_header = $mime_header;
274
275 $composeMessage = new Message();
276 $composeMessage->rfc822_header = $rfc822_header;
277 $composeMessage->addEntity($part1);
278 $composeMessage->addEntity($part2);
279
280
d9c1dccc 281 if ($useSendmail) {
282 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
283 global $sendmail_path;
284 $deliver = new Deliver_SendMail();
285 $stream = $deliver->initStream($composeMessage,$sendmail_path);
fc224f68 286 } else {
d9c1dccc 287 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
288 $deliver = new Deliver_SMTP();
47a29326 289 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
d9c1dccc 290 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
9bd3b1e6 291 get_smtp_user($user, $pass);
d9c1dccc 292 $stream = $deliver->initStream($composeMessage,$domain,0,
70ce2218 293 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
d9c1dccc 294 }
295 $success = false;
fc224f68 296 if ($stream) {
d9c1dccc 297 $length = $deliver->mail($composeMessage, $stream);
298 $success = $deliver->finalizeStream($stream);
fc224f68 299 }
d9c1dccc 300 if (!$success) {
00ac2f42 301 $msg = $deliver->dlv_msg . '<br>' .
302 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
303 $deliver->dlv_server_msg;
d9c1dccc 304 require_once(SM_PATH . 'functions/display_messages.php');
fc224f68 305 plain_error_message($msg, $color);
306 } else {
307 unset ($deliver);
d9c1dccc 308 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
309 sqimap_append ($imapConnection, $sent_folder, $length);
310 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
311 $imap_deliver = new Deliver_IMAP();
312 $imap_deliver->mail($composeMessage, $imapConnection);
313 sqimap_append_done ($imapConnection);
314 unset ($imap_deliver);
315 }
316 }
317 return $success;
57257333 318}
319
6201339c 320function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
d9c1dccc 321 $sg = $set?'+':'-';
322 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 323 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
6201339c 324 $readmessage, TRUE);
57257333 325}
326
327function ClearAttachments() {
d9c1dccc 328 global $username, $attachments, $attachment_dir;
329
330 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
331
332 $rem_attachments = array();
6191bcb1 333 if (isset($attachments)) {
334 foreach ($attachments as $info) {
335 if ($info['session'] == -1) {
336 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
337 if (file_exists($attached_file)) {
338 unlink($attached_file);
339 }
340 } else {
341 $rem_attachments[] = $info;
342 }
343 }
d9c1dccc 344 }
345 $attachments = $rem_attachments;
57257333 346}
347
4d0cd98b 348function formatRecipientString($recipients, $item ) {
d9c1dccc 349 global $show_more_cc, $show_more, $show_more_bcc,
350 $PHP_SELF;
4d0cd98b 351
d9c1dccc 352 $string = '';
38c944cc 353 if ((is_array($recipients)) && (isset($recipients[0]))) {
d9c1dccc 354 $show = false;
38c944cc 355
356 if ($item == 'to') {
d9c1dccc 357 if ($show_more) {
358 $show = true;
359 $url = set_url_var($PHP_SELF, 'show_more',0);
360 } else {
361 $url = set_url_var($PHP_SELF, 'show_more',1);
362 }
363 } else if ($item == 'cc') {
364 if ($show_more_cc) {
365 $show = true;
366 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
367 } else {
368 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
369 }
370 } else if ($item == 'bcc') {
371 if ($show_more_bcc) {
372 $show = true;
373 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
374 } else {
375 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
376 }
377 }
378
379 $cnt = count($recipients);
380 foreach($recipients as $r) {
a91189d6 381 $add = decodeHeader($r->getAddress(true));
d9c1dccc 382 if ($string) {
383 $string .= '<BR>' . $add;
384 } else {
385 $string = $add;
386 if ($cnt > 1) {
38c944cc 387 $string .= '&nbsp;(<A HREF="'.$url;
d9c1dccc 388 if ($show) {
389 $string .= '">'._("less").'</A>)';
390 } else {
391 $string .= '">'._("more").'</A>)';
392 break;
393 }
394 }
395 }
1fca12b5 396 }
4d0cd98b 397 }
c615b1da 398 return $string;
399}
400
af568a82 401function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
402 $color, $FirstTimeSee) {
a94c1db1 403 global $msn_user_support, $default_use_mdn, $default_use_priority,
77836429 404 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
405 $squirrelmail_language;
38bca81c 406
d9c1dccc 407 $header = $message->rfc822_header;
408 $env = array();
bdb9ce72 409 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
7893c8a5 410
d9c1dccc 411 $from_name = $header->getAddr_s('from');
d6b6d221 412 if (!$from_name)
d9c1dccc 413 $from_name = $header->getAddr_s('sender');
d6b6d221 414 if (!$from_name)
415 $env[_("From")] = _("Unknown sender");
416 else
417 $env[_("From")] = decodeHeader($from_name);
d9c1dccc 418 $env[_("Date")] = getLongDateString($header->date);
419 $env[_("To")] = formatRecipientString($header->to, "to");
420 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
421 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
422 if ($default_use_priority) {
0e8006dc 423 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
d9c1dccc 424 }
425 if ($show_xmailer_default) {
a91189d6 426 $env[_("Mailer")] = decodeHeader($header->xmailer);
d9c1dccc 427 }
428 if ($default_use_mdn) {
429 if ($mdn_user_support) {
430 if ($header->dnt) {
431 if ($message->is_mdnsent) {
509ce88e 432 $env[_("Read receipt")] = _("sent");
d9c1dccc 433 } else {
434 $env[_("Read receipt")] = _("requested");
8e1d27aa 435 if (!(handleAsSent($mailbox) ||
d9c1dccc 436 $message->is_deleted ||
437 $passed_ent_id)) {
438 $mdn_url = $PHP_SELF . '&sendreceipt=1';
439 if ($FirstTimeSee && $javascript_on) {
440 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
441 $script .= '<!--'. "\n";
442 $script .= 'if(window.confirm("' .
443 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
444 '")) { '."\n" .
445 ' sendMDN()'.
446 '}' . "\n";
447 $script .= '// -->'. "\n";
448 $script .= '</script>'. "\n";
449 echo $script;
450 }
451 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
452 _("Send read receipt now") . ']</a>';
453 }
454 }
455 }
456 }
457 }
c615b1da 458
a94c1db1 459 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
0e02d604 460 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
d9c1dccc 461 foreach ($env as $key => $val) {
462 if ($val) {
463 $s .= '<TR>';
464 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
465 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
466 $s .= '</TR>';
467 }
468 }
a94c1db1 469 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
da9a8410 470 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
a94c1db1 471 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
472 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
d9c1dccc 473 echo $s;
00ac2f42 474 do_hook('read_body_header');
d9c1dccc 475 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
476 echo '</TABLE>';
a94c1db1 477 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
feb5ec1b 478 echo '</TABLE>';
d9c1dccc 479}
c615b1da 480
1e150c97 481/**
482 * Format message toolbar
483 *
484 * @param string $mailbox Name of current mailbox
485 * @param int $passed_id UID of current message
486 * @param int $passed_ent_id Id of entity within message
487 * @param object $message Current message object
488 * @param object $mbx_response
489 */
490function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
a94c1db1 491 global $base_uri, $draft_folder, $where, $what, $color, $sort,
6201339c 492 $startMessage, $PHP_SELF, $save_as_draft,
1e150c97 493 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
1a531551 494 $data_dir, $username, $delete_prev_next_display,
495 $compose_new_win, $javascript_on;
c615b1da 496
d9c1dccc 497 $topbar_delimiter = '&nbsp;|&nbsp;';
1e150c97 498 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
d9c1dccc 499 $urlMailbox = urlencode($mailbox);
c615b1da 500
1e150c97 501 $msgs_url = $base_uri . 'src/';
2ffa3f57 502
1e150c97 503 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
45c1ed84 504 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
e55c441a 505
1e150c97 506 // Create Prev & Next links
507 // Handle nested entities first (i.e. Mime Attach parts)
508 if (isset($passed_ent_id) && $passed_ent_id) {
509 // code for navigating through attached message/rfc822 messages
d9c1dccc 510 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
70bdc740 511 $entities = array();
512 $entity_count = array();
513 $c = 0;
f2f03410 514
70bdc740 515 foreach($message->parent->entities as $ent) {
9f42bfc8 516 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
517 $c++;
518 $entity_count[$c] = $ent->entity_id;
519 $entities[$ent->entity_id] = $c;
520 }
70bdc740 521 }
1e150c97 522
70bdc740 523 $prev_link = _("Previous");
70bdc740 524 if($entities[$passed_ent_id] > 1) {
525 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
526 $prev_link = '<a href="'
527 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
528 . '">' . $prev_link . '</a>';
529 }
1e150c97 530
531 $next_link = _("Next");
70bdc740 532 if($entities[$passed_ent_id] < $c) {
533 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
534 $next_link = '<a href="'
535 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
536 . '">' . $next_link . '</a>';
537 }
1e150c97 538
d9c1dccc 539 $par_ent_id = $message->parent->entity_id;
1e150c97 540 $up_link = '';
d9c1dccc 541 if ($par_ent_id) {
542 $par_ent_id = substr($par_ent_id,0,-2);
1e150c97 543 if ( $par_ent_id != 0 ) {
544 $up_link = $topbar_delimiter;
545 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
546 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
547 }
548 }
549
550 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
abafb676 551 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
1e150c97 552
553 // Prev/Next links for regular messages
554 } else if ( !(isset($where) && isset($what)) ) {
555 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
556 $next = findNextMessage($passed_id);
557
558 $prev_link = _("Previous");
559 if ($prev >= 0) {
560 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
561 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
562 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
563 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
d9c1dccc 564 }
1e150c97 565
566 $next_link = _("Next");
567 if ($next >= 0) {
568 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
569 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
570 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
571 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
572 }
573
1e150c97 574 // Only bother with Delete & Prev and Delete & Next IF
6201339c 575 // top display is enabled.
576 if ( $delete_prev_next_display == 1 ) {
45c1ed84 577 $del_prev_link = _("Delete & Prev");
1e150c97 578 if ($prev >= 0) {
579 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
580 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
581 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
582 '&amp;delete_id='.$passed_id;
45c1ed84 583 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
1e150c97 584 }
585
45c1ed84 586 $del_next_link = _("Delete & Next");
1e150c97 587 if ($next >= 0) {
588 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
589 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
590 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
591 '&amp;delete_id='.$passed_id;
45c1ed84 592 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
1e150c97 593 }
1e150c97 594 }
45c1ed84 595
abafb676 596 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
597 if ( isset($del_prev_link) && isset($del_next_link) )
598 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
1e150c97 599 }
600
601 // Start with Search Results or Message List link.
602 if (isset($where) && isset($what)) {
603 $msgs_url .= 'search.php?where=' . urlencode($where) .
604 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
605 $msgs_str = _("Search Results");
606 } else {
607 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
608 $startMessage . '&amp;mailbox=' . $urlMailbox;
609 $msgs_str = _("Message List");
610 }
611 $nav_row .= $double_delimiter .
abafb676 612 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
1e150c97 613
614 $nav_row .= '</small></td></tr>';
615
616
617 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
618 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
98a9cc03 619 $comp_uri = $base_uri.'src/compose.php' .
620 '?passed_id=' . $passed_id .
621 '&amp;mailbox=' . $urlMailbox .
622 '&amp;startMessage=' . $startMessage .
623 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
1a531551 624
625 // Start form for reply/reply all/forward..
626 $target = '';
627 $on_click='';
ee66175d 628 $method='method="post" ';
1a531551 629 if ($compose_new_win == '1') {
630 if ( $javascript_on ) {
631 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
632 $comp_uri = 'javascript:void(0)';
ee66175d 633 $method='method="get" ';
1a531551 634 } else {
635 $target = 'target="_blank"';
1a531551 636 }
637 }
638
d35df487 639 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
98a9cc03 640
1e150c97 641 // If Draft folder - create Resume link
642 if (($mailbox == $draft_folder) && ($save_as_draft)) {
1a531551 643 $new_button = 'smaction_draft';
1e150c97 644 $comp_alt_string = _("Resume Draft");
645 } else if (handleAsSent($mailbox)) {
646 // If in Sent folder, edit as new
1a531551 647 $new_button = 'smaction_edit_new';
1e150c97 648 $comp_alt_string = _("Edit Message as New");
649 }
1e150c97 650 // Show Alt URI for Draft/Sent
98a9cc03 651 if (isset($comp_alt_string))
1a531551 652 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
1e150c97 653
1a531551 654 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
655 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
656 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
98a9cc03 657 if ($enable_forward_as_attachment)
51eb014b 658 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .'&nbsp;&nbsp;'."\n";
1e150c97 659
51eb014b 660 $menu_row .= '</form>&nbsp;';
c615b1da 661
98a9cc03 662 // Form for deletion
663 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
d35df487 664 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
a128c967 665
abafb676 666 if (!(isset($passed_ent_id) && $passed_ent_id)) {
64c9e87e 667 $menu_row .= addHidden('message', $passed_id);
abafb676 668
669 if ($where && $what) {
64c9e87e 670 $menu_row .= addHidden('where', $where);
671 $menu_row .= addHidden('what', $what);
abafb676 672 } else {
64c9e87e 673 $menu_row .= addHidden('sort', $sort);
674 $menu_row .= addHidden('startMessage', $startMessage);
abafb676 675 }
98a9cc03 676 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
677 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
abafb676 678 }
98a9cc03 679 else
1a531551 680 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
98a9cc03 681
51eb014b 682 $menu_row .= '</form>';
abafb676 683
684
1e150c97 685 // Add top move link
686 $menu_row .= '</small></td><td align="right">';
b2811304 687 if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
b2811304 688
689 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
1c13663f 690
691 // Set subsequent location based on whether or not there is a 'next' message.
b2811304 692 if ( isset($next) && $next >= 0 ) {
c0312de3 693 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
694 } elseif (isset($prev) && $prev >= 0) {
695 $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
b2811304 696 } else {
c0312de3 697 $location = $base_uri . 'src/right_main.php?';
b2811304 698 }
b2811304 699
39de750f 700 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
64c9e87e 701 '<small>'.
702 addHidden('show_more', '0' ).
703 addHidden('dmn', '1').
704 addHidden('location', $location.$current_box).
705 addHidden('msg[0]', $passed_id) . _("Move to:") .
1e150c97 706 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
b2811304 707
1e150c97 708 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
709 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
710 } else {
711 $menu_row .= sqimap_mailbox_option_list($imapConnection);
712 }
b2811304 713 $menu_row .= '</select> ';
714
b2811304 715 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
1e150c97 716 }
717 $menu_row .= '</td></tr>';
d9c1dccc 718
1e150c97 719 // echo rows, with hooks
764971df 720 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
988e24f6 721 if (is_array($ret)) {
722 if (isset($ret[0]) && !empty($ret[0])) {
723 $nav_row = $ret[0];
724 }
725 if (isset($ret[1]) && !empty($ret[1])) {
726 $menu_row = $ret[1];
727 }
764971df 728 }
1e150c97 729 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
730 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
731 echo '</table>'."\n";
d62c4938 732 do_hook('read_body_menu_bottom');
c615b1da 733}
734
735function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
a94c1db1 736 global $base_uri;
fe369c70 737
d9c1dccc 738 $urlMailbox = urlencode($mailbox);
7b9fdca9 739 if (!sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER)) {
740 // FIX ME !. If this happens there is something else wrong. Falling
741 // back to '' won't help. We should raise an error instead.
831b5d60 742 $query_string = '';
743 }
e95c04ec 744 $url = $base_uri.'src/view_header.php?'.$query_string;
d9c1dccc 745
a94c1db1 746 $s = "<TR>\n" .
98fb28fd 747 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
748 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
d9c1dccc 749 '<a href="'.$url.'">'._("View Full Header").'</a>';
750
751 /* Output the printer friendly link if we are in subtle mode. */
752 $s .= '&nbsp;|&nbsp;' .
1e150c97 753 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
d9c1dccc 754 echo $s;
755 do_hook("read_body_header_right");
756 $s = "</SMALL></TD>\n" .
757 "</TR>\n";
758 echo $s;
a128c967 759
4d0cd98b 760}
761
6206f6c4 762/***************************/
2ffa3f57 763/* Main of read_body.php */
6206f6c4 764/***************************/
57257333 765
0b97a708 766/* get the globals we may need */
767
1e12d1ff 768sqgetGlobalVar('key', $key, SQ_COOKIE);
e95c04ec 769sqgetGlobalVar('username', $username, SQ_SESSION);
770sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
e95c04ec 771sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
1e12d1ff 772sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
773
e95c04ec 774sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
775sqgetGlobalVar('msort', $msort, SQ_SESSION);
776sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
777sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
778if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
779 $messages = array();
ce274df9 780}
781
e95c04ec 782/** GET VARS */
783sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
784sqgetGlobalVar('where', $where, SQ_GET);
785sqgetGlobalVar('what', $what, SQ_GET);
786if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
787 $show_more = (int) $temp;
1b9f3c04 788}
e95c04ec 789if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
790 $show_more_cc = (int) $temp;
0b97a708 791}
e95c04ec 792if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
793 $show_more_bcc = (int) $temp;
0b97a708 794}
e95c04ec 795if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
796 $view_hdr = (int) $temp;
0b97a708 797}
e95c04ec 798
e95c04ec 799/** GET/POST VARS */
800sqgetGlobalVar('passed_ent_id', $passed_ent_id);
801sqgetGlobalVar('mailbox', $mailbox);
802
803if ( sqgetGlobalVar('passed_id', $temp) ) {
804 $passed_id = (int) $temp;
0b97a708 805}
e95c04ec 806if ( sqgetGlobalVar('sort', $temp) ) {
807 $sort = (int) $temp;
0b97a708 808}
e95c04ec 809if ( sqgetGlobalVar('startMessage', $temp) ) {
810 $startMessage = (int) $temp;
ce274df9 811}
0b97a708 812
ce274df9 813/* end of get globals */
6201339c 814global $sqimap_capabilities, $lastTargetMailbox;
38c944cc 815
6206f6c4 816$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
9f42bfc8 817$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
38c944cc 818
1e150c97 819/**
820 * Process Delete from delete-move-next
821 * but only if delete_id was set
822 */
823if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
653ff1e6 824 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
1e150c97 825
653ff1e6 826 sqimap_mailbox_expunge_dmn($delete_id);
1e150c97 827}
828
829/**
38c944cc 830 * $message contains all information about the message
831 * including header and body
832 */
37d2a6ee 833
834$uidvalidity = $mbx_response['UIDVALIDITY'];
9f42bfc8 835
37d2a6ee 836if (!isset($messages[$uidvalidity])) {
837 $messages[$uidvalidity] = array();
9f42bfc8 838}
6201339c 839if (!isset($messages[$uidvalidity][$passed_id])) {
5200c026 840 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 841 $FirstTimeSee = !$message->is_seen;
842 $message->is_seen = true;
5200c026 843 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 844} else {
fc224f68 845// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
846 $message = $messages[$uidvalidity][$passed_id];
847 $FirstTimeSee = !$message->is_seen;
5200c026 848}
af568a82 849
dd628162 850if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 851 $message = $message->getEntity($passed_ent_id);
ff9d4297 852 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
853 $message = $message->parent;
854 }
6201339c 855 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
19d470aa 856 $rfc822_header = new Rfc822Header();
141a16b2 857 $rfc822_header->parseHeader($read);
858 $message->rfc822_header = $rfc822_header;
c615b1da 859} else {
860 $passed_ent_id = 0;
38c944cc 861}
5200c026 862$header = $message->header;
57257333 863
6c31f818 864do_hook('html_top');
57257333 865
6206f6c4 866/****************************************/
867/* Block for handling incoming url vars */
868/****************************************/
5200c026 869
5200c026 870if (isset($sendreceipt)) {
871 if ( !$message->is_mdnsent ) {
27a1d10a 872 $final_recipient = '';
873 if ((isset($identity)) && ($identity != 0)) //Main identity
874 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
875 if ($final_recipient == '' )
876 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
af568a82 877 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 878 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
6201339c 879 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
5200c026 880 $message->is_mdnsent = true;
6a108031 881 $messages[$uidvalidity][$passed_id]=$message;
5200c026 882 }
883 ClearAttachments();
884 }
885}
6206f6c4 886/***********************************************/
887/* End of block for handling incoming url vars */
888/***********************************************/
889
38c944cc 890$msgs[$passed_id]['FLAG_SEEN'] = true;
9f42bfc8 891
892$messagebody = '';
c4ad259b 893do_hook('read_body_top');
894if ($show_html_default == 1) {
895 $ent_ar = $message->findDisplayEntity(array());
896} else {
897 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
898}
a128c967 899$cnt = count($ent_ar);
900for ($i = 0; $i < $cnt; $i++) {
6a108031 901 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 902 if ($i != $cnt-1) {
903 $messagebody .= '<hr noshade size=1>';
904 }
38c944cc 905}
e55c441a 906
c615b1da 907displayPageHeader($color, $mailbox);
7172cad7 908formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 909formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
a94c1db1 910echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
6206f6c4 911echo ' <tr><td>';
a94c1db1 912echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 913echo ' <tr><td>';
a94c1db1 914echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
6206f6c4 915echo ' <tr bgcolor="'.$color[4].'"><td>';
98fb28fd 916// echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
917echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
ce810ea7 918echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
6c7b5d8c 919 . '</tr>';
6206f6c4 920echo ' </table>';
921echo ' </td></tr>';
922echo ' </table></td></tr>';
2ffa3f57 923echo ' </table>';
924echo ' </td></tr>';
a128c967 925
d0a2476a 926echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
6c7b5d8c 927 $color[4].'"></TD></TR>'."\n";
d0a2476a 928
a128c967 929$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
930if ($attachmentsdisplay) {
8acd2fb5 931 echo ' </table>';
6206f6c4 932 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 933 echo ' <tr><td>';
d0a2476a 934 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
98fb28fd 935 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
6206f6c4 936 echo ' <b>' . _("Attachments") . ':</b>';
937 echo ' </td></tr>';
938 echo ' <tr><td>';
939 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
940 echo $attachmentsdisplay;
941 echo ' </td></tr></table>';
6c7b5d8c 942 echo ' </td></tr></table>';
6206f6c4 943 echo ' </td></tr>';
6c7b5d8c 944 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
945 $color[4].'"></TD></TR>';
a128c967 946}
c615b1da 947echo '</table>';
a07cd1a4 948
949/* show attached images inline -- if pref'fed so */
5be9f195 950if (($attachment_common_show_images) &&
a07cd1a4 951 is_array($attachment_common_show_images_list)) {
952 foreach ($attachment_common_show_images_list as $img) {
ce274df9 953 $imgurl = SM_PATH . 'src/download.php' .
57257333 954 '?' .
cd7b8833 955 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 956 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 957 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 958 '&amp;absolute_dl=true';
5be9f195 959
b5058e9e 960 echo html_tag( 'table', "\n" .
d9c1dccc 961 html_tag( 'tr', "\n" .
962 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
963 )
964 ) ,
b5058e9e 965 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 966 }
a07cd1a4 967}
968
4267d5de 969formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
1e150c97 970
c615b1da 971do_hook('read_body_bottom');
972do_hook('html_bottom');
a07cd1a4 973sqimap_logout($imapConnection);
ce274df9 974/* sessions are written at the end of the script. it's better to register
975 them at the end so we avoid double session_register calls */
976sqsession_register($messages,'messages');
e55c441a 977
dcc1cc82 978?>
979</body>
980</html>