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