57b1bd6f6309694592c69c6cd09ec4fdcffdf04a
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/mime.php');
27 require_once(SM_PATH
. 'functions/date.php');
28 require_once(SM_PATH
. 'functions/url_parser.php');
29 require_once(SM_PATH
. 'functions/html.php');
30 require_once(SM_PATH
. 'functions/global.php');
31 require_once(SM_PATH
. 'functions/identity.php');
32 require_once(SM_PATH
. 'functions/mailbox_display.php');
35 * Given an IMAP message id number, this will look it up in the cached
36 * and sorted msgs array and return the index of the next message
38 * @param int $passed_id The current message UID
39 * @return the index of the next valid message from the array
41 function findNextMessage($uidset,$passed_id='backwards') {
42 if (!is_array($uidset)) {
45 if ($passed_id=='backwards' ||
!is_array($uidset)) { // check for backwards compattibilty gpg plugin
49 $count = count($uidset) - 1;
50 foreach($uidset as $key=>$value) {
51 if ($passed_id == $value) {
55 $result = $uidset[$key +
1];
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
66 * @param int $passed_id The current message UID
67 * @return the index of the next valid message from the array
70 function findPreviousMessage($uidset, $passed_id) {
71 if (!is_array($uidset)) {
75 foreach($uidset as $key=>$value) {
76 if ($passed_id == $value) {
78 $result = $uidset[$key - 1];
88 * Displays a link to a page where the message is displayed more
90 * @param string $mailbox Name of current mailbox
91 * @param int $passed_id
93 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
94 global $javascript_on, $color;
96 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
97 '&mailbox=' . urlencode($mailbox) .
98 '&passed_id=' . urlencode($passed_id);
100 $print_text = _("View Printable Version");
103 /* Output the link. */
104 if ($javascript_on) {
105 $result = '<script language="javascript" type="text/javascript">' . "\n" .
107 " function printFormat() {\n" .
108 ' window.open("../src/printer_friendly_main.php' .
109 $params . '","Print","width=800,height=600");' . "\n".
113 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
115 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
116 "$params\">$print_text</a>\n";
121 function ServerMDNSupport($aFlags) {
122 /* escaping $ doesn't work -> \x36 */
123 return ( in_array('$mdnsent',$aFlags,true) ||
124 in_array('\\*',$aFlags,true) ) ;
127 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
128 global $username, $attachment_dir,
129 $version, $attachments, $squirrelmail_language, $default_charset,
130 $languages, $useSendmail, $domain, $sent_folder,
131 $popuser, $data_dir, $username;
133 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
135 $header = $message->rfc822_header
;
136 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
138 $rfc822_header = new Rfc822Header();
139 $content_type = new ContentType('multipart/report');
140 $content_type->properties
['report-type']='disposition-notification';
143 if ($default_charset) {
144 $content_type->properties
['charset']=$default_charset;
146 $rfc822_header->content_type
= $content_type;
147 $rfc822_header->to
[] = $header->dnt
;
148 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
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);
158 $popuser = $username;
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'];
170 $from_mail = "$popuser@$domain";
171 $from_addr = $from_mail;
173 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
175 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
179 $senton = getLongDateString( $header->date
);
180 $to_array = $header->to
;
182 foreach ($to_array as $line) {
183 $to .= ' '.$line->getAddress();
185 $now = getLongDateString( time() );
187 $body = _("Your message") . "\r\n\r\n" .
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" .
192 sprintf( _("Was displayed on %s"), $now );
194 $special_encoding = '';
195 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
196 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
197 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body);
198 if (strtolower($default_charset) == 'iso-2022-jp') {
199 if (mb_detect_encoding($body) == 'ASCII') {
200 $special_encoding = '8bit';
202 $body = mb_convert_encoding($body, 'JIS');
203 $special_encoding = '7bit';
206 } elseif (sq_is8bit($body)) {
207 $special_encoding = '8bit';
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;
217 $mime_header->encoding
= 'us-ascii';
219 if ($default_charset) {
220 $mime_header->parameters
['charset'] = $default_charset;
222 $part1->mime_header
= $mime_header;
225 $original_recipient = $to;
226 $original_message_id = $header->message_id
;
228 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
229 if ($original_recipient != '') {
230 $report .= "Original-Recipient : $original_recipient\r\n";
232 $final_recipient = $sender;
233 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
234 "Original-Message-ID : $original_message_id\r\n" .
235 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
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;
245 $composeMessage = new Message();
246 $composeMessage->rfc822_header
= $rfc822_header;
247 $composeMessage->addEntity($part1);
248 $composeMessage->addEntity($part2);
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);
257 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
258 $deliver = new Deliver_SMTP();
259 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
260 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
261 get_smtp_user($user, $pass);
262 $stream = $deliver->initStream($composeMessage,$domain,0,
263 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
267 $length = $deliver->mail($composeMessage, $stream);
268 $success = $deliver->finalizeStream($stream);
271 $msg = $deliver->dlv_msg
. '<br />' .
272 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
273 $deliver->dlv_server_msg
;
274 require_once(SM_PATH
. 'functions/display_messages.php');
275 plain_error_message($msg, $color);
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);
290 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
292 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
293 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
297 function ClearAttachments() {
298 global $username, $attachments, $attachment_dir;
300 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
302 $rem_attachments = array();
303 if (isset($attachments)) {
304 foreach ($attachments as $info) {
305 if ($info['session'] == -1) {
306 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
307 if (file_exists($attached_file)) {
308 unlink($attached_file);
311 $rem_attachments[] = $info;
315 $attachments = $rem_attachments;
318 function formatRecipientString($recipients, $item ) {
319 global $show_more_cc, $show_more, $show_more_bcc,
323 if ((is_array($recipients)) && (isset($recipients[0]))) {
329 $url = set_url_var($PHP_SELF, 'show_more',0);
331 $url = set_url_var($PHP_SELF, 'show_more',1);
333 } else if ($item == 'cc') {
336 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
338 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
340 } else if ($item == 'bcc') {
341 if ($show_more_bcc) {
343 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
345 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
349 $cnt = count($recipients);
350 foreach($recipients as $r) {
351 $add = decodeHeader($r->getAddress(true));
353 $string .= '<br />' . $add;
357 $string .= ' (<a href="'.$url;
359 $string .= '">'._("less").'</a>)';
361 $string .= '">'._("more").'</a>)';
371 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
372 $color, $FirstTimeSee) {
373 global $msn_user_support, $default_use_mdn, $default_use_priority,
374 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
375 $squirrelmail_language;
377 $mailbox = $aMailbox['NAME'];
379 $header = $message->rfc822_header
;
381 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
383 $from_name = $header->getAddr_s('from');
385 $from_name = $header->getAddr_s('sender');
387 $env[_("From")] = _("Unknown sender");
389 $env[_("From")] = decodeHeader($from_name);
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) {
395 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
397 if ($show_xmailer_default) {
398 $env[_("Mailer")] = decodeHeader($header->xmailer
);
400 if ($default_use_mdn) {
401 if ($mdn_user_support) {
403 if ($message->is_mdnsent
) {
404 $env[_("Read receipt")] = _("sent");
406 $env[_("Read receipt")] = _("requested");
407 if (!(handleAsSent($mailbox) ||
408 $message->is_deleted ||
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?") .
419 $script .= '// -->'. "\n";
420 $script .= '</script>'. "\n";
423 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
424 _("Send read receipt now") . ']</a>';
431 $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
432 $s .= ' align="center" bgcolor="'.$color[0].'">';
433 foreach ($env as $key => $val) {
436 $s .= html_tag('td', '<b>' . $key . ': </b>', 'right', '', 'valign="top" width="20%"') . "\n";
437 $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
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";
446 do_hook('read_body_header');
447 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
449 echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
454 * Format message toolbar
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
462 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
463 global $base_uri, $draft_folder, $where, $what, $color, $sort,
464 $startMessage, $PHP_SELF, $save_as_draft,
465 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
466 $data_dir, $username, $delete_prev_next_display,
467 $compose_new_win, $javascript_on;
469 //FIXME cleanup argument list, use $aMailbox where possible
470 $mailbox = $aMailbox['NAME'];
472 $topbar_delimiter = ' | ';
473 $double_delimiter = ' ';
474 $urlMailbox = urlencode($mailbox);
476 $msgs_url = $base_uri . 'src/';
478 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
479 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
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
485 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
487 $entity_count = array();
490 foreach($message->parent
->entities
as $ent) {
491 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
493 $entity_count[$c] = $ent->entity_id
;
494 $entities[$ent->entity_id
] = $c;
498 $prev_link = _("Previous");
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>';
506 $next_link = _("Next");
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>';
514 $par_ent_id = $message->parent
->entity_id
;
517 $par_ent_id = substr($par_ent_id,0,-2);
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>';
525 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
526 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
528 // Prev/Next links for regular messages
529 } else if ( true ) { //!(isset($where) && isset($what)) ) {
531 * Check if cache is still valid
533 if (!is_array($aMailbox['UIDSET'][$what])) {
534 fetchMessageHeaders($imapConnection, $aMailbox);
536 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
537 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
539 $prev_link = _("Previous");
541 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
542 '&mailbox='.$urlMailbox.'&sort='.$sort.
543 "&where=$where&what=$what" .
544 '&startMessage='.$startMessage.'&show_more=0';
545 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
548 $next_link = _("Next");
550 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
551 '&mailbox='.$urlMailbox.'&sort='.$sort.
552 "&where=$where&what=$what" .
553 '&startMessage='.$startMessage.'&show_more=0';
554 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
557 // Only bother with Delete & Prev and Delete & Next IF
558 // top display is enabled.
559 if ( $delete_prev_next_display == 1 &&
560 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
561 $del_prev_link = _("Delete & Prev");
563 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
564 '&mailbox='.$urlMailbox.'&sort='.$sort.
565 '&startMessage='.$startMessage.'&show_more=0'.
566 "&where=$where&what=$what" .
567 '&delete_id='.$passed_id;
568 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
571 $del_next_link = _("Delete & Next");
573 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
574 '&mailbox='.$urlMailbox.'&sort='.$sort.
575 '&startMessage='.$startMessage.'&show_more=0'.
576 "&where=$where&what=$what" .
577 '&delete_id='.$passed_id;
578 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
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.']';
587 // Start with Search Results or Message List link.
588 $msgs_url .= "$where?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
589 "&startMessage=$startMessage";
590 if ($where == 'search.php') {
591 $msgs_str = _("Search Results");
593 $msgs_str = _("Message List");
595 $nav_row .= $double_delimiter .
596 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
598 $nav_row .= '</small></td></tr>';
601 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
602 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
603 $comp_uri = $base_uri.'src/compose.php' .
604 '?passed_id=' . $passed_id .
605 '&mailbox=' . $urlMailbox .
606 '&startMessage=' . $startMessage .
607 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
609 // Start form for reply/reply all/forward..
612 $method='method="post" ';
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)';
617 $method='method="get" ';
619 $target = 'target="_blank"';
623 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
625 // If Draft folder - create Resume link
626 if (($mailbox == $draft_folder) && ($save_as_draft)) {
627 $new_button = 'smaction_draft';
628 $comp_alt_string = _("Resume Draft");
629 } else if (handleAsSent($mailbox)) {
630 // If in Sent folder, edit as new
631 $new_button = 'smaction_edit_new';
632 $comp_alt_string = _("Edit Message as New");
634 // Show Alt URI for Draft/Sent
635 if (isset($comp_alt_string))
636 $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n";
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);
641 if ($enable_forward_as_attachment)
642 $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .' '."\n";
644 $menu_row .= '</form> ';
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";
649 $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">';
651 if (!(isset($passed_ent_id) && $passed_ent_id)) {
652 $menu_row .= addHidden('mailbox', $aMailbox['NAME']);
653 $menu_row .= addHidden('msg[0]', $passed_id);
654 $menu_row .= addHidden('startMessage', $startMessage);
655 $menu_row .= getButton('submit', 'delete', _("Delete"));
656 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
658 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
661 $menu_row .= '</form>';
665 $menu_row .= '</small></td><td align="right">';
666 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
667 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
669 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
672 addHidden('mailbox',$aMailbox['NAME']) .
673 addHidden('msg[0]', $passed_id) . _("Move to:") .
674 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
676 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
677 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
679 $menu_row .= sqimap_mailbox_option_list($imapConnection);
681 $menu_row .= '</select> ';
683 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
685 $menu_row .= '</td></tr>';
687 // echo rows, with hooks
688 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
689 if (is_array($ret)) {
690 if (isset($ret[0]) && !empty($ret[0])) {
693 if (isset($ret[1]) && !empty($ret[1])) {
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";
700 do_hook('read_body_menu_bottom');
703 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
704 global $base_uri, $where, $what;
706 $urlMailbox = urlencode($mailbox);
707 $urlPassed_id = urlencode($passed_id);
708 $urlPassed_ent_id = urlencode($passed_ent_id);
710 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
712 if (!empty($where)) {
713 $query_string .= '&where=' . urlencode($where);
717 $query_string .= '&what=' . urlencode($what);
720 $url = $base_uri.'src/view_header.php?'.$query_string;
723 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ": </b></td>\n" .
724 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
725 '<a href="'.$url.'">'._("View Full Header").'</a>';
727 /* Output the printer friendly link if we are in subtle mode. */
728 $s .= ' | ' .
729 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
731 do_hook("read_body_header_right");
732 $s = "</small></td>\n" .
738 /***************************/
739 /* Main of read_body.php */
740 /***************************/
742 /* get the globals we may need */
744 sqgetGlobalVar('key', $key, SQ_COOKIE
);
745 sqgetGlobalVar('username', $username, SQ_SESSION
);
746 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
747 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
748 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
749 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
750 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
755 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
756 if (!sqgetGlobalVar('where', $where, SQ_GET
) ) {
757 $where = 'right_main.php';
759 if (!sqgetGlobalVar('what', $what, SQ_GET
) ){
762 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
763 $show_more = (int) $temp;
765 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
766 $show_more_cc = (int) $temp;
768 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
769 $show_more_bcc = (int) $temp;
771 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
772 $view_hdr = (int) $temp;
776 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
777 sqgetGlobalVar('mailbox', $mailbox);
779 if ( sqgetGlobalVar('passed_id', $temp) ) {
780 $passed_id = (int) $temp;
782 if ( sqgetGlobalVar('sort', $temp) ) {
785 if ( sqgetGlobalVar('startMessage', $temp) ) {
786 $startMessage = (int) $temp;
791 * Retrieve mailbox cache
793 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
795 /* end of get globals */
796 global $sqimap_capabilities, $lastTargetMailbox;
798 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
799 $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox,array('setindex' => $what),array());
802 * Update the seen state
803 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
805 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
806 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
810 * Process Delete from delete-move-next
811 * but only if delete_id was set
813 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
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);
820 * $message contains all information about the message
821 * including header and body
824 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
825 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
826 $FirstTimeSee = !$message->is_seen
;
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;
834 if (isset($passed_ent_id) && $passed_ent_id) {
835 $message = $message->getEntity($passed_ent_id);
836 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
837 $message = $message->parent
;
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;
846 $header = $message->header
;
849 /****************************************/
850 /* Block for handling incoming url vars */
851 /****************************************/
853 if (isset($sendreceipt)) {
854 if ( !$message->is_mdnsent
) {
855 $final_recipient = '';
856 if ((isset($identity)) && ($identity != 0)) //Main identity
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', '' ));
860 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
861 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
862 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
863 $message->is_mdnsent
= true;
864 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
869 /***********************************************/
870 /* End of block for handling incoming url vars */
871 /***********************************************/
876 do_hook('read_body_top');
877 if ($show_html_default == 1) {
878 $ent_ar = $message->findDisplayEntity(array());
880 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
882 $cnt = count($ent_ar);
883 for ($i = 0; $i < $cnt; $i++
) {
884 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
886 $messagebody .= '<hr style="height: 1px;" />';
890 displayPageHeader($color, $mailbox);
891 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
892 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
893 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
895 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
897 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
898 echo ' <tr bgcolor="'.$color[4].'"><td>';
899 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
900 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
901 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
905 echo ' </table></td></tr>';
909 echo '<tr><td height="5" colspan="2" bgcolor="'.
910 $color[4].'"></td></tr>'."\n";
912 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
913 if ($attachmentsdisplay) {
915 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
917 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
918 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
919 echo ' <b>' . _("Attachments") . ':</b>';
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>';
925 echo ' </td></tr></table>';
927 echo '<tr><td height="5" colspan="2" bgcolor="'.
928 $color[4].'"></td></tr>';
932 /* show attached images inline -- if pref'fed so */
933 if (($attachment_common_show_images) &&
934 is_array($attachment_common_show_images_list)) {
935 foreach ($attachment_common_show_images_list as $img) {
936 $imgurl = SM_PATH
. 'src/download.php' .
938 'passed_id=' . urlencode($img['passed_id']) .
939 '&mailbox=' . urlencode($mailbox) .
940 '&ent_id=' . urlencode($img['ent_id']) .
941 '&absolute_dl=true';
943 echo html_tag( 'table', "\n" .
944 html_tag( 'tr', "\n" .
945 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
948 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
952 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
954 do_hook('read_body_bottom');
955 sqimap_logout($imapConnection);
956 /* sessions are written at the end of the script. it's better to register
957 them at the end so we avoid double session_register calls */
958 /* add the mailbox to the cache */
959 $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
960 sqsession_register($mailbox_cache,'mailbox_cache');