if boolean vars are quoted they become strings
[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
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/mime.php');
22require_once(SM_PATH . 'functions/date.php');
23require_once(SM_PATH . 'functions/url_parser.php');
24require_once(SM_PATH . 'functions/html.php');
38c944cc 25
d9c1dccc 26
a07cd1a4 27/**
1fca12b5 28 * Given an IMAP message id number, this will look it up in the cached
29 * and sorted msgs array and return the index. Used for finding the next
30 * and previous messages.
31 *
32 * @return the index of the next valid message from the array
33 */
c615b1da 34function findNextMessage($passed_id) {
35 global $msort, $msgs, $sort,
cf710efe 36 $thread_sort_messages, $allow_server_sort,
60a3e687 37 $server_sort_array;
2728fa19 38 if (!is_array($server_sort_array)) {
39 $thread_sort_messages = 0;
794d59c0 40 $allow_server_sort = FALSE;
2728fa19 41 }
a07cd1a4 42 $result = -1;
c615b1da 43 if ($thread_sort_messages || $allow_server_sort) {
d9c1dccc 44 $count = count($server_sort_array) - 1;
45 foreach($server_sort_array as $key=>$value) {
c615b1da 46 if ($passed_id == $value) {
d9c1dccc 47 if ($key == $count) {
60a3e687 48 break;
49 }
1fca12b5 50 $result = $server_sort_array[$key + 1];
60a3e687 51 break;
789b4d79 52 }
60a3e687 53 }
d9c1dccc 54 } else {
55 if ($sort == 6) {
56 if ($passed_id != 1) {
57 $result = $passed_id - 1;
58 }
59 } else {
60 if (is_array($msort)) {
61 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
62 if ($passed_id == $msgs[$key]['ID']) {
63 next($msort);
64 $key = key($msort);
65 if (isset($key)){
66 $result = $msgs[$key]['ID'];
67 break;
68 }
69 }
1fca12b5 70 }
10f0ce72 71 }
72 }
10f0ce72 73 }
d9c1dccc 74 return $result;
a07cd1a4 75}
76
a07cd1a4 77/** returns the index of the previous message from the array. */
c615b1da 78function findPreviousMessage($numMessages, $passed_id) {
79 global $msort, $sort, $msgs,
80 $thread_sort_messages,
60a3e687 81 $allow_server_sort, $server_sort_array;
a07cd1a4 82 $result = -1;
2728fa19 83 if (!is_array($server_sort_array)) {
84 $thread_sort_messages = 0;
794d59c0 85 $allow_server_sort = FALSE;
2728fa19 86 }
c615b1da 87 if ($thread_sort_messages || $allow_server_sort ) {
d9c1dccc 88 foreach($server_sort_array as $key=>$value) {
c615b1da 89 if ($passed_id == $value) {
60a3e687 90 if ($key == 0) {
60a3e687 91 break;
92 }
d9c1dccc 93 $result = $server_sort_array[$key - 1];
60a3e687 94 break;
789b4d79 95 }
60a3e687 96 }
d9c1dccc 97 } else {
98 if ($sort == 6) {
99 if ($passed_id != $numMessages) {
100 $result = $passed_id + 1;
101 }
102 } else {
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 //echo $msort[$key]; /* Why again were we echoing here? */
110 $result = $msgs[$key]['ID'];
111 break;
112 }
113 }
10f0ce72 114 }
115 }
10f0ce72 116 }
a07cd1a4 117 }
d9c1dccc 118 return $result;
a07cd1a4 119}
10f0ce72 120
a07cd1a4 121/**
1fca12b5 122 * Displays a link to a page where the message is displayed more
123 * "printer friendly".
124 */
c615b1da 125function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
126 global $javascript_on;
a07cd1a4 127
c615b1da 128 $params = '?passed_ent_id=' . $passed_ent_id .
d9c1dccc 129 '&mailbox=' . urlencode($mailbox) .
130 '&passed_id=' . $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) {
3d570ba0 137 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
d9c1dccc 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 {
b5058e9e 147 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
d9c1dccc 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 */
d9c1dccc 155 $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read);
156 return $ret;
57257333 157}
158
fc224f68 159function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
0b97a708 160 global $username, $attachment_dir, $_SERVER,
fc224f68 161 $version, $attachments, $squirrelmail_language, $default_charset,
d9c1dccc 162 $languages, $useSendmail, $domain, $sent_folder,
163 $popuser, $data_dir, $username;
57257333 164
0b97a708 165 $SERVER_NAME = $_SERVER['SERVER_NAME'];
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;
180 $rfc822_header->subject = _("Read:") . ' ' . $header->subject;
181
182
183 $reply_to = '';
184 if (isset($identity) && $identity != 'default') {
185 $from_mail = getPref($data_dir, $username,
d9c1dccc 186 'email_address' . $identity);
fc224f68 187 $full_name = getPref($data_dir, $username,
d9c1dccc 188 'full_name' . $identity);
fc224f68 189 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 190 $reply_to = getPref($data_dir, $username,
191 'reply_to' . $identity);
fc224f68 192 } else {
193 $from_mail = getPref($data_dir, $username, 'email_address');
194 $full_name = getPref($data_dir, $username, 'full_name');
195 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 196 $reply_to = getPref($data_dir, $username,'reply_to');
fc224f68 197 }
198 if (!$from_addr) {
199 $from_addr = "$popuser@$domain";
200 $from_mail = $from_addr;
201 }
202 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
203 if ($reply_to) {
204 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
205 }
d9c1dccc 206
57257333 207 // part 1 (RFC2298)
57257333 208 $senton = getLongDateString( $header->date );
209 $to_array = $header->to;
210 $to = '';
211 foreach ($to_array as $line) {
af568a82 212 $to .= ' '.$line->getAddress();
57257333 213 }
57257333 214 $now = getLongDateString( time() );
78db1583 215 set_my_charset();
46bb8da8 216 $body = _("Your message") . "\r\n\r\n" .
217 "\t" . _("To:") . ' ' . $to . "\r\n" .
fc224f68 218 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
46bb8da8 219 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
220 "\r\n" .
221 sprintf( _("Was displayed on %s"), $now );
f69feefe 222
fc224f68 223 $special_encoding = '';
224 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
225 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 226 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
d9c1dccc 227 if (strtolower($default_charset) == 'iso-2022-jp') {
228 if (mb_detect_encoding($body) == 'ASCII') {
229 $special_encoding = '8bit';
230 } else {
231 $body = mb_convert_encoding($body, 'JIS');
232 $special_encoding = '7bit';
233 }
234 }
6fbd125b 235 }
fc224f68 236 $part1 = new Message();
237 $part1->setBody($body);
238 $mime_header = new MessageHeader;
239 $mime_header->type0 = 'text';
240 $mime_header->type1 = 'plain';
241 if ($special_encoding) {
242 $mime_header->encoding = $special_encoding;
d9c1dccc 243 } else {
fc224f68 244 $mime_header->encoding = 'us-ascii';
245 }
246 if ($default_charset) {
247 $mime_header->parameters['charset'] = $default_charset;
248 }
249 $part1->mime_header = $mime_header;
250
57257333 251 // part2 (RFC2298)
d9c1dccc 252 $original_recipient = $to;
57257333 253 $original_message_id = $header->message_id;
254
fc224f68 255 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
57257333 256 if ($original_recipient != '') {
fc224f68 257 $report .= "Original-Recipient : $original_recipient\r\n";
57257333 258 }
259 $final_recipient = $sender;
fc224f68 260 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
57257333 261 "Original-Message-ID : $original_message_id\r\n" .
262 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
263
fc224f68 264 $part2 = new Message();
265 $part2->setBody($report);
266 $mime_header = new MessageHeader;
267 $mime_header->type0 = 'message';
268 $mime_header->type1 = 'disposition-notification';
269 $mime_header->encoding = 'us-ascii';
270 $part2->mime_header = $mime_header;
271
272 $composeMessage = new Message();
273 $composeMessage->rfc822_header = $rfc822_header;
274 $composeMessage->addEntity($part1);
275 $composeMessage->addEntity($part2);
276
277
d9c1dccc 278 if ($useSendmail) {
279 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
280 global $sendmail_path;
281 $deliver = new Deliver_SendMail();
282 $stream = $deliver->initStream($composeMessage,$sendmail_path);
fc224f68 283 } else {
d9c1dccc 284 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
285 $deliver = new Deliver_SMTP();
286 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
287 if ($use_authenticated_smtp) {
288 global $key, $onetimepad;
289 $user = $username;
290 $pass = OneTimePadDecrypt($key, $onetimepad);
291 } else {
292 $user = '';
293 $pass = '';
294 }
295 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
296 $stream = $deliver->initStream($composeMessage,$domain,0,
297 $smtpServerAddress, $smtpPort, $authPop);
298 }
299 $success = false;
fc224f68 300 if ($stream) {
d9c1dccc 301 $length = $deliver->mail($composeMessage, $stream);
302 $success = $deliver->finalizeStream($stream);
fc224f68 303 }
d9c1dccc 304 if (!$success) {
fc224f68 305 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
d9c1dccc 306 require_once(SM_PATH . 'functions/display_messages.php');
fc224f68 307 plain_error_message($msg, $color);
308 } else {
309 unset ($deliver);
d9c1dccc 310 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
311 sqimap_append ($imapConnection, $sent_folder, $length);
312 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
313 $imap_deliver = new Deliver_IMAP();
314 $imap_deliver->mail($composeMessage, $imapConnection);
315 sqimap_append_done ($imapConnection);
316 unset ($imap_deliver);
317 }
318 }
319 return $success;
57257333 320}
321
322
d9c1dccc 323function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
324 $sg = $set?'+':'-';
325 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 326 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 327 $readmessage, $uid_support);
57257333 328}
329
330function ClearAttachments() {
d9c1dccc 331 global $username, $attachments, $attachment_dir;
332
333 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
334
335 $rem_attachments = array();
336 foreach ($attachments as $info) {
337 if ($info['session'] == -1) {
338 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
339 if (file_exists($attached_file)) {
340 unlink($attached_file);
341 }
342 } else {
343 $rem_attachments[] = $info;
344 }
345 }
346 $attachments = $rem_attachments;
57257333 347}
348
4d0cd98b 349function formatRecipientString($recipients, $item ) {
d9c1dccc 350 global $show_more_cc, $show_more, $show_more_bcc,
351 $PHP_SELF;
4d0cd98b 352
d9c1dccc 353 $string = '';
38c944cc 354 if ((is_array($recipients)) && (isset($recipients[0]))) {
d9c1dccc 355 $show = false;
38c944cc 356
357 if ($item == 'to') {
d9c1dccc 358 if ($show_more) {
359 $show = true;
360 $url = set_url_var($PHP_SELF, 'show_more',0);
361 } else {
362 $url = set_url_var($PHP_SELF, 'show_more',1);
363 }
364 } else if ($item == 'cc') {
365 if ($show_more_cc) {
366 $show = true;
367 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
368 } else {
369 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
370 }
371 } else if ($item == 'bcc') {
372 if ($show_more_bcc) {
373 $show = true;
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
375 } else {
376 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
377 }
378 }
379
380 $cnt = count($recipients);
381 foreach($recipients as $r) {
382 $add = htmlspecialchars($r->getAddress());
383 if ($string) {
384 $string .= '<BR>' . $add;
385 } else {
386 $string = $add;
387 if ($cnt > 1) {
38c944cc 388 $string .= '&nbsp;(<A HREF="'.$url;
d9c1dccc 389 if ($show) {
390 $string .= '">'._("less").'</A>)';
391 } else {
392 $string .= '">'._("more").'</A>)';
393 break;
394 }
395 }
396 }
1fca12b5 397 }
4d0cd98b 398 }
c615b1da 399 return $string;
400}
401
af568a82 402function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
403 $color, $FirstTimeSee) {
2ffa3f57 404 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
405 $default_use_priority, $show_xmailer_default,
406 $mdn_user_support, $PHP_SELF, $javascript_on;
38bca81c 407
d9c1dccc 408 $header = $message->rfc822_header;
409 $env = array();
410 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
411 $from_name = $header->getAddr_s('from');
412 if (!$from_name) {
413 $from_name = $header->getAddr_s('sender');
414 if (!$from_name) {
415 $from_name = _("Unknown sender");
416 }
417 }
418 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
419 $env[_("Date")] = getLongDateString($header->date);
420 $env[_("To")] = formatRecipientString($header->to, "to");
421 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
422 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
423 if ($default_use_priority) {
424 $env[_("Priority")] = getPriorityStr($header->priority);
425 }
426 if ($show_xmailer_default) {
427 $env[_("Mailer")] = decodeHeader($header->xmailer);
428 }
429 if ($default_use_mdn) {
430 if ($mdn_user_support) {
431 if ($header->dnt) {
432 if ($message->is_mdnsent) {
433 $env[_("Read receipt")] = _("send");
434 } else {
435 $env[_("Read receipt")] = _("requested");
436 if (!($mailbox == $draft_folder ||
437 $mailbox == $sent_folder ||
438 $message->is_deleted ||
439 $passed_ent_id)) {
440 $mdn_url = $PHP_SELF . '&sendreceipt=1';
441 if ($FirstTimeSee && $javascript_on) {
442 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
443 $script .= '<!--'. "\n";
444 $script .= 'if(window.confirm("' .
445 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
446 '")) { '."\n" .
447 ' sendMDN()'.
448 '}' . "\n";
449 $script .= '// -->'. "\n";
450 $script .= '</script>'. "\n";
451 echo $script;
452 }
453 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
454 _("Send read receipt now") . ']</a>';
455 }
456 }
457 }
458 }
459 }
c615b1da 460
d9c1dccc 461 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
462 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
463 foreach ($env as $key => $val) {
464 if ($val) {
465 $s .= '<TR>';
466 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
467 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
468 $s .= '</TR>';
469 }
470 }
471 echo $s;
472 do_hook("read_body_header");
473 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
474 echo '</TABLE>';
475}
c615b1da 476
7172cad7 477function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
d9c1dccc 478 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
479 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
480 $enable_forward_as_attachment;
c615b1da 481
d9c1dccc 482 $topbar_delimiter = '&nbsp;|&nbsp;';
483 $urlMailbox = urlencode($mailbox);
484 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
c615b1da 485 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
486
d9c1dccc 487 $msgs_url = $base_uri . 'src/';
488 if (isset($where) && isset($what)) {
489 $msgs_url .= 'search.php?where=' . urlencode($where) .
490 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
491 $msgs_str = _("Search results");
492 } else {
493 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
494 $startMessage . '&amp;mailbox=' . $urlMailbox;
495 $msgs_str = _("Message List");
496 }
497 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
498 $s .= $topbar_delimiter;
499
500 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
501 '&amp;message=' . $passed_id . '&amp;';
502 if (!(isset($passed_ent_id) && $passed_ent_id)) {
503 if ($where && $what) {
504 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
505 } else {
506 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
507 }
508 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
509 }
c615b1da 510
d9c1dccc 511 $comp_uri = $base_uri . 'src/compose.php' .
512 '?passed_id=' . $passed_id .
513 '&amp;mailbox=' . $urlMailbox .
514 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
2ffa3f57 515
d9c1dccc 516 if ($compose_new_win == '1') {
517 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
518 $link_close = '\')">';
519 } else {
520 $link_open = '<a href="';
521 $link_close = '">';
522 }
523 if (($mailbox == $draft_folder) && ($save_as_draft)) {
524 $comp_alt_uri = $comp_uri . '&amp;action=draft';
525 $comp_alt_string = _("Resume Draft");
526 } else if ($mailbox == $sent_folder) {
527 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
528 $comp_alt_string = _("Edit Message as New");
529 }
530 if (isset($comp_alt_uri)) {
531 $s .= $topbar_delimiter;
532 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
533 }
2ffa3f57 534
d9c1dccc 535 $s .= '</small></td><td align="center" width="33%"><small>';
536
537 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
538 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
539 $next = findNextMessage($passed_id);
540 if ($prev != -1) {
541 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
542 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
543 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
544 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
545 } else {
546 $s .= _("Previous");
547 }
2ffa3f57 548 $s .= $topbar_delimiter;
d9c1dccc 549 if ($next != -1) {
550 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
551 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
552 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
553 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
554 } else {
555 $s .= _("Next");
556 }
557 } else if (isset($passed_ent_id) && $passed_ent_id) {
558 /* code for navigating through attached message/rfc822 messages */
559 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
560 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
561 $par_ent_id = $message->parent->entity_id;
562 if ($par_ent_id) {
563 $par_ent_id = substr($par_ent_id,0,-2);
564 $s .= $topbar_delimiter;
565 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
566 $s .= '<a href="'.$url.'">'._("Up").'</a>';
567 }
568 }
c615b1da 569
d9c1dccc 570 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
571 $comp_action_uri = $comp_uri . '&amp;action=forward';
572 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
573 $s .= $topbar_delimiter;
c615b1da 574
d9c1dccc 575 if ($enable_forward_as_attachment) {
576 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
577 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
578 $s .= $topbar_delimiter;
579 }
a128c967 580
d9c1dccc 581 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
582 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
583 $s .= $topbar_delimiter;
584
585 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
586 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
587 $s .= '</small></td></tr></table>';
588 do_hook("read_body_menu_top");
589 echo $s;
590 do_hook("read_body_menu_bottom");
c615b1da 591}
592
593function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
fe369c70 594 global $base_uri;
595
d9c1dccc 596 $urlMailbox = urlencode($mailbox);
fe369c70 597 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
d9c1dccc 598
599 $s = "<TR>\n" .
600 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
601 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
602 '<a href="'.$url.'">'._("View Full Header").'</a>';
603
604 /* Output the printer friendly link if we are in subtle mode. */
605 $s .= '&nbsp;|&nbsp;' .
606 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
607 echo $s;
608 do_hook("read_body_header_right");
609 $s = "</SMALL></TD>\n" .
610 "</TR>\n";
611 echo $s;
a128c967 612
4d0cd98b 613}
614
6206f6c4 615/***************************/
2ffa3f57 616/* Main of read_body.php */
6206f6c4 617/***************************/
57257333 618
0b97a708 619/* get the globals we may need */
620
621$username = $_SESSION['username'];
622$key = $_COOKIE['key'];
623$onetimepad = $_SESSION['onetimepad'];
624$msgs = $_SESSION['msgs'];
625$base_uri = $_SESSION['base_uri'];
626$delimiter = $_SESSION['delimiter'];
627
628if (isset($_GET['passed_id'])) {
629 $passed_id = $_GET['passed_id'];
630}
631elseif (isset($_POST['passed_id'])) {
632 $passed_id = $_POST['passed_id'];
633}
634
ce274df9 635if (isset($_GET['passed_ent_id'])) {
636 $passed_ent_id = $_GET['passed_ent_id'];
637}
638elseif (isset($_POST['passed_ent_id'])) {
639 $passed_ent_id = $_POST['passed_ent_id'];
640}
641
0b97a708 642if (isset($_GET['sendreceipt'])) {
643 $sendreceipt = $_GET['sendreceipt'];
644}
645
646if (isset($_GET['sort'])) {
647 $sort = $_GET['sort'];
648}
649elseif (isset($_POST['sort'])) {
650 $sort = $_POST['sort'];
651}
652if (isset($_GET['startMessage'])) {
653 $startMessage = $_GET['startMessage'];
654}
655elseif (isset($_POST['startMessage'])) {
656 $startMessage = $_POST['startMessage'];
657}
658if (isset($_GET['show_more'])) {
659 $show_more = $_GET['show_more'];
660}
1b9f3c04 661if (isset($_GET['show_more_cc'])) {
662 $show_more_cc = $_GET['show_more_cc'];
663}
664if (isset($_GET['show_more_bcc'])) {
665 $show_more_bcc = $_GET['show_more_bcc'];
0b97a708 666}
667if (isset($_GET['mailbox'])) {
668 $mailbox = $_GET['mailbox'];
669}
670elseif (isset($_POST['mailbox'])) {
671 $mailbox = $_POST['mailbox'];
672}
673if (isset($_GET['where'])) {
674 $where = $_GET['where'];
675}
676if (isset($_GET['what'])) {
677 $what = $_GET['what'];
678}
679if (isset($_GET['view_hdr'])) {
680 $view_hdr = $_GET['view_hdr'];
681}
682if (isset($_SESSION['server_sort_array'])) {
683 $server_sort_array = $_SESSION['server_sort_array'];
684}
685if (isset($_SESSION['msgs'])) {
686 $msgs = $_SESSION['msgs'];
687}
688if (isset($_SESSION['msort'])) {
689 $msort = $_SESSION['msort'];
690}
691if (isset($_POST['move_id'])) {
692 $move_id = $_POST['move_id'];
693}
694if (isset($_SESSION['lastTargetMailbox'])) {
695 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
696}
ce274df9 697if (isset($_SESSION['messages'])) {
698 $messages = $_SESSION['messages'];
699} else {
700 $messages = array();
701}
0b97a708 702
a07cd1a4 703
ce274df9 704
705/* end of get globals */
38c944cc 706global $uid_support, $sqimap_capabilities;
707
6a108031 708if (isset($mailbox)) {
4366bea4 709 $mailbox = urldecode( $mailbox );
710}
38c944cc 711
6206f6c4 712$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38c944cc 713$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
714
38c944cc 715
716/**
717 * $message contains all information about the message
718 * including header and body
719 */
37d2a6ee 720
721$uidvalidity = $mbx_response['UIDVALIDITY'];
722
723if (!isset($messages[$uidvalidity])) {
724 $messages[$uidvalidity] = array();
725}
5200c026 726if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
727 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 728 $FirstTimeSee = !$message->is_seen;
729 $message->is_seen = true;
5200c026 730 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 731} else {
fc224f68 732// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
733 $message = $messages[$uidvalidity][$passed_id];
734 $FirstTimeSee = !$message->is_seen;
5200c026 735}
af568a82 736
dd628162 737if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 738 $message = $message->getEntity($passed_ent_id);
ff9d4297 739 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
740 $message = $message->parent;
741 }
141a16b2 742 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 743 $rfc822_header = new Rfc822Header();
141a16b2 744 $rfc822_header->parseHeader($read);
745 $message->rfc822_header = $rfc822_header;
c615b1da 746} else {
747 $passed_ent_id = 0;
38c944cc 748}
5200c026 749$header = $message->header;
57257333 750
6c31f818 751do_hook('html_top');
57257333 752
6206f6c4 753/****************************************/
754/* Block for handling incoming url vars */
755/****************************************/
5200c026 756
5200c026 757if (isset($sendreceipt)) {
758 if ( !$message->is_mdnsent ) {
759 if (isset($identity) ) {
760 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
761 } else {
762 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
763 }
764
765 $final_recipient = trim($final_recipient);
766 if ($final_recipient == '' ) {
767 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
768 }
af568a82 769 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 770 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 771 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 772 $message->is_mdnsent = true;
6a108031 773 $messages[$uidvalidity][$passed_id]=$message;
5200c026 774 }
775 ClearAttachments();
776 }
777}
6206f6c4 778/***********************************************/
779/* End of block for handling incoming url vars */
780/***********************************************/
781
38c944cc 782$msgs[$passed_id]['FLAG_SEEN'] = true;
38c944cc 783
5200c026 784$messagebody = '';
c4ad259b 785do_hook('read_body_top');
786if ($show_html_default == 1) {
787 $ent_ar = $message->findDisplayEntity(array());
788} else {
789 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
790}
a128c967 791$cnt = count($ent_ar);
792for ($i = 0; $i < $cnt; $i++) {
6a108031 793 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 794 if ($i != $cnt-1) {
795 $messagebody .= '<hr noshade size=1>';
796 }
38c944cc 797}
6a108031 798
c615b1da 799displayPageHeader($color, $mailbox);
7172cad7 800formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 801formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
6206f6c4 802echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
803echo ' <tr><td>';
804echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 805echo ' <tr><td>';
6206f6c4 806echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
807echo ' <tr bgcolor="'.$color[4].'"><td>';
bc947071 808echo ' <table cellpadding="5" cellspacing="0" border="0">';
809echo ' <tr>'. html_tag( 'td', '<br>'. $messagebody."\n", 'left').'</td>';
6206f6c4 810echo ' </table>';
811echo ' </td></tr>';
812echo ' </table></td></tr>';
2ffa3f57 813echo ' </table>';
814echo ' </td></tr>';
a128c967 815
816$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
817if ($attachmentsdisplay) {
2ffa3f57 818 echo ' <tr><td>';
6206f6c4 819 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 820 echo ' <tr><td>';
821 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
6206f6c4 822 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
823 echo ' <b>' . _("Attachments") . ':</b>';
824 echo ' </td></tr>';
825 echo ' <tr><td>';
826 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
827 echo $attachmentsdisplay;
828 echo ' </td></tr></table>';
829 echo ' </table></td></tr>';
2ffa3f57 830 echo ' </table></td></tr>';
6206f6c4 831 echo ' </table>';
832 echo ' </td></tr>';
a128c967 833}
c615b1da 834echo '</table>';
a07cd1a4 835
836/* show attached images inline -- if pref'fed so */
5be9f195 837if (($attachment_common_show_images) &&
a07cd1a4 838 is_array($attachment_common_show_images_list)) {
839 foreach ($attachment_common_show_images_list as $img) {
ce274df9 840 $imgurl = SM_PATH . 'src/download.php' .
57257333 841 '?' .
cd7b8833 842 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 843 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 844 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 845 '&amp;absolute_dl=true';
5be9f195 846
b5058e9e 847 echo html_tag( 'table', "\n" .
d9c1dccc 848 html_tag( 'tr', "\n" .
849 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
850 )
851 ) ,
b5058e9e 852 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 853 }
a07cd1a4 854}
855
c615b1da 856do_hook('read_body_bottom');
857do_hook('html_bottom');
a07cd1a4 858sqimap_logout($imapConnection);
ce274df9 859/* sessions are written at the end of the script. it's better to register
860 them at the end so we avoid double session_register calls */
861sqsession_register($messages,'messages');
862
a07cd1a4 863?>
c615b1da 864</body>
865</html>