Right-to-left fixes from Saleh Madi <webmail@p-i-s.com> (part 2)
[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$
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');
21c8d457 25require_once(SM_PATH . 'functions/set_language_align.php');
26
27
28/* --------------------- Get globals ------------------------------------- */
29$language_align = set_language_align();
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 */
d9c1dccc 146 $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read);
147 return $ret;
57257333 148}
149
fc224f68 150function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
0b97a708 151 global $username, $attachment_dir, $_SERVER,
fc224f68 152 $version, $attachments, $squirrelmail_language, $default_charset,
d9c1dccc 153 $languages, $useSendmail, $domain, $sent_folder,
154 $popuser, $data_dir, $username;
57257333 155
0b97a708 156 $SERVER_NAME = $_SERVER['SERVER_NAME'];
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;
171 $rfc822_header->subject = _("Read:") . ' ' . $header->subject;
172
173
174 $reply_to = '';
175 if (isset($identity) && $identity != 'default') {
176 $from_mail = getPref($data_dir, $username,
d9c1dccc 177 'email_address' . $identity);
fc224f68 178 $full_name = getPref($data_dir, $username,
d9c1dccc 179 'full_name' . $identity);
fc224f68 180 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 181 $reply_to = getPref($data_dir, $username,
182 'reply_to' . $identity);
fc224f68 183 } else {
184 $from_mail = getPref($data_dir, $username, 'email_address');
185 $full_name = getPref($data_dir, $username, 'full_name');
186 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
d9c1dccc 187 $reply_to = getPref($data_dir, $username,'reply_to');
fc224f68 188 }
189 if (!$from_addr) {
190 $from_addr = "$popuser@$domain";
191 $from_mail = $from_addr;
192 }
193 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
194 if ($reply_to) {
195 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
196 }
d9c1dccc 197
57257333 198 // part 1 (RFC2298)
57257333 199 $senton = getLongDateString( $header->date );
200 $to_array = $header->to;
201 $to = '';
202 foreach ($to_array as $line) {
af568a82 203 $to .= ' '.$line->getAddress();
57257333 204 }
57257333 205 $now = getLongDateString( time() );
78db1583 206 set_my_charset();
46bb8da8 207 $body = _("Your message") . "\r\n\r\n" .
208 "\t" . _("To:") . ' ' . $to . "\r\n" .
fc224f68 209 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
46bb8da8 210 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
211 "\r\n" .
212 sprintf( _("Was displayed on %s"), $now );
f69feefe 213
fc224f68 214 $special_encoding = '';
215 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
216 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 217 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
d9c1dccc 218 if (strtolower($default_charset) == 'iso-2022-jp') {
219 if (mb_detect_encoding($body) == 'ASCII') {
220 $special_encoding = '8bit';
221 } else {
222 $body = mb_convert_encoding($body, 'JIS');
223 $special_encoding = '7bit';
224 }
225 }
6fbd125b 226 }
fc224f68 227 $part1 = new Message();
228 $part1->setBody($body);
229 $mime_header = new MessageHeader;
230 $mime_header->type0 = 'text';
231 $mime_header->type1 = 'plain';
232 if ($special_encoding) {
233 $mime_header->encoding = $special_encoding;
d9c1dccc 234 } else {
fc224f68 235 $mime_header->encoding = 'us-ascii';
236 }
237 if ($default_charset) {
238 $mime_header->parameters['charset'] = $default_charset;
239 }
240 $part1->mime_header = $mime_header;
241
57257333 242 // part2 (RFC2298)
d9c1dccc 243 $original_recipient = $to;
57257333 244 $original_message_id = $header->message_id;
245
fc224f68 246 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
57257333 247 if ($original_recipient != '') {
fc224f68 248 $report .= "Original-Recipient : $original_recipient\r\n";
57257333 249 }
250 $final_recipient = $sender;
fc224f68 251 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
57257333 252 "Original-Message-ID : $original_message_id\r\n" .
253 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
254
fc224f68 255 $part2 = new Message();
256 $part2->setBody($report);
257 $mime_header = new MessageHeader;
258 $mime_header->type0 = 'message';
259 $mime_header->type1 = 'disposition-notification';
260 $mime_header->encoding = 'us-ascii';
261 $part2->mime_header = $mime_header;
262
263 $composeMessage = new Message();
264 $composeMessage->rfc822_header = $rfc822_header;
265 $composeMessage->addEntity($part1);
266 $composeMessage->addEntity($part2);
267
268
d9c1dccc 269 if ($useSendmail) {
270 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
271 global $sendmail_path;
272 $deliver = new Deliver_SendMail();
273 $stream = $deliver->initStream($composeMessage,$sendmail_path);
fc224f68 274 } else {
d9c1dccc 275 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
276 $deliver = new Deliver_SMTP();
47a29326 277 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
278 if ($smtp_auth_mech == 'none') {
279 $user = '';
280 $pass = '';
281 } else {
d9c1dccc 282 global $key, $onetimepad;
283 $user = $username;
284 $pass = OneTimePadDecrypt($key, $onetimepad);
d9c1dccc 285 }
286 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
287 $stream = $deliver->initStream($composeMessage,$domain,0,
70ce2218 288 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
d9c1dccc 289 }
290 $success = false;
fc224f68 291 if ($stream) {
d9c1dccc 292 $length = $deliver->mail($composeMessage, $stream);
293 $success = $deliver->finalizeStream($stream);
fc224f68 294 }
d9c1dccc 295 if (!$success) {
00ac2f42 296 $msg = $deliver->dlv_msg . '<br>' .
297 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
298 $deliver->dlv_server_msg;
d9c1dccc 299 require_once(SM_PATH . 'functions/display_messages.php');
fc224f68 300 plain_error_message($msg, $color);
301 } else {
302 unset ($deliver);
d9c1dccc 303 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
304 sqimap_append ($imapConnection, $sent_folder, $length);
305 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
306 $imap_deliver = new Deliver_IMAP();
307 $imap_deliver->mail($composeMessage, $imapConnection);
308 sqimap_append_done ($imapConnection);
309 unset ($imap_deliver);
310 }
311 }
312 return $success;
57257333 313}
314
d9c1dccc 315function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
316 $sg = $set?'+':'-';
317 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 318 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 319 $readmessage, $uid_support);
57257333 320}
321
322function ClearAttachments() {
d9c1dccc 323 global $username, $attachments, $attachment_dir;
324
325 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
326
327 $rem_attachments = array();
328 foreach ($attachments as $info) {
329 if ($info['session'] == -1) {
330 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
331 if (file_exists($attached_file)) {
332 unlink($attached_file);
333 }
334 } else {
335 $rem_attachments[] = $info;
336 }
337 }
338 $attachments = $rem_attachments;
57257333 339}
340
4d0cd98b 341function formatRecipientString($recipients, $item ) {
d9c1dccc 342 global $show_more_cc, $show_more, $show_more_bcc,
343 $PHP_SELF;
4d0cd98b 344
d9c1dccc 345 $string = '';
38c944cc 346 if ((is_array($recipients)) && (isset($recipients[0]))) {
d9c1dccc 347 $show = false;
38c944cc 348
349 if ($item == 'to') {
d9c1dccc 350 if ($show_more) {
351 $show = true;
352 $url = set_url_var($PHP_SELF, 'show_more',0);
353 } else {
354 $url = set_url_var($PHP_SELF, 'show_more',1);
355 }
356 } else if ($item == 'cc') {
357 if ($show_more_cc) {
358 $show = true;
359 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
360 } else {
361 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
362 }
363 } else if ($item == 'bcc') {
364 if ($show_more_bcc) {
365 $show = true;
366 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
367 } else {
368 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
369 }
370 }
371
372 $cnt = count($recipients);
373 foreach($recipients as $r) {
374 $add = htmlspecialchars($r->getAddress());
375 if ($string) {
376 $string .= '<BR>' . $add;
377 } else {
378 $string = $add;
379 if ($cnt > 1) {
38c944cc 380 $string .= '&nbsp;(<A HREF="'.$url;
d9c1dccc 381 if ($show) {
382 $string .= '">'._("less").'</A>)';
383 } else {
384 $string .= '">'._("more").'</A>)';
385 break;
386 }
387 }
388 }
1fca12b5 389 }
4d0cd98b 390 }
c615b1da 391 return $string;
392}
393
af568a82 394function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
395 $color, $FirstTimeSee) {
21c8d457 396 global $msn_user_support, $default_use_mdn, $default_use_priority, $language_align,
77836429 397 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
398 $squirrelmail_language;
38bca81c 399
d9c1dccc 400 $header = $message->rfc822_header;
401 $env = array();
77836429 402 if ($squirrelmail_language == 'ja_JP') {
403 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
404 } else {
405 $env[_("Subject")] = decodeHeader(htmlspecialchars($header->subject));
406 }
d9c1dccc 407 $from_name = $header->getAddr_s('from');
408 if (!$from_name) {
409 $from_name = $header->getAddr_s('sender');
410 if (!$from_name) {
411 $from_name = _("Unknown sender");
412 }
413 }
414 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
415 $env[_("Date")] = getLongDateString($header->date);
416 $env[_("To")] = formatRecipientString($header->to, "to");
417 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
418 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
419 if ($default_use_priority) {
420 $env[_("Priority")] = getPriorityStr($header->priority);
421 }
422 if ($show_xmailer_default) {
423 $env[_("Mailer")] = decodeHeader($header->xmailer);
424 }
425 if ($default_use_mdn) {
426 if ($mdn_user_support) {
427 if ($header->dnt) {
428 if ($message->is_mdnsent) {
429 $env[_("Read receipt")] = _("send");
430 } else {
431 $env[_("Read receipt")] = _("requested");
8e1d27aa 432 if (!(handleAsSent($mailbox) ||
d9c1dccc 433 $message->is_deleted ||
434 $passed_ent_id)) {
435 $mdn_url = $PHP_SELF . '&sendreceipt=1';
436 if ($FirstTimeSee && $javascript_on) {
437 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
438 $script .= '<!--'. "\n";
439 $script .= 'if(window.confirm("' .
440 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
441 '")) { '."\n" .
442 ' sendMDN()'.
443 '}' . "\n";
444 $script .= '// -->'. "\n";
445 $script .= '</script>'. "\n";
446 echo $script;
447 }
448 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
449 _("Send read receipt now") . ']</a>';
450 }
451 }
452 }
453 }
454 }
c615b1da 455
21c8d457 456 $s = '<TABLE dir="' . $language_align['dir'] . '" WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
0e02d604 457 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
d9c1dccc 458 foreach ($env as $key => $val) {
459 if ($val) {
460 $s .= '<TR>';
461 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
462 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
463 $s .= '</TR>';
464 }
465 }
21c8d457 466 echo '<TABLE dir="' . $language_align['dir'] . '" BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
feb5ec1b 467 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
21c8d457 468 echo '<TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.
469 $color[4].'"></TD></TR><TR><TD dir="' . $language_align['dir'] . '" align=center>'."\n";
d9c1dccc 470 echo $s;
00ac2f42 471 do_hook('read_body_header');
d9c1dccc 472 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
473 echo '</TABLE>';
21c8d457 474 echo '</TD></TR><TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
feb5ec1b 475 echo '</TABLE>';
d9c1dccc 476}
c615b1da 477
7172cad7 478function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
21c8d457 479 global $base_uri, $draft_folder, $where, $what, $color, $sort, $language_align,
d9c1dccc 480 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
481 $enable_forward_as_attachment;
c615b1da 482
d9c1dccc 483 $topbar_delimiter = '&nbsp;|&nbsp;';
484 $urlMailbox = urlencode($mailbox);
21c8d457 485 $s = '<table dir=' . $language_align['dir'] . ' width="100%" cellpadding="3" cellspacing="0" align="center"'.
486 ' border="0" bgcolor="'.$color[9].'"><tr><td align="' . $language_align['left'] . '" width="33%"><small>';
e55c441a 487
d9c1dccc 488 $msgs_url = $base_uri . 'src/';
489 if (isset($where) && isset($what)) {
490 $msgs_url .= 'search.php?where=' . urlencode($where) .
491 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
492 $msgs_str = _("Search results");
493 } else {
494 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
495 $startMessage . '&amp;mailbox=' . $urlMailbox;
496 $msgs_str = _("Message List");
497 }
e55c441a 498 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
d9c1dccc 499
500 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
501 '&amp;message=' . $passed_id . '&amp;';
502 if (!(isset($passed_ent_id) && $passed_ent_id)) {
503 if ($where && $what) {
504 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
505 } else {
506 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
507 }
9f42bfc8 508 $s .= $topbar_delimiter;
e55c441a 509 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
d9c1dccc 510 }
c615b1da 511
d9c1dccc 512 $comp_uri = $base_uri . 'src/compose.php' .
513 '?passed_id=' . $passed_id .
514 '&amp;mailbox=' . $urlMailbox .
515 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
2ffa3f57 516
d9c1dccc 517 if ($compose_new_win == '1') {
518 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
519 $link_close = '\')">';
520 } else {
521 $link_open = '<a href="';
522 $link_close = '">';
523 }
524 if (($mailbox == $draft_folder) && ($save_as_draft)) {
525 $comp_alt_uri = $comp_uri . '&amp;action=draft';
526 $comp_alt_string = _("Resume Draft");
8e1d27aa 527 } else if (handleAsSent($mailbox)) {
d9c1dccc 528 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
529 $comp_alt_string = _("Edit Message as New");
530 }
531 if (isset($comp_alt_uri)) {
e55c441a 532 $s .= $topbar_delimiter;
533 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
d9c1dccc 534 }
2ffa3f57 535
e55c441a 536 $s .= '</small></td><td align="center" width="33%"><small>';
537
d9c1dccc 538 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
539 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
540 $next = findNextMessage($passed_id);
541 if ($prev != -1) {
542 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
543 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
544 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
e55c441a 545 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
d9c1dccc 546 } else {
e55c441a 547 $s .= _("Previous");
d9c1dccc 548 }
e55c441a 549 $s .= $topbar_delimiter;
d9c1dccc 550 if ($next != -1) {
551 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
552 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
553 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
e55c441a 554 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
d9c1dccc 555 } else {
e55c441a 556 $s .= _("Next");
d9c1dccc 557 }
558 } else if (isset($passed_ent_id) && $passed_ent_id) {
559 /* code for navigating through attached message/rfc822 messages */
560 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
e55c441a 561 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
70bdc740 562 $entities = array();
563 $entity_count = array();
564 $c = 0;
f2f03410 565
70bdc740 566 foreach($message->parent->entities as $ent) {
9f42bfc8 567 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
568 $c++;
569 $entity_count[$c] = $ent->entity_id;
570 $entities[$ent->entity_id] = $c;
571 }
70bdc740 572 }
573 $prev_link = _("Previous");
574 $next_link = _("Next");
575 if($entities[$passed_ent_id] > 1) {
576 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
577 $prev_link = '<a href="'
578 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
579 . '">' . $prev_link . '</a>';
580 }
581 if($entities[$passed_ent_id] < $c) {
582 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
583 $next_link = '<a href="'
584 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
585 . '">' . $next_link . '</a>';
586 }
e55c441a 587 $s .= $topbar_delimiter . $prev_link;
d9c1dccc 588 $par_ent_id = $message->parent->entity_id;
589 if ($par_ent_id) {
590 $par_ent_id = substr($par_ent_id,0,-2);
e55c441a 591 $s .= $topbar_delimiter;
d9c1dccc 592 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
e55c441a 593 $s .= '<a href="'.$url.'">'._("Up").'</a>';
d9c1dccc 594 }
e55c441a 595 $s .= $topbar_delimiter . $next_link;
d9c1dccc 596 }
c615b1da 597
e55c441a 598 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
d9c1dccc 599 $comp_action_uri = $comp_uri . '&amp;action=forward';
e55c441a 600 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
c615b1da 601
d9c1dccc 602 if ($enable_forward_as_attachment) {
603 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
e55c441a 604 $s .= $topbar_delimiter;
9f42bfc8 605 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
d9c1dccc 606 }
a128c967 607
d9c1dccc 608 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
e55c441a 609 $s .= $topbar_delimiter;
9f42bfc8 610 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
d9c1dccc 611
612 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
9f42bfc8 613 $s .= $topbar_delimiter;
e55c441a 614 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
615 $s .= '</small></td></tr></table>';
d9c1dccc 616 do_hook("read_body_menu_top");
e55c441a 617 echo $s;
d9c1dccc 618 do_hook("read_body_menu_bottom");
c615b1da 619}
620
621function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
21c8d457 622 global $base_uri, $language_align;
fe369c70 623
d9c1dccc 624 $urlMailbox = urlencode($mailbox);
fe369c70 625 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
d9c1dccc 626
21c8d457 627 $s = "<TR dir=" . $language_align['dir'] . ">\n" .
628 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['right'] . ' WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
629 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['left'] . ' WIDTH="80%"><SMALL>' .
d9c1dccc 630 '<a href="'.$url.'">'._("View Full Header").'</a>';
631
632 /* Output the printer friendly link if we are in subtle mode. */
633 $s .= '&nbsp;|&nbsp;' .
634 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
635 echo $s;
636 do_hook("read_body_header_right");
637 $s = "</SMALL></TD>\n" .
638 "</TR>\n";
639 echo $s;
a128c967 640
4d0cd98b 641}
642
6206f6c4 643/***************************/
2ffa3f57 644/* Main of read_body.php */
6206f6c4 645/***************************/
57257333 646
0b97a708 647/* get the globals we may need */
648
9f42bfc8 649$username = $_SESSION['username'];
650$key = $_COOKIE['key'];
0b97a708 651$onetimepad = $_SESSION['onetimepad'];
9f42bfc8 652$msgs = $_SESSION['msgs'];
653$base_uri = $_SESSION['base_uri'];
654$delimiter = $_SESSION['delimiter'];
0b97a708 655
656if (isset($_GET['passed_id'])) {
9b761dbd 657 $passed_id = (int) $_GET['passed_id'];
0b97a708 658}
659elseif (isset($_POST['passed_id'])) {
9b761dbd 660 $passed_id = (int) $_POST['passed_id'];
0b97a708 661}
662
ce274df9 663if (isset($_GET['passed_ent_id'])) {
664 $passed_ent_id = $_GET['passed_ent_id'];
665}
666elseif (isset($_POST['passed_ent_id'])) {
667 $passed_ent_id = $_POST['passed_ent_id'];
668}
669
0b97a708 670if (isset($_GET['sendreceipt'])) {
671 $sendreceipt = $_GET['sendreceipt'];
672}
673
674if (isset($_GET['sort'])) {
9b761dbd 675 $sort = (int) $_GET['sort'];
0b97a708 676}
677elseif (isset($_POST['sort'])) {
9b761dbd 678 $sort = (int) $_POST['sort'];
0b97a708 679}
680if (isset($_GET['startMessage'])) {
9b761dbd 681 $startMessage = (int) $_GET['startMessage'];
0b97a708 682}
683elseif (isset($_POST['startMessage'])) {
9b761dbd 684 $startMessage = (int) $_POST['startMessage'];
0b97a708 685}
686if (isset($_GET['show_more'])) {
9b761dbd 687 $show_more = (int) $_GET['show_more'];
0b97a708 688}
1b9f3c04 689if (isset($_GET['show_more_cc'])) {
9b761dbd 690 $show_more_cc = (int) $_GET['show_more_cc'];
1b9f3c04 691}
692if (isset($_GET['show_more_bcc'])) {
9b761dbd 693 $show_more_bcc = (int) $_GET['show_more_bcc'];
0b97a708 694}
695if (isset($_GET['mailbox'])) {
696 $mailbox = $_GET['mailbox'];
697}
698elseif (isset($_POST['mailbox'])) {
699 $mailbox = $_POST['mailbox'];
700}
701if (isset($_GET['where'])) {
702 $where = $_GET['where'];
703}
704if (isset($_GET['what'])) {
705 $what = $_GET['what'];
706}
707if (isset($_GET['view_hdr'])) {
9b761dbd 708 $view_hdr = (int) $_GET['view_hdr'];
0b97a708 709}
710if (isset($_SESSION['server_sort_array'])) {
711 $server_sort_array = $_SESSION['server_sort_array'];
712}
713if (isset($_SESSION['msgs'])) {
714 $msgs = $_SESSION['msgs'];
715}
716if (isset($_SESSION['msort'])) {
717 $msort = $_SESSION['msort'];
718}
719if (isset($_POST['move_id'])) {
720 $move_id = $_POST['move_id'];
721}
722if (isset($_SESSION['lastTargetMailbox'])) {
723 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
724}
ce274df9 725if (isset($_SESSION['messages'])) {
726 $messages = $_SESSION['messages'];
727} else {
728 $messages = array();
729}
0b97a708 730
a07cd1a4 731
ce274df9 732
733/* end of get globals */
38c944cc 734global $uid_support, $sqimap_capabilities;
735
6a108031 736if (isset($mailbox)) {
4366bea4 737 $mailbox = urldecode( $mailbox );
738}
38c944cc 739
6206f6c4 740$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
9f42bfc8 741$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
38c944cc 742
38c944cc 743
744/**
745 * $message contains all information about the message
746 * including header and body
747 */
37d2a6ee 748
749$uidvalidity = $mbx_response['UIDVALIDITY'];
9f42bfc8 750
37d2a6ee 751if (!isset($messages[$uidvalidity])) {
752 $messages[$uidvalidity] = array();
9f42bfc8 753}
5200c026 754if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
755 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
fc224f68 756 $FirstTimeSee = !$message->is_seen;
757 $message->is_seen = true;
5200c026 758 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 759} else {
fc224f68 760// $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
761 $message = $messages[$uidvalidity][$passed_id];
762 $FirstTimeSee = !$message->is_seen;
5200c026 763}
af568a82 764
dd628162 765if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 766 $message = $message->getEntity($passed_ent_id);
ff9d4297 767 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
768 $message = $message->parent;
769 }
141a16b2 770 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 771 $rfc822_header = new Rfc822Header();
141a16b2 772 $rfc822_header->parseHeader($read);
773 $message->rfc822_header = $rfc822_header;
c615b1da 774} else {
775 $passed_ent_id = 0;
38c944cc 776}
5200c026 777$header = $message->header;
57257333 778
6c31f818 779do_hook('html_top');
57257333 780
6206f6c4 781/****************************************/
782/* Block for handling incoming url vars */
783/****************************************/
5200c026 784
5200c026 785if (isset($sendreceipt)) {
786 if ( !$message->is_mdnsent ) {
787 if (isset($identity) ) {
788 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
789 } else {
790 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
791 }
792
793 $final_recipient = trim($final_recipient);
794 if ($final_recipient == '' ) {
795 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
796 }
af568a82 797 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
fc224f68 798 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
c615b1da 799 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 800 $message->is_mdnsent = true;
6a108031 801 $messages[$uidvalidity][$passed_id]=$message;
5200c026 802 }
803 ClearAttachments();
804 }
805}
6206f6c4 806/***********************************************/
807/* End of block for handling incoming url vars */
808/***********************************************/
809
38c944cc 810$msgs[$passed_id]['FLAG_SEEN'] = true;
9f42bfc8 811
812$messagebody = '';
c4ad259b 813do_hook('read_body_top');
814if ($show_html_default == 1) {
815 $ent_ar = $message->findDisplayEntity(array());
816} else {
817 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
818}
a128c967 819$cnt = count($ent_ar);
820for ($i = 0; $i < $cnt; $i++) {
6a108031 821 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 822 if ($i != $cnt-1) {
823 $messagebody .= '<hr noshade size=1>';
824 }
38c944cc 825}
e55c441a 826
c615b1da 827displayPageHeader($color, $mailbox);
7172cad7 828formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 829formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
21c8d457 830echo '<table dir="' . $language_align['dir'] . '" width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
6206f6c4 831echo ' <tr><td>';
21c8d457 832echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 833echo ' <tr><td>';
21c8d457 834echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
6206f6c4 835echo ' <tr bgcolor="'.$color[4].'"><td>';
21c8d457 836echo ' <table dir="' . $language_align['dir'] . '" cellpadding="1" cellspacing="5" align="' . $language_align['left'] . '" border="0">';
ce810ea7 837echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
6c7b5d8c 838 . '</tr>';
6206f6c4 839echo ' </table>';
840echo ' </td></tr>';
841echo ' </table></td></tr>';
2ffa3f57 842echo ' </table>';
843echo ' </td></tr>';
a128c967 844
d0a2476a 845echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
6c7b5d8c 846 $color[4].'"></TD></TR>'."\n";
d0a2476a 847
a128c967 848$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
849if ($attachmentsdisplay) {
2ffa3f57 850 echo ' <tr><td>';
6206f6c4 851 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 852 echo ' <tr><td>';
d0a2476a 853 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
21c8d457 854 echo ' <tr><td align="' . $language_align['left'] . '" bgcolor="'.$color[9].'">';
6206f6c4 855 echo ' <b>' . _("Attachments") . ':</b>';
856 echo ' </td></tr>';
857 echo ' <tr><td>';
858 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
859 echo $attachmentsdisplay;
860 echo ' </td></tr></table>';
6c7b5d8c 861 echo ' </td></tr></table>';
862 echo ' </td></tr></table>';
6206f6c4 863 echo ' </td></tr>';
6c7b5d8c 864 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
865 $color[4].'"></TD></TR>';
a128c967 866}
c615b1da 867echo '</table>';
a07cd1a4 868
869/* show attached images inline -- if pref'fed so */
5be9f195 870if (($attachment_common_show_images) &&
a07cd1a4 871 is_array($attachment_common_show_images_list)) {
872 foreach ($attachment_common_show_images_list as $img) {
ce274df9 873 $imgurl = SM_PATH . 'src/download.php' .
57257333 874 '?' .
cd7b8833 875 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 876 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 877 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 878 '&amp;absolute_dl=true';
5be9f195 879
b5058e9e 880 echo html_tag( 'table', "\n" .
d9c1dccc 881 html_tag( 'tr', "\n" .
882 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
883 )
884 ) ,
b5058e9e 885 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 886 }
a07cd1a4 887}
888
c615b1da 889do_hook('read_body_bottom');
890do_hook('html_bottom');
a07cd1a4 891sqimap_logout($imapConnection);
ce274df9 892/* sessions are written at the end of the script. it's better to register
893 them at the end so we avoid double session_register calls */
894sqsession_register($messages,'messages');
e55c441a 895
a07cd1a4 896?>
c615b1da 897</body>
898</html>