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