disable if we are in an opened message/rfc822 attachment
[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
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 .
d9c1dccc 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) {
3d570ba0 123 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
d9c1dccc 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 {
b5058e9e 133 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
d9c1dccc 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();
272 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
273 if ($use_authenticated_smtp) {
274 global $key, $onetimepad;
275 $user = $username;
276 $pass = OneTimePadDecrypt($key, $onetimepad);
277 } else {
278 $user = '';
279 $pass = '';
280 }
281 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
282 $stream = $deliver->initStream($composeMessage,$domain,0,
283 $smtpServerAddress, $smtpPort, $authPop);
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) {
fc224f68 291 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
d9c1dccc 292 require_once(SM_PATH . 'functions/display_messages.php');
fc224f68 293 plain_error_message($msg, $color);
294 } else {
295 unset ($deliver);
d9c1dccc 296 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
297 sqimap_append ($imapConnection, $sent_folder, $length);
298 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
299 $imap_deliver = new Deliver_IMAP();
300 $imap_deliver->mail($composeMessage, $imapConnection);
301 sqimap_append_done ($imapConnection);
302 unset ($imap_deliver);
303 }
304 }
305 return $success;
57257333 306}
307
308
d9c1dccc 309function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
310 $sg = $set?'+':'-';
311 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 312 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 313 $readmessage, $uid_support);
57257333 314}
315
316function ClearAttachments() {
d9c1dccc 317 global $username, $attachments, $attachment_dir;
318
319 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
320
321 $rem_attachments = array();
322 foreach ($attachments as $info) {
323 if ($info['session'] == -1) {
324 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
325 if (file_exists($attached_file)) {
326 unlink($attached_file);
327 }
328 } else {
329 $rem_attachments[] = $info;
330 }
331 }
332 $attachments = $rem_attachments;
57257333 333}
334
4d0cd98b 335function formatRecipientString($recipients, $item ) {
d9c1dccc 336 global $show_more_cc, $show_more, $show_more_bcc,
337 $PHP_SELF;
4d0cd98b 338
d9c1dccc 339 $string = '';
38c944cc 340 if ((is_array($recipients)) && (isset($recipients[0]))) {
d9c1dccc 341 $show = false;
38c944cc 342
343 if ($item == 'to') {
d9c1dccc 344 if ($show_more) {
345 $show = true;
346 $url = set_url_var($PHP_SELF, 'show_more',0);
347 } else {
348 $url = set_url_var($PHP_SELF, 'show_more',1);
349 }
350 } else if ($item == 'cc') {
351 if ($show_more_cc) {
352 $show = true;
353 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
354 } else {
355 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
356 }
357 } else if ($item == 'bcc') {
358 if ($show_more_bcc) {
359 $show = true;
360 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
361 } else {
362 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
363 }
364 }
365
366 $cnt = count($recipients);
367 foreach($recipients as $r) {
368 $add = htmlspecialchars($r->getAddress());
369 if ($string) {
370 $string .= '<BR>' . $add;
371 } else {
372 $string = $add;
373 if ($cnt > 1) {
38c944cc 374 $string .= '&nbsp;(<A HREF="'.$url;
d9c1dccc 375 if ($show) {
376 $string .= '">'._("less").'</A>)';
377 } else {
378 $string .= '">'._("more").'</A>)';
379 break;
380 }
381 }
382 }
1fca12b5 383 }
4d0cd98b 384 }
c615b1da 385 return $string;
386}
387
af568a82 388function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
389 $color, $FirstTimeSee) {
2ffa3f57 390 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
391 $default_use_priority, $show_xmailer_default,
392 $mdn_user_support, $PHP_SELF, $javascript_on;
38bca81c 393
d9c1dccc 394 $header = $message->rfc822_header;
395 $env = array();
396 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
397 $from_name = $header->getAddr_s('from');
398 if (!$from_name) {
399 $from_name = $header->getAddr_s('sender');
400 if (!$from_name) {
401 $from_name = _("Unknown sender");
402 }
403 }
404 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
405 $env[_("Date")] = getLongDateString($header->date);
406 $env[_("To")] = formatRecipientString($header->to, "to");
407 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
408 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
409 if ($default_use_priority) {
410 $env[_("Priority")] = getPriorityStr($header->priority);
411 }
412 if ($show_xmailer_default) {
413 $env[_("Mailer")] = decodeHeader($header->xmailer);
414 }
415 if ($default_use_mdn) {
416 if ($mdn_user_support) {
417 if ($header->dnt) {
418 if ($message->is_mdnsent) {
419 $env[_("Read receipt")] = _("send");
420 } else {
421 $env[_("Read receipt")] = _("requested");
422 if (!($mailbox == $draft_folder ||
423 $mailbox == $sent_folder ||
424 $message->is_deleted ||
425 $passed_ent_id)) {
426 $mdn_url = $PHP_SELF . '&sendreceipt=1';
427 if ($FirstTimeSee && $javascript_on) {
428 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
429 $script .= '<!--'. "\n";
430 $script .= 'if(window.confirm("' .
431 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
432 '")) { '."\n" .
433 ' sendMDN()'.
434 '}' . "\n";
435 $script .= '// -->'. "\n";
436 $script .= '</script>'. "\n";
437 echo $script;
438 }
439 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
440 _("Send read receipt now") . ']</a>';
441 }
442 }
443 }
444 }
445 }
c615b1da 446
0e02d604 447 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
448 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
d9c1dccc 449 foreach ($env as $key => $val) {
450 if ($val) {
451 $s .= '<TR>';
452 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
453 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
454 $s .= '</TR>';
455 }
456 }
feb5ec1b 457 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
458 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
d0a2476a 459 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
460 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
d9c1dccc 461 echo $s;
462 do_hook("read_body_header");
463 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
464 echo '</TABLE>';
feb5ec1b 465 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
466 echo '</TABLE>';
d9c1dccc 467}
c615b1da 468
7172cad7 469function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
d9c1dccc 470 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
471 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
472 $enable_forward_as_attachment;
c615b1da 473
d9c1dccc 474 $topbar_delimiter = '&nbsp;|&nbsp;';
475 $urlMailbox = urlencode($mailbox);
e55c441a 476 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
477 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
478
d9c1dccc 479 $msgs_url = $base_uri . 'src/';
480 if (isset($where) && isset($what)) {
481 $msgs_url .= 'search.php?where=' . urlencode($where) .
482 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
483 $msgs_str = _("Search results");
484 } else {
485 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
486 $startMessage . '&amp;mailbox=' . $urlMailbox;
487 $msgs_str = _("Message List");
488 }
e55c441a 489 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
490 $s .= $topbar_delimiter;
d9c1dccc 491
492 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
493 '&amp;message=' . $passed_id . '&amp;';
494 if (!(isset($passed_ent_id) && $passed_ent_id)) {
495 if ($where && $what) {
496 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
497 } else {
498 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
499 }
e55c441a 500 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
d9c1dccc 501 }
c615b1da 502
d9c1dccc 503 $comp_uri = $base_uri . 'src/compose.php' .
504 '?passed_id=' . $passed_id .
505 '&amp;mailbox=' . $urlMailbox .
506 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
2ffa3f57 507
d9c1dccc 508 if ($compose_new_win == '1') {
509 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
510 $link_close = '\')">';
511 } else {
512 $link_open = '<a href="';
513 $link_close = '">';
514 }
515 if (($mailbox == $draft_folder) && ($save_as_draft)) {
516 $comp_alt_uri = $comp_uri . '&amp;action=draft';
517 $comp_alt_string = _("Resume Draft");
518 } else if ($mailbox == $sent_folder) {
519 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
520 $comp_alt_string = _("Edit Message as New");
521 }
522 if (isset($comp_alt_uri)) {
e55c441a 523 $s .= $topbar_delimiter;
524 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
d9c1dccc 525 }
2ffa3f57 526
e55c441a 527 $s .= '</small></td><td align="center" width="33%"><small>';
528
d9c1dccc 529 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
530 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
531 $next = findNextMessage($passed_id);
532 if ($prev != -1) {
533 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
534 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
535 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
e55c441a 536 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
d9c1dccc 537 } else {
e55c441a 538 $s .= _("Previous");
d9c1dccc 539 }
e55c441a 540 $s .= $topbar_delimiter;
d9c1dccc 541 if ($next != -1) {
542 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
543 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
544 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
e55c441a 545 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
d9c1dccc 546 } else {
e55c441a 547 $s .= _("Next");
d9c1dccc 548 }
549 } else if (isset($passed_ent_id) && $passed_ent_id) {
550 /* code for navigating through attached message/rfc822 messages */
551 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
e55c441a 552 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
70bdc740 553 $entities = array();
554 $entity_count = array();
555 $c = 0;
f2f03410 556
70bdc740 557 foreach($message->parent->entities as $ent) {
f2f03410 558 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
559 $c++;
560 $entity_count[$c] = $ent->entity_id;
561 $entities[$ent->entity_id] = $c;
562 }
70bdc740 563 }
564 $prev_link = _("Previous");
565 $next_link = _("Next");
566 if($entities[$passed_ent_id] > 1) {
567 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
568 $prev_link = '<a href="'
569 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
570 . '">' . $prev_link . '</a>';
571 }
572 if($entities[$passed_ent_id] < $c) {
573 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
574 $next_link = '<a href="'
575 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
576 . '">' . $next_link . '</a>';
577 }
e55c441a 578 $s .= $topbar_delimiter . $prev_link;
d9c1dccc 579 $par_ent_id = $message->parent->entity_id;
580 if ($par_ent_id) {
581 $par_ent_id = substr($par_ent_id,0,-2);
e55c441a 582 $s .= $topbar_delimiter;
d9c1dccc 583 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
e55c441a 584 $s .= '<a href="'.$url.'">'._("Up").'</a>';
d9c1dccc 585 }
e55c441a 586 $s .= $topbar_delimiter . $next_link;
d9c1dccc 587 }
c615b1da 588
e55c441a 589 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
d9c1dccc 590 $comp_action_uri = $comp_uri . '&amp;action=forward';
e55c441a 591 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
592 $s .= $topbar_delimiter;
c615b1da 593
d9c1dccc 594 if ($enable_forward_as_attachment) {
595 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
e55c441a 596 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
597 $s .= $topbar_delimiter;
d9c1dccc 598 }
a128c967 599
d9c1dccc 600 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
e55c441a 601 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
602 $s .= $topbar_delimiter;
d9c1dccc 603
604 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
e55c441a 605 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
606 $s .= '</small></td></tr></table>';
d9c1dccc 607 do_hook("read_body_menu_top");
e55c441a 608 echo $s;
d9c1dccc 609 do_hook("read_body_menu_bottom");
c615b1da 610}
611
612function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
fe369c70 613 global $base_uri;
614
d9c1dccc 615 $urlMailbox = urlencode($mailbox);
fe369c70 616 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
d9c1dccc 617
618 $s = "<TR>\n" .
619 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
620 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
621 '<a href="'.$url.'">'._("View Full Header").'</a>';
622
623 /* Output the printer friendly link if we are in subtle mode. */
624 $s .= '&nbsp;|&nbsp;' .
625 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
626 echo $s;
627 do_hook("read_body_header_right");
628 $s = "</SMALL></TD>\n" .
629 "</TR>\n";
630 echo $s;
a128c967 631
4d0cd98b 632}
633
6206f6c4 634/***************************/
2ffa3f57 635/* Main of read_body.php */
6206f6c4 636/***************************/
57257333 637
0b97a708 638/* get the globals we may need */
639
640$username = $_SESSION['username'];
641$key = $_COOKIE['key'];
642$onetimepad = $_SESSION['onetimepad'];
643$msgs = $_SESSION['msgs'];
644$base_uri = $_SESSION['base_uri'];
645$delimiter = $_SESSION['delimiter'];
646
647if (isset($_GET['passed_id'])) {
648 $passed_id = $_GET['passed_id'];
649}
650elseif (isset($_POST['passed_id'])) {
651 $passed_id = $_POST['passed_id'];
652}
653
ce274df9 654if (isset($_GET['passed_ent_id'])) {
655 $passed_ent_id = $_GET['passed_ent_id'];
656}
657elseif (isset($_POST['passed_ent_id'])) {
658 $passed_ent_id = $_POST['passed_ent_id'];
659}
660
0b97a708 661if (isset($_GET['sendreceipt'])) {
662 $sendreceipt = $_GET['sendreceipt'];
663}
664
665if (isset($_GET['sort'])) {
666 $sort = $_GET['sort'];
667}
668elseif (isset($_POST['sort'])) {
669 $sort = $_POST['sort'];
670}
671if (isset($_GET['startMessage'])) {
672 $startMessage = $_GET['startMessage'];
673}
674elseif (isset($_POST['startMessage'])) {
675 $startMessage = $_POST['startMessage'];
676}
677if (isset($_GET['show_more'])) {
678 $show_more = $_GET['show_more'];
679}
1b9f3c04 680if (isset($_GET['show_more_cc'])) {
681 $show_more_cc = $_GET['show_more_cc'];
682}
683if (isset($_GET['show_more_bcc'])) {
684 $show_more_bcc = $_GET['show_more_bcc'];
0b97a708 685}
686if (isset($_GET['mailbox'])) {
687 $mailbox = $_GET['mailbox'];
688}
689elseif (isset($_POST['mailbox'])) {
690 $mailbox = $_POST['mailbox'];
691}
692if (isset($_GET['where'])) {
693 $where = $_GET['where'];
694}
695if (isset($_GET['what'])) {
696 $what = $_GET['what'];
697}
698if (isset($_GET['view_hdr'])) {
699 $view_hdr = $_GET['view_hdr'];
700}
701if (isset($_SESSION['server_sort_array'])) {
702 $server_sort_array = $_SESSION['server_sort_array'];
703}
704if (isset($_SESSION['msgs'])) {
705 $msgs = $_SESSION['msgs'];
706}
707if (isset($_SESSION['msort'])) {
708 $msort = $_SESSION['msort'];
709}
710if (isset($_POST['move_id'])) {
711 $move_id = $_POST['move_id'];
712}
713if (isset($_SESSION['lastTargetMailbox'])) {
714 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
715}
ce274df9 716if (isset($_SESSION['messages'])) {
717 $messages = $_SESSION['messages'];
718} else {
719 $messages = array();
720}
0b97a708 721
a07cd1a4 722
ce274df9 723
724/* end of get globals */
38c944cc 725global $uid_support, $sqimap_capabilities;
726
6a108031 727if (isset($mailbox)) {
4366bea4 728 $mailbox = urldecode( $mailbox );
729}
38c944cc 730
6206f6c4 731$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38c944cc 732$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
733
38c944cc 734
735/**
736 * $message contains all information about the message
737 * including header and body
738 */
37d2a6ee 739
740$uidvalidity = $mbx_response['UIDVALIDITY'];
741
742if (!isset($messages[$uidvalidity])) {
743 $messages[$uidvalidity] = array();
744}
5200c026 745if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
746 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 747 $FirstTimeSee = !$message->is_seen;
748 $message->is_seen = true;
5200c026 749 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 750} else {
fc224f68 751// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
752 $message = $messages[$uidvalidity][$passed_id];
753 $FirstTimeSee = !$message->is_seen;
5200c026 754}
af568a82 755
dd628162 756if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 757 $message = $message->getEntity($passed_ent_id);
ff9d4297 758 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
759 $message = $message->parent;
760 }
141a16b2 761 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 762 $rfc822_header = new Rfc822Header();
141a16b2 763 $rfc822_header->parseHeader($read);
764 $message->rfc822_header = $rfc822_header;
c615b1da 765} else {
766 $passed_ent_id = 0;
38c944cc 767}
5200c026 768$header = $message->header;
57257333 769
6c31f818 770do_hook('html_top');
57257333 771
6206f6c4 772/****************************************/
773/* Block for handling incoming url vars */
774/****************************************/
5200c026 775
5200c026 776if (isset($sendreceipt)) {
777 if ( !$message->is_mdnsent ) {
778 if (isset($identity) ) {
779 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
780 } else {
781 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
782 }
783
784 $final_recipient = trim($final_recipient);
785 if ($final_recipient == '' ) {
786 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
787 }
af568a82 788 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 789 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 790 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 791 $message->is_mdnsent = true;
6a108031 792 $messages[$uidvalidity][$passed_id]=$message;
5200c026 793 }
794 ClearAttachments();
795 }
796}
6206f6c4 797/***********************************************/
798/* End of block for handling incoming url vars */
799/***********************************************/
800
38c944cc 801$msgs[$passed_id]['FLAG_SEEN'] = true;
38c944cc 802
5200c026 803$messagebody = '';
c4ad259b 804do_hook('read_body_top');
805if ($show_html_default == 1) {
806 $ent_ar = $message->findDisplayEntity(array());
807} else {
808 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
809}
a128c967 810$cnt = count($ent_ar);
811for ($i = 0; $i < $cnt; $i++) {
6a108031 812 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 813 if ($i != $cnt-1) {
814 $messagebody .= '<hr noshade size=1>';
815 }
38c944cc 816}
e55c441a 817
c615b1da 818displayPageHeader($color, $mailbox);
7172cad7 819formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 820formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
6206f6c4 821echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
822echo ' <tr><td>';
823echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 824echo ' <tr><td>';
6206f6c4 825echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
826echo ' <tr bgcolor="'.$color[4].'"><td>';
4b214684 827echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
ce810ea7 828echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
829 . '</td>';
6206f6c4 830echo ' </table>';
831echo ' </td></tr>';
832echo ' </table></td></tr>';
2ffa3f57 833echo ' </table>';
834echo ' </td></tr>';
a128c967 835
d0a2476a 836echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
837 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
838
a128c967 839$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
840if ($attachmentsdisplay) {
2ffa3f57 841 echo ' <tr><td>';
6206f6c4 842 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 843 echo ' <tr><td>';
d0a2476a 844 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
6206f6c4 845 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
846 echo ' <b>' . _("Attachments") . ':</b>';
847 echo ' </td></tr>';
848 echo ' <tr><td>';
849 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
850 echo $attachmentsdisplay;
851 echo ' </td></tr></table>';
e55c441a 852 echo ' </table></td></tr>';
2ffa3f57 853 echo ' </table></td></tr>';
6206f6c4 854 echo ' </table>';
855 echo ' </td></tr>';
a128c967 856}
c615b1da 857echo '</table>';
a07cd1a4 858
859/* show attached images inline -- if pref'fed so */
5be9f195 860if (($attachment_common_show_images) &&
a07cd1a4 861 is_array($attachment_common_show_images_list)) {
862 foreach ($attachment_common_show_images_list as $img) {
ce274df9 863 $imgurl = SM_PATH . 'src/download.php' .
57257333 864 '?' .
cd7b8833 865 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 866 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 867 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 868 '&amp;absolute_dl=true';
5be9f195 869
b5058e9e 870 echo html_tag( 'table', "\n" .
d9c1dccc 871 html_tag( 'tr', "\n" .
872 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
873 )
874 ) ,
b5058e9e 875 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 876 }
a07cd1a4 877}
878
c615b1da 879do_hook('read_body_bottom');
880do_hook('html_bottom');
a07cd1a4 881sqimap_logout($imapConnection);
ce274df9 882/* sessions are written at the end of the script. it's better to register
883 them at the end so we avoid double session_register calls */
884sqsession_register($messages,'messages');
e55c441a 885
a07cd1a4 886?>
c615b1da 887</body>
888</html>