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