A terrible pile of things done to the code. Did a little bit of SM_PATH
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * read_body.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 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$
a07cd1a4 13 */
35586184 14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/mime.php');
22require_once(SM_PATH . 'functions/date.php');
23require_once(SM_PATH . 'functions/url_parser.php');
24require_once(SM_PATH . 'functions/html.php');
38c944cc 25
a07cd1a4 26/**
1fca12b5 27 * Given an IMAP message id number, this will look it up in the cached
28 * and sorted msgs array and return the index. Used for finding the next
29 * and previous messages.
30 *
31 * @return the index of the next valid message from the array
32 */
c615b1da 33function findNextMessage($passed_id) {
34 global $msort, $msgs, $sort,
cf710efe 35 $thread_sort_messages, $allow_server_sort,
60a3e687 36 $server_sort_array;
2728fa19 37 if (!is_array($server_sort_array)) {
38 $thread_sort_messages = 0;
794d59c0 39 $allow_server_sort = FALSE;
2728fa19 40 }
a07cd1a4 41 $result = -1;
c615b1da 42 if ($thread_sort_messages || $allow_server_sort) {
60a3e687 43 reset($server_sort_array);
44 while(list($key, $value) = each ($server_sort_array)) {
c615b1da 45 if ($passed_id == $value) {
1fca12b5 46 if ($key == (count($server_sort_array) - 1)) {
60a3e687 47 $result = -1;
48 break;
49 }
1fca12b5 50 $result = $server_sort_array[$key + 1];
60a3e687 51 break;
789b4d79 52 }
60a3e687 53 }
6206f6c4 54 } else if ($sort == 6 && !$allow_server_sort &&
c615b1da 55 !$thread_sort_messages ) {
56 if ($passed_id != 1) {
57 $result = $passed_id - 1;
a07cd1a4 58 }
6206f6c4 59 } else if (!$allow_server_sort && !$thread_sort_messages ) {
75ef78d8 60 if (!is_array($msort)) {
61 return -1;
62 }
a07cd1a4 63 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
c615b1da 64 if ($passed_id == $msgs[$key]['ID']) {
a07cd1a4 65 next($msort);
66 $key = key($msort);
1fca12b5 67 if (isset($key)){
a07cd1a4 68 $result = $msgs[$key]['ID'];
69 break;
1fca12b5 70 }
10f0ce72 71 }
72 }
10f0ce72 73 }
a07cd1a4 74 return ($result);
75}
76
a07cd1a4 77/** returns the index of the previous message from the array. */
c615b1da 78function findPreviousMessage($numMessages, $passed_id) {
79 global $msort, $sort, $msgs,
80 $thread_sort_messages,
60a3e687 81 $allow_server_sort, $server_sort_array;
a07cd1a4 82 $result = -1;
2728fa19 83 if (!is_array($server_sort_array)) {
84 $thread_sort_messages = 0;
794d59c0 85 $allow_server_sort = FALSE;
2728fa19 86 }
c615b1da 87 if ($thread_sort_messages || $allow_server_sort ) {
60a3e687 88 reset($server_sort_array);
89 while(list($key, $value) = each ($server_sort_array)) {
c615b1da 90 if ($passed_id == $value) {
60a3e687 91 if ($key == 0) {
92 $result = -1;
93 break;
94 }
95 $result = $server_sort_array[$key -1];
96 break;
789b4d79 97 }
60a3e687 98 }
6206f6c4 99 } else if ($sort == 6 && !$allow_server_sort &&
c615b1da 100 !$thread_sort_messages) {
101 if ($passed_id != $numMessages) {
102 $result = $passed_id + 1;
a07cd1a4 103 }
6206f6c4 104 } else if (!$thread_sort_messages && !$allow_server_sort) {
1fca12b5 105 if (!is_array($msort)) {
75ef78d8 106 return -1;
1fca12b5 107 }
a07cd1a4 108 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
c615b1da 109 if ($passed_id == $msgs[$key]['ID']) {
a07cd1a4 110 prev($msort);
111 $key = key($msort);
112 if (isset($key)) {
6206f6c4 113 //echo $msort[$key]; /* Why again were we echoing here? */
a07cd1a4 114 $result = $msgs[$key]['ID'];
115 break;
10f0ce72 116 }
117 }
10f0ce72 118 }
a07cd1a4 119 }
120 return ($result);
121}
10f0ce72 122
a07cd1a4 123/**
1fca12b5 124 * Displays a link to a page where the message is displayed more
125 * "printer friendly".
126 */
c615b1da 127function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
128 global $javascript_on;
a07cd1a4 129
c615b1da 130 $params = '?passed_ent_id=' . $passed_ent_id .
1fca12b5 131 '&mailbox=' . urlencode($mailbox) .
132 '&passed_id=' . $passed_id;
10f0ce72 133
a07cd1a4 134 $print_text = _("View Printable Version");
10f0ce72 135
c615b1da 136 $result = '';
a07cd1a4 137 /* Output the link. */
138 if ($javascript_on) {
3d570ba0 139 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
a07cd1a4 140 '<!--' . "\n" .
141 " function printFormat() {\n" .
142 ' window.open("../src/printer_friendly_main.php' .
c615b1da 143 $params . '","Print","width=800,height=600");' . "\n".
a07cd1a4 144 " }\n" .
145 "// -->\n" .
146 "</script>\n" .
b5058e9e 147 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
a07cd1a4 148 } else {
b5058e9e 149 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
150 "$params\">$print_text</a>\n";
a07cd1a4 151 }
a07cd1a4 152 return ($result);
153}
154
57257333 155function ServerMDNSupport( $read ) {
f69feefe 156 /* escaping $ doesn't work -> \x36 */
157 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
57257333 158 return ( $ret );
159}
160
fc224f68 161function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
c615b1da 162 global $username, $attachment_dir, $SERVER_NAME,
fc224f68 163 $version, $attachments, $squirrelmail_language, $default_charset,
164 $languages, $useSendmail, $domain, $sent_folder,
165 $popuser, $data_dir, $username;
57257333 166
38bca81c 167 $header = $message->rfc822_header;
57257333 168 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169
fc224f68 170 $rfc822_header = new Rfc822Header();
171 $content_type = new ContentType('multipart/report');
172 $content_type->properties['report-type']='disposition-notification';
173
174 set_my_charset();
175 if ($default_charset) {
176 $content_type->properties['charset']=$default_charset;
177 }
178 $rfc822_header->content_type = $content_type;
179 $rfc822_header->to[] = $header->dnt;
180 $rfc822_header->subject = _("Read:") . ' ' . $header->subject;
181
182
183 $reply_to = '';
184 if (isset($identity) && $identity != 'default') {
185 $from_mail = getPref($data_dir, $username,
186 'email_address' . $identity);
187 $full_name = getPref($data_dir, $username,
188 'full_name' . $identity);
189 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
190 $reply_to = getPref($data_dir, $username,
191 'reply_to' . $identity);
192 } else {
193 $from_mail = getPref($data_dir, $username, 'email_address');
194 $full_name = getPref($data_dir, $username, 'full_name');
195 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
196 $reply_to = getPref($data_dir, $username,'reply_to');
197 }
198 if (!$from_addr) {
199 $from_addr = "$popuser@$domain";
200 $from_mail = $from_addr;
201 }
202 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
203 if ($reply_to) {
204 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
205 }
206
57257333 207 // part 1 (RFC2298)
57257333 208 $senton = getLongDateString( $header->date );
209 $to_array = $header->to;
210 $to = '';
211 foreach ($to_array as $line) {
af568a82 212 $to .= ' '.$line->getAddress();
57257333 213 }
57257333 214 $now = getLongDateString( time() );
78db1583 215 set_my_charset();
46bb8da8 216 $body = _("Your message") . "\r\n\r\n" .
217 "\t" . _("To:") . ' ' . $to . "\r\n" .
fc224f68 218 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
46bb8da8 219 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
220 "\r\n" .
221 sprintf( _("Was displayed on %s"), $now );
f69feefe 222
fc224f68 223 $special_encoding = '';
224 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
225 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 226 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
fc224f68 227 if (strtolower($default_charset) == 'iso-2022-jp') {
228 if (mb_detect_encoding($body) == 'ASCII') {
229 $special_encoding = '8bit';
230 } else {
231 $body = mb_convert_encoding($body, 'JIS');
232 $special_encoding = '7bit';
233 }
234 }
6fbd125b 235 }
fc224f68 236 $part1 = new Message();
237 $part1->setBody($body);
238 $mime_header = new MessageHeader;
239 $mime_header->type0 = 'text';
240 $mime_header->type1 = 'plain';
241 if ($special_encoding) {
242 $mime_header->encoding = $special_encoding;
243 } else {
244 $mime_header->encoding = 'us-ascii';
245 }
246 if ($default_charset) {
247 $mime_header->parameters['charset'] = $default_charset;
248 }
249 $part1->mime_header = $mime_header;
250
57257333 251 // part2 (RFC2298)
57257333 252 $original_recipient = $to;
253 $original_message_id = $header->message_id;
254
fc224f68 255 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
57257333 256 if ($original_recipient != '') {
fc224f68 257 $report .= "Original-Recipient : $original_recipient\r\n";
57257333 258 }
259 $final_recipient = $sender;
fc224f68 260 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
57257333 261 "Original-Message-ID : $original_message_id\r\n" .
262 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
263
fc224f68 264 $part2 = new Message();
265 $part2->setBody($report);
266 $mime_header = new MessageHeader;
267 $mime_header->type0 = 'message';
268 $mime_header->type1 = 'disposition-notification';
269 $mime_header->encoding = 'us-ascii';
270 $part2->mime_header = $mime_header;
271
272 $composeMessage = new Message();
273 $composeMessage->rfc822_header = $rfc822_header;
274 $composeMessage->addEntity($part1);
275 $composeMessage->addEntity($part2);
276
277
278 if (!$useSendmail) {
86725763 279 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
fc224f68 280 $deliver = new Deliver_SMTP();
281 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
282 if ($use_authenticated_smtp) {
283 global $key, $onetimepad;
284 $user = $username;
285 $pass = OneTimePadDecrypt($key, $onetimepad);
286 } else {
287 $user = '';
288 $pass = '';
289 }
290 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
291 $stream = $deliver->initStream($composeMessage,$domain,0,
292 $smtpServerAddress, $smtpPort, $authPop);
293 } else {
86725763 294 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
fc224f68 295 global $sendmail_path;
296 $deliver = new Deliver_SendMail();
297 $stream = $deliver->initStream($composeMessage,$sendmail_path);
298 }
299 $succes = false;
300 if ($stream) {
301 $length = $deliver->mail($composeMessage, $stream);
302 $succes = $deliver->finalizeStream($stream);
303 }
304 if (!$succes) {
305 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
86725763 306 require_once(SM_PATH . 'functions/display_messages.php');
fc224f68 307 plain_error_message($msg, $color);
308 } else {
309 unset ($deliver);
310 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
311 sqimap_append ($imapConnection, $sent_folder, $length);
86725763 312 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
fc224f68 313 $imap_deliver = new Deliver_IMAP();
314 $imap_deliver->mail($composeMessage, $imapConnection);
315 sqimap_append_done ($imapConnection);
316 unset ($imap_deliver);
317 }
318 }
319 return $succes;
57257333 320}
321
322
c615b1da 323function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
0892e427 324 $sg = $set?'+':'-';
325 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 326 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 327 $readmessage, $uid_support);
57257333 328}
329
330function ClearAttachments() {
331 global $username, $attachments, $attachment_dir;
332
333 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
334
aa866a40 335 $rem_attachments = array();
57257333 336 foreach ($attachments as $info) {
b2c19764 337 if ($info['session'] == -1) {
aa866a40 338 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
339 if (file_exists($attached_file)) {
340 unlink($attached_file);
341 }
342 } else {
343 $rem_attachments[] = $info;
344 }
345 }
68c3b52a 346 $attachments = $rem_attachments;
57257333 347}
348
4d0cd98b 349function formatRecipientString($recipients, $item ) {
c615b1da 350 global $show_more_cc, $show_more, $show_more_bcc,
38c944cc 351 $PHP_SELF;
4d0cd98b 352
38c944cc 353 if ((is_array($recipients)) && (isset($recipients[0]))) {
1fca12b5 354 $string = '';
4d0cd98b 355 $ary = $recipients;
38c944cc 356 $show = false;
357
358 if ($item == 'to') {
359 if ($show_more) {
360 $show = true;
361 $url = set_url_var($PHP_SELF, 'show_more',0);
362 } else {
363 $url = set_url_var($PHP_SELF, 'show_more',1);
364 }
365 } else if ($item == 'cc') {
366 if ($show_more_cc) {
367 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
368 $show = true;
369 } else {
370 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
371 }
372 } else if ($item == 'bcc') {
373 if ($show_more_bcc) {
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
375 $show = true;
376 } else {
377 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
378 }
379 }
4d0cd98b 380
38c944cc 381 $cnt = count($ary);
c615b1da 382 $i = 0;
38c944cc 383 while ($i < $cnt) {
c615b1da 384 $ary[$i] = htmlspecialchars($ary[$i]->getAddress());
4d0cd98b 385 if ($string) {
38c944cc 386 $string .= '<BR>'.$ary[$i];
4d0cd98b 387 } else {
38c944cc 388 $string = $ary[$i];
389 if ($cnt>1) {
390 $string .= '&nbsp;(<A HREF="'.$url;
391 if ($show) {
c615b1da 392 $string .= '">'._("less").'</A>)';
38c944cc 393 } else {
c615b1da 394 $string .= '">'._("more").'</A>)';
38c944cc 395 break;
396 }
397 }
4d0cd98b 398 }
4d0cd98b 399 $i++;
1fca12b5 400 }
4d0cd98b 401 }
402 else {
1fca12b5 403 $string = '';
4d0cd98b 404 }
c615b1da 405 return $string;
406}
407
af568a82 408function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
409 $color, $FirstTimeSee) {
2ffa3f57 410 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
411 $default_use_priority, $show_xmailer_default,
412 $mdn_user_support, $PHP_SELF, $javascript_on;
38bca81c 413
414 $header = $message->rfc822_header;
c615b1da 415 $env = array();
83be314a 416 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
38bca81c 417 $from_name = $header->getAddr_s('from');
418 if (!$from_name) {
419 $from_name = $header->getAddr_s('sender');
420 if (!$from_name) {
421 $from_name = _("Unknown sender");
422 }
c615b1da 423 }
83be314a 424 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
88d3af4f 425 $env[_("Date")] = getLongDateString($header->date);
c615b1da 426 $env[_("To")] = formatRecipientString($header->to, "to");
427 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
428 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
429 if ($default_use_priority) {
430 $env[_("Priority")] = getPriorityStr($header->priority);
431 }
432 if ($show_xmailer_default) {
83be314a 433 $env[_("Mailer")] = decodeHeader($header->xmailer);
c615b1da 434 }
435 if ($default_use_mdn) {
436 if ($mdn_user_support) {
437 if ($header->dnt) {
438 if ($message->is_mdnsent) {
439 $env[_("Read receipt")] = _("send");
440 } else {
441 if ( !($mailbox == $draft_folder ||
27ff41bd 442 $mailbox == $sent_folder ||
443 $message->is_deleted ||
444 $passed_ent_id)) {
c615b1da 445 $mdn_url = $PHP_SELF . '&sendreceipt=1';
c615b1da 446 if ($FirstTimeSee && $javascript_on) {
447 $script = '<script language="JavaScript" type="text/javascript">' ."\n";
448 $script .= '<!--'. "\n";
449 $script .= 'if(window.confirm("' .
450 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
451 '")) { '."\n" .
452 ' sendMDN()'.
453 '}' . "\n";
454 $script .= '// -->'. "\n";
455 $script .= '</script>'. "\n";
456 echo $script;
457 }
458 $env[_("Read receipt")] = _("requested") .
459 '&nbsp;<a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>';
460 } else {
461 $env[_("Read receipt")] = _("requested");
462 }
463 }
464 }
465 }
466 }
467
9feb4369 468 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
469 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
c615b1da 470 foreach ($env as $key => $val) {
471 if ($val) {
9feb4369 472 $s .= '<TR>';
9a231083 473 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
474 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
9feb4369 475 $s .= '</TR>';
c615b1da 476 }
477 }
7172cad7 478 echo $s;
2ffa3f57 479 do_hook("read_body_header");
9feb4369 480 formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color);
481 echo '</table>';
c615b1da 482}
483
7172cad7 484function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
c615b1da 485 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
6206f6c4 486 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
487 $enable_forward_as_attachment;
c615b1da 488
489 $topbar_delimiter = '&nbsp;|&nbsp;';
f099d05f 490 $urlMailbox = urlencode($mailbox);
c615b1da 491 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
492 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
493
494 $msgs_url = $base_uri . 'src/';
495 if (isset($where) && isset($what)) {
d215ca7d 496 $msgs_url .= 'search.php?where='.urlencode($where).
c615b1da 497 '&amp;what='.urlencode($what).'&amp;mailbox='.$urlMailbox;
2ffa3f57 498 $msgs_str = _("Search results");
c615b1da 499 } else {
500 $msgs_url .= 'right_main.php?sort='.$sort.'&amp;startMessage='.
501 $startMessage.'&amp;mailbox='.$urlMailbox;
d215ca7d 502 $msgs_str = _("Message List");
c615b1da 503 }
d215ca7d 504 $s .= '<a href="'. $msgs_url.'">'.$msgs_str.'</a>';
c615b1da 505 $s .= $topbar_delimiter;
6206f6c4 506
c615b1da 507 $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox.
508 '&amp;message='.$passed_id.'&amp;';
509 if (!(isset($passed_ent_id) && $passed_ent_id)) {
510 if ($where && $what) {
511 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
512 } else {
513 $delete_url .= 'sort='. $sort . '&amp;startMessage='. $startMessage;
514 }
515 $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>';
516 }
517
518 $comp_uri = $base_uri . 'src/compose.php'.
519 '?passed_id='.$passed_id.
2ffa3f57 520 '&amp;mailbox='.$urlMailbox.
521 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
c615b1da 522
523 if (($mailbox == $draft_folder) && ($save_as_draft)) {
524 $comp_alt_uri = $comp_uri . '&amp;action=draft';
525 $comp_alt_string = _("Resume Draft");
526 } else if ($mailbox == $sent_folder) {
527 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
528 $comp_alt_string = _("Edit Message as New");
529 }
530 if (isset($comp_alt_uri)) {
531 $s .= $topbar_delimiter;
532 if ($compose_new_win == '1') {
533 $s .= '<a href="javascript:void(0)" '.
2ffa3f57 534 'onclick="comp_in_new(\''.$comp_alt_uri.'\')">'.$comp_alt_string.'</a>';
c615b1da 535 } else {
536 $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>';
537 }
538 }
2ffa3f57 539
c615b1da 540 $s .= '</small></td><td align="center" width="33%"><small>';
2ffa3f57 541
c615b1da 542 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
543 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
544 $next = findNextMessage($passed_id);
545 if ($prev != -1) {
546 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
547 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
548 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
549 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
550 } else {
551 $s .= _("Previous");
552 }
553 $s .= $topbar_delimiter;
554 if ($next != -1) {
555 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
556 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
557 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
2ffa3f57 558 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
c615b1da 559 } else {
560 $s .= _("Next");
561 }
562 } else if (isset($passed_ent_id) && $passed_ent_id) {
7172cad7 563 /* code for navigating through attached message/rfc822 messages */
564 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
565 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
566 $par_ent_id = $message->parent->entity_id;
567 if ($par_ent_id) {
2ffa3f57 568 $par_ent_id = substr($par_ent_id,0,-2);
569 $s .= $topbar_delimiter;
570 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
571 $s .= '<a href="'.$url.'">'._("Up").'</a>';
7172cad7 572 }
2ffa3f57 573 }
c615b1da 574
a128c967 575 $s .= '</small></td><td align="right" width="33%" nowrap><small>';
c615b1da 576 $comp_action_uri = $comp_uri . '&amp;action=forward';
577 if ($compose_new_win == '1') {
578 $s .= '<a href="javascript:void(0)" '.
579 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>';
580 } else {
581 $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>';
582 }
583 $s .= $topbar_delimiter;
584
6206f6c4 585 if ($enable_forward_as_attachment) {
586 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
587 if ($compose_new_win == '1') {
588 $s .= '<a href="javascript:void(0)" '.
589 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward as Attachment").'</a>';
590 } else {
591 $s .= '<a href="'.$comp_action_uri.'">'._("Forward as Attachment").'</a>';
592 }
593 $s .= $topbar_delimiter;
a128c967 594 }
a128c967 595
c615b1da 596 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
597 if ($compose_new_win == '1') {
598 $s .= '<a href="javascript:void(0)" '.
599 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>';
600 } else {
601 $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>';
602 }
603 $s .= $topbar_delimiter;
604
605 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
606 if ($compose_new_win == '1') {
607 $s .= '<a href="javascript:void(0)" '.
608 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>';
609 } else {
610 $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>';
611 }
612 $s .= '</small></td></tr></table>';
2ffa3f57 613 do_hook("read_body_menu_top");
7172cad7 614 echo $s;
2ffa3f57 615 do_hook("read_body_menu_bottom");
c615b1da 616}
617
618function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
8fde8417 619 global $QUERY_STRING, $base_uri;
c615b1da 620
f099d05f 621 $urlMailbox = urlencode($mailbox);
8fde8417 622 $url = $base_uri.'src/view_header.php?'.$QUERY_STRING;
9feb4369 623
70b98171 624 $s = "<TR>\n" .
625 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
626 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
627 '<a href="'.$url.'">'._("View Full Header").'</a>';
9feb4369 628
629 /* Output the printer friendly link if we are in subtle mode. */
70b98171 630 $s .= '&nbsp;|&nbsp;' .
631 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
7172cad7 632 echo $s;
c615b1da 633 do_hook("read_body_header_right");
70b98171 634 $s = "</SMALL></TD>\n" .
635 "</TR>\n";
a128c967 636 echo $s;
637
4d0cd98b 638}
639
6206f6c4 640/***************************/
2ffa3f57 641/* Main of read_body.php */
6206f6c4 642/***************************/
57257333 643
644/*
645 Urled vars
646 ----------
647 $passed_id
648*/
a07cd1a4 649
38c944cc 650global $uid_support, $sqimap_capabilities;
651
6a108031 652if (isset($mailbox)) {
4366bea4 653 $mailbox = urldecode( $mailbox );
654}
38c944cc 655
6206f6c4 656$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38c944cc 657$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
658
659if (!isset($messages)) {
660 $messages = array();
fc224f68 661 sqsession_register($messages,'messages');
38c944cc 662}
663
664/**
665 * $message contains all information about the message
666 * including header and body
667 */
37d2a6ee 668
669$uidvalidity = $mbx_response['UIDVALIDITY'];
670
671if (!isset($messages[$uidvalidity])) {
672 $messages[$uidvalidity] = array();
673}
5200c026 674if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
675 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 676 $FirstTimeSee = !$message->is_seen;
677 $message->is_seen = true;
5200c026 678 $messages[$uidvalidity][$passed_id] = $message;
fc224f68 679 sqsession_register($messages, 'messages');
38c944cc 680} else {
fc224f68 681// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
682 $message = $messages[$uidvalidity][$passed_id];
683 $FirstTimeSee = !$message->is_seen;
5200c026 684}
fc224f68 685//$FirstTimeSee = !$message->is_seen;
686//$message->is_seen = true;
687//$messages[$uidvalidity][$passed_id] = $message;
af568a82 688
dd628162 689if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 690 $message = $message->getEntity($passed_ent_id);
ff9d4297 691 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
692 $message = $message->parent;
693 }
141a16b2 694 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 695 $rfc822_header = new Rfc822Header();
141a16b2 696 $rfc822_header->parseHeader($read);
697 $message->rfc822_header = $rfc822_header;
c615b1da 698} else {
699 $passed_ent_id = 0;
38c944cc 700}
5200c026 701$header = $message->header;
57257333 702
6c31f818 703do_hook('html_top');
57257333 704
6206f6c4 705/****************************************/
706/* Block for handling incoming url vars */
707/****************************************/
5200c026 708
5200c026 709if (isset($sendreceipt)) {
710 if ( !$message->is_mdnsent ) {
711 if (isset($identity) ) {
712 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
713 } else {
714 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
715 }
716
717 $final_recipient = trim($final_recipient);
718 if ($final_recipient == '' ) {
719 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
720 }
af568a82 721 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 722 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 723 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 724 $message->is_mdnsent = true;
6a108031 725 $messages[$uidvalidity][$passed_id]=$message;
5200c026 726 }
727 ClearAttachments();
728 }
729}
6206f6c4 730/***********************************************/
731/* End of block for handling incoming url vars */
732/***********************************************/
733
38c944cc 734$msgs[$passed_id]['FLAG_SEEN'] = true;
38c944cc 735
5200c026 736$messagebody = '';
c4ad259b 737do_hook('read_body_top');
738if ($show_html_default == 1) {
739 $ent_ar = $message->findDisplayEntity(array());
740} else {
741 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
742}
a128c967 743$cnt = count($ent_ar);
744for ($i = 0; $i < $cnt; $i++) {
6a108031 745 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 746 if ($i != $cnt-1) {
747 $messagebody .= '<hr noshade size=1>';
748 }
38c944cc 749}
6a108031 750
c615b1da 751displayPageHeader($color, $mailbox);
7172cad7 752formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 753formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
6206f6c4 754echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
755echo ' <tr><td>';
756echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 757echo ' <tr><td>';
6206f6c4 758echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
759echo ' <tr bgcolor="'.$color[4].'"><td>';
760echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">';
761echo ' <tr><td><br>' . $messagebody . '</td></td>';
762echo ' </table>';
763echo ' </td></tr>';
764echo ' </table></td></tr>';
2ffa3f57 765echo ' </table>';
766echo ' </td></tr>';
a128c967 767
768$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
769if ($attachmentsdisplay) {
2ffa3f57 770 echo ' <tr><td>';
6206f6c4 771 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 772 echo ' <tr><td>';
773 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
6206f6c4 774 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
775 echo ' <b>' . _("Attachments") . ':</b>';
776 echo ' </td></tr>';
777 echo ' <tr><td>';
778 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
779 echo $attachmentsdisplay;
780 echo ' </td></tr></table>';
781 echo ' </table></td></tr>';
2ffa3f57 782 echo ' </table></td></tr>';
6206f6c4 783 echo ' </table>';
784 echo ' </td></tr>';
a128c967 785}
c615b1da 786echo '</table>';
a07cd1a4 787
a128c967 788
a07cd1a4 789/* show attached images inline -- if pref'fed so */
5be9f195 790if (($attachment_common_show_images) &&
a07cd1a4 791 is_array($attachment_common_show_images_list)) {
792 foreach ($attachment_common_show_images_list as $img) {
5be9f195 793 $imgurl = '../src/download.php' .
57257333 794 '?' .
cd7b8833 795 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 796 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 797 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 798 '&amp;absolute_dl=true';
5be9f195 799
b5058e9e 800 echo html_tag( 'table', "\n" .
801 html_tag( 'tr', "\n" .
802 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
803 )
804 ) ,
805 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 806 }
a07cd1a4 807}
808
c615b1da 809do_hook('read_body_bottom');
810do_hook('html_bottom');
d7eab095 811//$message->clean_up();
a07cd1a4 812sqimap_logout($imapConnection);
813?>
c615b1da 814</body>
815</html>