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