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