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