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