We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * read_body.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 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,
48dc9174 493 $data_dir, $username, $delete_prev_next_display;
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;
abafb676 555 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
1e150c97 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 if ( $uid_support && $delete_prev_next_display == 1 ) {
45c1ed84 581 $del_prev_link = _("Delete & Prev");
1e150c97 582 if ($prev >= 0) {
583 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
584 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
585 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
586 '&amp;delete_id='.$passed_id;
45c1ed84 587 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
1e150c97 588 }
589
45c1ed84 590 $del_next_link = _("Delete & Next");
1e150c97 591 if ($next >= 0) {
592 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
593 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
594 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
595 '&amp;delete_id='.$passed_id;
45c1ed84 596 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
1e150c97 597 }
1e150c97 598 }
45c1ed84 599
abafb676 600 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
601 if ( isset($del_prev_link) && isset($del_next_link) )
602 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
1e150c97 603 }
604
605 // Start with Search Results or Message List link.
606 if (isset($where) && isset($what)) {
607 $msgs_url .= 'search.php?where=' . urlencode($where) .
608 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
609 $msgs_str = _("Search Results");
610 } else {
611 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
612 $startMessage . '&amp;mailbox=' . $urlMailbox;
613 $msgs_str = _("Message List");
614 }
615 $nav_row .= $double_delimiter .
abafb676 616 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
1e150c97 617
618 $nav_row .= '</small></td></tr>';
619
620
621 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
622 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
623
624 // If Draft folder - create Resume link
625 if (($mailbox == $draft_folder) && ($save_as_draft)) {
626 $comp_alt_uri = $comp_uri . '&amp;smaction=draft';
627 $comp_alt_string = _("Resume Draft");
628 } else if (handleAsSent($mailbox)) {
629 // If in Sent folder, edit as new
630 $comp_alt_uri = $comp_uri . '&amp;smaction=edit_as_new';
631 $comp_alt_string = _("Edit Message as New");
632 }
633
634 // Show Alt URI for Draft/Sent
635 if (isset($comp_alt_uri)) {
636 $menu_row .= $topbar_delimiter;
637 $menu_row .= makeComposeLink($comp_alt_uri, $comp_alt_string);
638 $menu_row .= $topbar_delimiter;
639 }
640
1e150c97 641 $comp_action_uri = $comp_uri . '&amp;smaction=reply';
1e150c97 642 $menu_row .= makeComposeLink($comp_action_uri, _("Reply"));
643
644 $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
645 $menu_row .= $topbar_delimiter;
646 $menu_row .= makeComposeLink($comp_action_uri, _("Reply All"));
647
c615b1da 648
6f09fb70 649 $comp_action_uri = $comp_uri . '&amp;smaction=forward';
1e150c97 650 $menu_row .= $topbar_delimiter;
651 $menu_row .= makeComposeLink($comp_action_uri, _("Forward"));
c615b1da 652
d9c1dccc 653 if ($enable_forward_as_attachment) {
6f09fb70 654 $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
1e150c97 655 $menu_row .= $topbar_delimiter;
656 $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
d9c1dccc 657 }
a128c967 658
abafb676 659 $delete_link = _("Delete");
660 if (!(isset($passed_ent_id) && $passed_ent_id)) {
661 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
662 '&amp;message=' . $passed_id . '&amp;';
663
664 if ($where && $what) {
665 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
666 } else {
667 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
668 }
669 $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
670 $delete_link .= '&nbsp;(<a href="' . $delete_url.'&amp;bypass_trash=1">'
671 ._("Bypass Trash").'</a>)';
672
673 }
674 $menu_row .= $topbar_delimiter.$delete_link;
675
676
1e150c97 677 // Add top move link
678 $menu_row .= '</small></td><td align="right">';
679 if (!(isset($passed_ent_id) && $passed_ent_id)) {
680 $menu_row .= '<form action="read_body.php?mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage.'&passed_id='.$next.'" method="post">'.
681 '<small><input type="hidden" name="show_more" value="0" />'.
682 '<input type="hidden" name="move_id" value="'.$passed_id.'" />'._("Move to:") .
683 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
684 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
685 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
686 } else {
687 $menu_row .= sqimap_mailbox_option_list($imapConnection);
688 }
689 $menu_row .= '</select> '.
690 '<input type="submit" value="' . _("Move") . '" style="padding: 0px; margin: 0px"/>'.
691 '</small></form>';
692 }
693 $menu_row .= '</td></tr>';
d9c1dccc 694
1e150c97 695 // echo rows, with hooks
d62c4938 696 do_hook('read_body_menu_top');
1e150c97 697 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
698 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
699 echo '</table>'."\n";
d62c4938 700 do_hook('read_body_menu_bottom');
c615b1da 701}
702
703function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
a94c1db1 704 global $base_uri;
fe369c70 705
d9c1dccc 706 $urlMailbox = urlencode($mailbox);
e95c04ec 707 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER);
708 $url = $base_uri.'src/view_header.php?'.$query_string;
d9c1dccc 709
a94c1db1 710 $s = "<TR>\n" .
98fb28fd 711 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
712 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
d9c1dccc 713 '<a href="'.$url.'">'._("View Full Header").'</a>';
714
715 /* Output the printer friendly link if we are in subtle mode. */
716 $s .= '&nbsp;|&nbsp;' .
1e150c97 717 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
d9c1dccc 718 echo $s;
719 do_hook("read_body_header_right");
720 $s = "</SMALL></TD>\n" .
721 "</TR>\n";
722 echo $s;
a128c967 723
4d0cd98b 724}
725
6206f6c4 726/***************************/
2ffa3f57 727/* Main of read_body.php */
6206f6c4 728/***************************/
57257333 729
0b97a708 730/* get the globals we may need */
731
1e12d1ff 732sqgetGlobalVar('key', $key, SQ_COOKIE);
e95c04ec 733sqgetGlobalVar('username', $username, SQ_SESSION);
734sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
e95c04ec 735sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
1e12d1ff 736sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
737
e95c04ec 738sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
739sqgetGlobalVar('msort', $msort, SQ_SESSION);
740sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
741sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
742if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
743 $messages = array();
ce274df9 744}
745
e95c04ec 746/** GET VARS */
747sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
748sqgetGlobalVar('where', $where, SQ_GET);
749sqgetGlobalVar('what', $what, SQ_GET);
750if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
751 $show_more = (int) $temp;
1b9f3c04 752}
e95c04ec 753if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
754 $show_more_cc = (int) $temp;
0b97a708 755}
e95c04ec 756if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
757 $show_more_bcc = (int) $temp;
0b97a708 758}
e95c04ec 759if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
760 $view_hdr = (int) $temp;
0b97a708 761}
e95c04ec 762
e95c04ec 763/** GET/POST VARS */
764sqgetGlobalVar('passed_ent_id', $passed_ent_id);
765sqgetGlobalVar('mailbox', $mailbox);
766
767if ( sqgetGlobalVar('passed_id', $temp) ) {
768 $passed_id = (int) $temp;
0b97a708 769}
e95c04ec 770if ( sqgetGlobalVar('sort', $temp) ) {
771 $sort = (int) $temp;
0b97a708 772}
e95c04ec 773if ( sqgetGlobalVar('startMessage', $temp) ) {
774 $startMessage = (int) $temp;
ce274df9 775}
0b97a708 776
ce274df9 777/* end of get globals */
653ff1e6 778global $uid_support, $sqimap_capabilities, $lastTargetMailbox;
38c944cc 779
6206f6c4 780$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
9f42bfc8 781$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
38c944cc 782
1e150c97 783/**
784 * Process Delete from delete-move-next
785 * but only if delete_id was set
786 */
787if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
653ff1e6 788 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
1e150c97 789
653ff1e6 790 sqimap_mailbox_expunge_dmn($delete_id);
1e150c97 791}
792
793/**
794 * Process Move from delete-move-next
795 * but only if move_id and target_mailbox were set
796 */
797if ( sqgetGlobalVar('move_id', $move_id, SQ_POST) &&
798 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST) ) {
799 // Move message
653ff1e6 800 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
801 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
1e150c97 802
653ff1e6 803 sqimap_mailbox_expunge_dmn($move_id);
1e150c97 804
653ff1e6 805 if ($targetMailbox != $lastTargetMailbox) {
806 $lastTargetMailbox = $targetMailbox;
807 sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
808 }
1e150c97 809}
810
38c944cc 811
812/**
813 * $message contains all information about the message
814 * including header and body
815 */
37d2a6ee 816
817$uidvalidity = $mbx_response['UIDVALIDITY'];
9f42bfc8 818
37d2a6ee 819if (!isset($messages[$uidvalidity])) {
820 $messages[$uidvalidity] = array();
9f42bfc8 821}
5200c026 822if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
823 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 824 $FirstTimeSee = !$message->is_seen;
825 $message->is_seen = true;
5200c026 826 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 827} else {
fc224f68 828// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
829 $message = $messages[$uidvalidity][$passed_id];
830 $FirstTimeSee = !$message->is_seen;
5200c026 831}
af568a82 832
dd628162 833if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 834 $message = $message->getEntity($passed_ent_id);
ff9d4297 835 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
836 $message = $message->parent;
837 }
141a16b2 838 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 839 $rfc822_header = new Rfc822Header();
141a16b2 840 $rfc822_header->parseHeader($read);
841 $message->rfc822_header = $rfc822_header;
c615b1da 842} else {
843 $passed_ent_id = 0;
38c944cc 844}
5200c026 845$header = $message->header;
57257333 846
6c31f818 847do_hook('html_top');
57257333 848
6206f6c4 849/****************************************/
850/* Block for handling incoming url vars */
851/****************************************/
5200c026 852
5200c026 853if (isset($sendreceipt)) {
854 if ( !$message->is_mdnsent ) {
27a1d10a 855 $final_recipient = '';
856 if ((isset($identity)) && ($identity != 0)) //Main identity
857 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
858 if ($final_recipient == '' )
859 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
af568a82 860 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 861 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 862 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 863 $message->is_mdnsent = true;
6a108031 864 $messages[$uidvalidity][$passed_id]=$message;
5200c026 865 }
866 ClearAttachments();
867 }
868}
6206f6c4 869/***********************************************/
870/* End of block for handling incoming url vars */
871/***********************************************/
872
38c944cc 873$msgs[$passed_id]['FLAG_SEEN'] = true;
9f42bfc8 874
875$messagebody = '';
c4ad259b 876do_hook('read_body_top');
877if ($show_html_default == 1) {
878 $ent_ar = $message->findDisplayEntity(array());
879} else {
880 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
881}
a128c967 882$cnt = count($ent_ar);
883for ($i = 0; $i < $cnt; $i++) {
6a108031 884 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 885 if ($i != $cnt-1) {
886 $messagebody .= '<hr noshade size=1>';
887 }
38c944cc 888}
e55c441a 889
c615b1da 890displayPageHeader($color, $mailbox);
7172cad7 891formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 892formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
a94c1db1 893echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
6206f6c4 894echo ' <tr><td>';
a94c1db1 895echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 896echo ' <tr><td>';
a94c1db1 897echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
6206f6c4 898echo ' <tr bgcolor="'.$color[4].'"><td>';
98fb28fd 899// echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
900echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
ce810ea7 901echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
6c7b5d8c 902 . '</tr>';
6206f6c4 903echo ' </table>';
904echo ' </td></tr>';
905echo ' </table></td></tr>';
2ffa3f57 906echo ' </table>';
907echo ' </td></tr>';
a128c967 908
d0a2476a 909echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
6c7b5d8c 910 $color[4].'"></TD></TR>'."\n";
d0a2476a 911
a128c967 912$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
913if ($attachmentsdisplay) {
8acd2fb5 914 echo ' </table>';
6206f6c4 915 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 916 echo ' <tr><td>';
d0a2476a 917 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
98fb28fd 918 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
6206f6c4 919 echo ' <b>' . _("Attachments") . ':</b>';
920 echo ' </td></tr>';
921 echo ' <tr><td>';
922 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
923 echo $attachmentsdisplay;
924 echo ' </td></tr></table>';
6c7b5d8c 925 echo ' </td></tr></table>';
6206f6c4 926 echo ' </td></tr>';
6c7b5d8c 927 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
928 $color[4].'"></TD></TR>';
a128c967 929}
c615b1da 930echo '</table>';
a07cd1a4 931
932/* show attached images inline -- if pref'fed so */
5be9f195 933if (($attachment_common_show_images) &&
a07cd1a4 934 is_array($attachment_common_show_images_list)) {
935 foreach ($attachment_common_show_images_list as $img) {
ce274df9 936 $imgurl = SM_PATH . 'src/download.php' .
57257333 937 '?' .
cd7b8833 938 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 939 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 940 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 941 '&amp;absolute_dl=true';
5be9f195 942
b5058e9e 943 echo html_tag( 'table', "\n" .
d9c1dccc 944 html_tag( 'tr', "\n" .
945 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
946 )
947 ) ,
b5058e9e 948 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 949 }
a07cd1a4 950}
951
4267d5de 952formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
1e150c97 953
c615b1da 954do_hook('read_body_bottom');
955do_hook('html_bottom');
a07cd1a4 956sqimap_logout($imapConnection);
ce274df9 957/* sessions are written at the end of the script. it's better to register
958 them at the end so we avoid double session_register calls */
959sqsession_register($messages,'messages');
e55c441a 960
dcc1cc82 961?>
962</body>
963</html>