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