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