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