Wrong include path
[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) {
c615b1da 160 global $username, $attachment_dir, $SERVER_NAME,
fc224f68 161 $version, $attachments, $squirrelmail_language, $default_charset,
d9c1dccc 162 $languages, $useSendmail, $domain, $sent_folder,
163 $popuser, $data_dir, $username;
57257333 164
38bca81c 165 $header = $message->rfc822_header;
57257333 166 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
167
fc224f68 168 $rfc822_header = new Rfc822Header();
d9c1dccc 169 $content_type = new ContentType('multipart/report');
fc224f68 170 $content_type->properties['report-type']='disposition-notification';
d9c1dccc 171
fc224f68 172 set_my_charset();
173 if ($default_charset) {
d9c1dccc 174 $content_type->properties['charset']=$default_charset;
fc224f68 175 }
176 $rfc822_header->content_type = $content_type;
177 $rfc822_header->to[] = $header->dnt;
178 $rfc822_header->subject = _("Read:") . ' ' . $header->subject;
179
180
181 $reply_to = '';
182 if (isset($identity) && $identity != 'default') {
183 $from_mail = getPref($data_dir, $username,
d9c1dccc 184 'email_address' . $identity);
fc224f68 185 $full_name = getPref($data_dir, $username,
d9c1dccc 186 'full_name' . $identity);
fc224f68 187 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 188 $reply_to = getPref($data_dir, $username,
189 'reply_to' . $identity);
fc224f68 190 } else {
191 $from_mail = getPref($data_dir, $username, 'email_address');
192 $full_name = getPref($data_dir, $username, 'full_name');
193 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 194 $reply_to = getPref($data_dir, $username,'reply_to');
fc224f68 195 }
196 if (!$from_addr) {
197 $from_addr = "$popuser@$domain";
198 $from_mail = $from_addr;
199 }
200 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
201 if ($reply_to) {
202 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
203 }
d9c1dccc 204
57257333 205 // part 1 (RFC2298)
57257333 206 $senton = getLongDateString( $header->date );
207 $to_array = $header->to;
208 $to = '';
209 foreach ($to_array as $line) {
af568a82 210 $to .= ' '.$line->getAddress();
57257333 211 }
57257333 212 $now = getLongDateString( time() );
78db1583 213 set_my_charset();
46bb8da8 214 $body = _("Your message") . "\r\n\r\n" .
215 "\t" . _("To:") . ' ' . $to . "\r\n" .
fc224f68 216 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
46bb8da8 217 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
218 "\r\n" .
219 sprintf( _("Was displayed on %s"), $now );
f69feefe 220
fc224f68 221 $special_encoding = '';
222 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
223 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 224 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
d9c1dccc 225 if (strtolower($default_charset) == 'iso-2022-jp') {
226 if (mb_detect_encoding($body) == 'ASCII') {
227 $special_encoding = '8bit';
228 } else {
229 $body = mb_convert_encoding($body, 'JIS');
230 $special_encoding = '7bit';
231 }
232 }
6fbd125b 233 }
fc224f68 234 $part1 = new Message();
235 $part1->setBody($body);
236 $mime_header = new MessageHeader;
237 $mime_header->type0 = 'text';
238 $mime_header->type1 = 'plain';
239 if ($special_encoding) {
240 $mime_header->encoding = $special_encoding;
d9c1dccc 241 } else {
fc224f68 242 $mime_header->encoding = 'us-ascii';
243 }
244 if ($default_charset) {
245 $mime_header->parameters['charset'] = $default_charset;
246 }
247 $part1->mime_header = $mime_header;
248
57257333 249 // part2 (RFC2298)
d9c1dccc 250 $original_recipient = $to;
57257333 251 $original_message_id = $header->message_id;
252
fc224f68 253 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
57257333 254 if ($original_recipient != '') {
fc224f68 255 $report .= "Original-Recipient : $original_recipient\r\n";
57257333 256 }
257 $final_recipient = $sender;
fc224f68 258 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
57257333 259 "Original-Message-ID : $original_message_id\r\n" .
260 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
261
fc224f68 262 $part2 = new Message();
263 $part2->setBody($report);
264 $mime_header = new MessageHeader;
265 $mime_header->type0 = 'message';
266 $mime_header->type1 = 'disposition-notification';
267 $mime_header->encoding = 'us-ascii';
268 $part2->mime_header = $mime_header;
269
270 $composeMessage = new Message();
271 $composeMessage->rfc822_header = $rfc822_header;
272 $composeMessage->addEntity($part1);
273 $composeMessage->addEntity($part2);
274
275
d9c1dccc 276 if ($useSendmail) {
277 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
278 global $sendmail_path;
279 $deliver = new Deliver_SendMail();
280 $stream = $deliver->initStream($composeMessage,$sendmail_path);
fc224f68 281 } else {
d9c1dccc 282 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
283 $deliver = new Deliver_SMTP();
284 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
285 if ($use_authenticated_smtp) {
286 global $key, $onetimepad;
287 $user = $username;
288 $pass = OneTimePadDecrypt($key, $onetimepad);
289 } else {
290 $user = '';
291 $pass = '';
292 }
293 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
294 $stream = $deliver->initStream($composeMessage,$domain,0,
295 $smtpServerAddress, $smtpPort, $authPop);
296 }
297 $success = false;
fc224f68 298 if ($stream) {
d9c1dccc 299 $length = $deliver->mail($composeMessage, $stream);
300 $success = $deliver->finalizeStream($stream);
fc224f68 301 }
d9c1dccc 302 if (!$success) {
fc224f68 303 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
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
320
d9c1dccc 321function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
322 $sg = $set?'+':'-';
323 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 324 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 325 $readmessage, $uid_support);
57257333 326}
327
328function ClearAttachments() {
d9c1dccc 329 global $username, $attachments, $attachment_dir;
330
331 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
332
333 $rem_attachments = array();
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 }
344 $attachments = $rem_attachments;
57257333 345}
346
4d0cd98b 347function formatRecipientString($recipients, $item ) {
d9c1dccc 348 global $show_more_cc, $show_more, $show_more_bcc,
349 $PHP_SELF;
4d0cd98b 350
d9c1dccc 351 $string = '';
38c944cc 352 if ((is_array($recipients)) && (isset($recipients[0]))) {
d9c1dccc 353 $show = false;
38c944cc 354
355 if ($item == 'to') {
d9c1dccc 356 if ($show_more) {
357 $show = true;
358 $url = set_url_var($PHP_SELF, 'show_more',0);
359 } else {
360 $url = set_url_var($PHP_SELF, 'show_more',1);
361 }
362 } else if ($item == 'cc') {
363 if ($show_more_cc) {
364 $show = true;
365 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
366 } else {
367 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
368 }
369 } else if ($item == 'bcc') {
370 if ($show_more_bcc) {
371 $show = true;
372 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
373 } else {
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
375 }
376 }
377
378 $cnt = count($recipients);
379 foreach($recipients as $r) {
380 $add = htmlspecialchars($r->getAddress());
381 if ($string) {
382 $string .= '<BR>' . $add;
383 } else {
384 $string = $add;
385 if ($cnt > 1) {
38c944cc 386 $string .= '&nbsp;(<A HREF="'.$url;
d9c1dccc 387 if ($show) {
388 $string .= '">'._("less").'</A>)';
389 } else {
390 $string .= '">'._("more").'</A>)';
391 break;
392 }
393 }
394 }
1fca12b5 395 }
4d0cd98b 396 }
c615b1da 397 return $string;
398}
399
af568a82 400function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
401 $color, $FirstTimeSee) {
2ffa3f57 402 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
403 $default_use_priority, $show_xmailer_default,
404 $mdn_user_support, $PHP_SELF, $javascript_on;
38bca81c 405
d9c1dccc 406 $header = $message->rfc822_header;
407 $env = array();
408 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
409 $from_name = $header->getAddr_s('from');
410 if (!$from_name) {
411 $from_name = $header->getAddr_s('sender');
412 if (!$from_name) {
413 $from_name = _("Unknown sender");
414 }
415 }
416 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
417 $env[_("Date")] = getLongDateString($header->date);
418 $env[_("To")] = formatRecipientString($header->to, "to");
419 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
420 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
421 if ($default_use_priority) {
422 $env[_("Priority")] = getPriorityStr($header->priority);
423 }
424 if ($show_xmailer_default) {
425 $env[_("Mailer")] = decodeHeader($header->xmailer);
426 }
427 if ($default_use_mdn) {
428 if ($mdn_user_support) {
429 if ($header->dnt) {
430 if ($message->is_mdnsent) {
431 $env[_("Read receipt")] = _("send");
432 } else {
433 $env[_("Read receipt")] = _("requested");
434 if (!($mailbox == $draft_folder ||
435 $mailbox == $sent_folder ||
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
d9c1dccc 459 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
460 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
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 }
469 echo $s;
470 do_hook("read_body_header");
471 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
472 echo '</TABLE>';
473}
c615b1da 474
7172cad7 475function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
d9c1dccc 476 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
477 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
478 $enable_forward_as_attachment;
c615b1da 479
d9c1dccc 480 $topbar_delimiter = '&nbsp;|&nbsp;';
481 $urlMailbox = urlencode($mailbox);
482 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
c615b1da 483 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
484
d9c1dccc 485 $msgs_url = $base_uri . 'src/';
486 if (isset($where) && isset($what)) {
487 $msgs_url .= 'search.php?where=' . urlencode($where) .
488 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
489 $msgs_str = _("Search results");
490 } else {
491 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
492 $startMessage . '&amp;mailbox=' . $urlMailbox;
493 $msgs_str = _("Message List");
494 }
495 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
496 $s .= $topbar_delimiter;
497
498 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
499 '&amp;message=' . $passed_id . '&amp;';
500 if (!(isset($passed_ent_id) && $passed_ent_id)) {
501 if ($where && $what) {
502 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
503 } else {
504 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
505 }
506 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
507 }
c615b1da 508
d9c1dccc 509 $comp_uri = $base_uri . 'src/compose.php' .
510 '?passed_id=' . $passed_id .
511 '&amp;mailbox=' . $urlMailbox .
512 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
2ffa3f57 513
d9c1dccc 514 if ($compose_new_win == '1') {
515 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
516 $link_close = '\')">';
517 } else {
518 $link_open = '<a href="';
519 $link_close = '">';
520 }
521 if (($mailbox == $draft_folder) && ($save_as_draft)) {
522 $comp_alt_uri = $comp_uri . '&amp;action=draft';
523 $comp_alt_string = _("Resume Draft");
524 } else if ($mailbox == $sent_folder) {
525 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
526 $comp_alt_string = _("Edit Message as New");
527 }
528 if (isset($comp_alt_uri)) {
529 $s .= $topbar_delimiter;
530 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
531 }
2ffa3f57 532
d9c1dccc 533 $s .= '</small></td><td align="center" width="33%"><small>';
534
535 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
536 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
537 $next = findNextMessage($passed_id);
538 if ($prev != -1) {
539 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
540 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
541 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
542 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
543 } else {
544 $s .= _("Previous");
545 }
2ffa3f57 546 $s .= $topbar_delimiter;
d9c1dccc 547 if ($next != -1) {
548 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
549 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
550 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
551 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
552 } else {
553 $s .= _("Next");
554 }
555 } else if (isset($passed_ent_id) && $passed_ent_id) {
556 /* code for navigating through attached message/rfc822 messages */
557 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
558 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
559 $par_ent_id = $message->parent->entity_id;
560 if ($par_ent_id) {
561 $par_ent_id = substr($par_ent_id,0,-2);
562 $s .= $topbar_delimiter;
563 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
564 $s .= '<a href="'.$url.'">'._("Up").'</a>';
565 }
566 }
c615b1da 567
d9c1dccc 568 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
569 $comp_action_uri = $comp_uri . '&amp;action=forward';
570 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
571 $s .= $topbar_delimiter;
c615b1da 572
d9c1dccc 573 if ($enable_forward_as_attachment) {
574 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
575 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
576 $s .= $topbar_delimiter;
577 }
a128c967 578
d9c1dccc 579 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
580 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
581 $s .= $topbar_delimiter;
582
583 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
584 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
585 $s .= '</small></td></tr></table>';
586 do_hook("read_body_menu_top");
587 echo $s;
588 do_hook("read_body_menu_bottom");
c615b1da 589}
590
591function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
d9c1dccc 592 global $QUERY_STRING, $base_uri;
c615b1da 593
d9c1dccc 594 $urlMailbox = urlencode($mailbox);
595 $url = $base_uri.'src/view_header.php?'.$QUERY_STRING;
596
597 $s = "<TR>\n" .
598 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
599 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
600 '<a href="'.$url.'">'._("View Full Header").'</a>';
601
602 /* Output the printer friendly link if we are in subtle mode. */
603 $s .= '&nbsp;|&nbsp;' .
604 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
605 echo $s;
606 do_hook("read_body_header_right");
607 $s = "</SMALL></TD>\n" .
608 "</TR>\n";
609 echo $s;
a128c967 610
4d0cd98b 611}
612
6206f6c4 613/***************************/
2ffa3f57 614/* Main of read_body.php */
6206f6c4 615/***************************/
57257333 616
617/*
618 Urled vars
619 ----------
620 $passed_id
621*/
a07cd1a4 622
38c944cc 623global $uid_support, $sqimap_capabilities;
624
6a108031 625if (isset($mailbox)) {
4366bea4 626 $mailbox = urldecode( $mailbox );
627}
38c944cc 628
6206f6c4 629$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38c944cc 630$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
631
632if (!isset($messages)) {
633 $messages = array();
fc224f68 634 sqsession_register($messages,'messages');
38c944cc 635}
636
637/**
638 * $message contains all information about the message
639 * including header and body
640 */
37d2a6ee 641
642$uidvalidity = $mbx_response['UIDVALIDITY'];
643
644if (!isset($messages[$uidvalidity])) {
645 $messages[$uidvalidity] = array();
646}
5200c026 647if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
648 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 649 $FirstTimeSee = !$message->is_seen;
650 $message->is_seen = true;
5200c026 651 $messages[$uidvalidity][$passed_id] = $message;
fc224f68 652 sqsession_register($messages, 'messages');
38c944cc 653} else {
fc224f68 654// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
655 $message = $messages[$uidvalidity][$passed_id];
656 $FirstTimeSee = !$message->is_seen;
5200c026 657}
fc224f68 658//$FirstTimeSee = !$message->is_seen;
659//$message->is_seen = true;
660//$messages[$uidvalidity][$passed_id] = $message;
af568a82 661
dd628162 662if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 663 $message = $message->getEntity($passed_ent_id);
ff9d4297 664 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
665 $message = $message->parent;
666 }
141a16b2 667 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 668 $rfc822_header = new Rfc822Header();
141a16b2 669 $rfc822_header->parseHeader($read);
670 $message->rfc822_header = $rfc822_header;
c615b1da 671} else {
672 $passed_ent_id = 0;
38c944cc 673}
5200c026 674$header = $message->header;
57257333 675
6c31f818 676do_hook('html_top');
57257333 677
6206f6c4 678/****************************************/
679/* Block for handling incoming url vars */
680/****************************************/
5200c026 681
5200c026 682if (isset($sendreceipt)) {
683 if ( !$message->is_mdnsent ) {
684 if (isset($identity) ) {
685 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
686 } else {
687 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
688 }
689
690 $final_recipient = trim($final_recipient);
691 if ($final_recipient == '' ) {
692 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
693 }
af568a82 694 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 695 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 696 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 697 $message->is_mdnsent = true;
6a108031 698 $messages[$uidvalidity][$passed_id]=$message;
5200c026 699 }
700 ClearAttachments();
701 }
702}
6206f6c4 703/***********************************************/
704/* End of block for handling incoming url vars */
705/***********************************************/
706
38c944cc 707$msgs[$passed_id]['FLAG_SEEN'] = true;
38c944cc 708
5200c026 709$messagebody = '';
c4ad259b 710do_hook('read_body_top');
711if ($show_html_default == 1) {
712 $ent_ar = $message->findDisplayEntity(array());
713} else {
714 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
715}
a128c967 716$cnt = count($ent_ar);
717for ($i = 0; $i < $cnt; $i++) {
6a108031 718 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 719 if ($i != $cnt-1) {
720 $messagebody .= '<hr noshade size=1>';
721 }
38c944cc 722}
6a108031 723
c615b1da 724displayPageHeader($color, $mailbox);
7172cad7 725formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 726formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
6206f6c4 727echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
728echo ' <tr><td>';
729echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 730echo ' <tr><td>';
6206f6c4 731echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
732echo ' <tr bgcolor="'.$color[4].'"><td>';
733echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">';
734echo ' <tr><td><br>' . $messagebody . '</td></td>';
735echo ' </table>';
736echo ' </td></tr>';
737echo ' </table></td></tr>';
2ffa3f57 738echo ' </table>';
739echo ' </td></tr>';
a128c967 740
741$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
742if ($attachmentsdisplay) {
2ffa3f57 743 echo ' <tr><td>';
6206f6c4 744 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 745 echo ' <tr><td>';
746 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
6206f6c4 747 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
748 echo ' <b>' . _("Attachments") . ':</b>';
749 echo ' </td></tr>';
750 echo ' <tr><td>';
751 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
752 echo $attachmentsdisplay;
753 echo ' </td></tr></table>';
754 echo ' </table></td></tr>';
2ffa3f57 755 echo ' </table></td></tr>';
6206f6c4 756 echo ' </table>';
757 echo ' </td></tr>';
a128c967 758}
c615b1da 759echo '</table>';
a07cd1a4 760
a128c967 761
a07cd1a4 762/* show attached images inline -- if pref'fed so */
5be9f195 763if (($attachment_common_show_images) &&
a07cd1a4 764 is_array($attachment_common_show_images_list)) {
765 foreach ($attachment_common_show_images_list as $img) {
5be9f195 766 $imgurl = '../src/download.php' .
57257333 767 '?' .
cd7b8833 768 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 769 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 770 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 771 '&amp;absolute_dl=true';
5be9f195 772
b5058e9e 773 echo html_tag( 'table', "\n" .
d9c1dccc 774 html_tag( 'tr', "\n" .
775 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
776 )
777 ) ,
b5058e9e 778 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 779 }
a07cd1a4 780}
781
c615b1da 782do_hook('read_body_bottom');
783do_hook('html_bottom');
d7eab095 784//$message->clean_up();
a07cd1a4 785sqimap_logout($imapConnection);
786?>
c615b1da 787</body>
788</html>