6 * This file is used for reading the msgs array and displaying
7 * the resulting emails in the right frame.
9 * @copyright © 1999-2005 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
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 include_once(SM_PATH
. 'functions/arrays.php');
32 include_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
48 $result = sqm_array_get_value_by_offset($uidset,$passed_id,1);
49 if ($result === false) {
57 * Given an IMAP message id number, this will look it up in the cached
58 * and sorted msgs array and return the index of the previous message
60 * @param int $passed_id The current message UID
61 * @return the index of the next valid message from the array
64 function findPreviousMessage($uidset, $passed_id) {
65 if (!is_array($uidset)) {
68 $result = sqm_array_get_value_by_offset($uidset,$passed_id,-1);
69 if ($result === false) {
77 * Displays a link to a page where the message is displayed more
79 * @param string $mailbox Name of current mailbox
80 * @param int $passed_id
82 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
83 global $javascript_on;
86 if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET
) ) {
87 $view_unsafe_images = false;
89 $view_unsafe_images = true;
91 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
92 '&mailbox=' . urlencode($mailbox) .
93 '&passed_id=' . urlencode($passed_id).
94 '&view_unsafe_images='. (bool) $view_unsafe_images;
96 $print_text = _("View Printable Version");
99 /* Output the link. */
100 if ($javascript_on) {
101 $result = '<script language="javascript" type="text/javascript">' . "\n" .
103 " function printFormat() {\n" .
104 ' window.open("../src/printer_friendly_main.php' .
105 $params . '","Print","width=800,height=600");' . "\n".
109 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
111 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
112 "$params\">$print_text</a>\n";
117 function ServerMDNSupport($aFlags) {
118 /* escaping $ doesn't work -> \x36 */
119 return ( in_array('$mdnsent',$aFlags,true) ||
120 in_array('\\*',$aFlags,true) ) ;
123 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
124 global $username, $attachment_dir, $popuser, $username, $color,
125 $version, $squirrelmail_language, $default_charset,
126 $languages, $useSendmail, $domain, $sent_folder;
128 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
130 $header = $message->rfc822_header
;
132 $rfc822_header = new Rfc822Header();
133 $content_type = new ContentType('multipart/report');
134 $content_type->properties
['report-type']='disposition-notification';
137 if ($default_charset) {
138 $content_type->properties
['charset']=$default_charset;
140 $rfc822_header->content_type
= $content_type;
141 $rfc822_header->to
[] = $header->dnt
;
142 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
144 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
145 // This merely comes from compose.php and only happens when there is no
146 // email_addr specified in user's identity (which is the startup config)
147 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
148 $popuser = $usernamedata[1];
149 $domain = $usernamedata[2];
150 unset($usernamedata);
152 $popuser = $username;
156 $ident = get_identities();
157 if(!isset($identity)) $identity = 0;
158 $full_name = $ident[$identity]['full_name'];
159 $from_mail = $ident[$identity]['email_address'];
160 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
161 $reply_to = $ident[$identity]['reply_to'];
164 $from_mail = "$popuser@$domain";
165 $from_addr = $from_mail;
167 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
169 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
173 $senton = getLongDateString( $header->date
);
174 $to_array = $header->to
;
176 foreach ($to_array as $line) {
177 $to .= ' '.$line->getAddress();
179 $now = getLongDateString( time() );
181 $body = _("Your message") . "\r\n\r\n" .
182 "\t" . _("To") . ': ' . decodeHeader($to,false,false) . "\r\n" .
183 "\t" . _("Subject") . ': ' . decodeHeader($header->subject
,false,false) . "\r\n" .
184 "\t" . _("Sent") . ': ' . $senton . "\r\n" .
186 sprintf( _("Was displayed on %s"), $now );
188 $special_encoding = '';
189 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
190 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
191 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body);
192 if (strtolower($default_charset) == 'iso-2022-jp') {
193 if (mb_detect_encoding($body) == 'ASCII') {
194 $special_encoding = '8bit';
196 $body = mb_convert_encoding($body, 'JIS');
197 $special_encoding = '7bit';
200 } elseif (sq_is8bit($body)) {
201 $special_encoding = '8bit';
203 $part1 = new Message();
204 $part1->setBody($body);
205 $mime_header = new MessageHeader
;
206 $mime_header->type0
= 'text';
207 $mime_header->type1
= 'plain';
208 if ($special_encoding) {
209 $mime_header->encoding
= $special_encoding;
211 $mime_header->encoding
= 'us-ascii';
213 if ($default_charset) {
214 $mime_header->parameters
['charset'] = $default_charset;
216 $part1->mime_header
= $mime_header;
219 $original_recipient = $to;
220 $original_message_id = $header->message_id
;
222 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
223 if ($original_recipient != '') {
224 $report .= "Original-Recipient : $original_recipient\r\n";
226 $final_recipient = $sender;
227 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
228 "Original-Message-ID : $original_message_id\r\n" .
229 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
231 $part2 = new Message();
232 $part2->setBody($report);
233 $mime_header = new MessageHeader
;
234 $mime_header->type0
= 'message';
235 $mime_header->type1
= 'disposition-notification';
236 $mime_header->encoding
= 'us-ascii';
237 $part2->mime_header
= $mime_header;
239 $composeMessage = new Message();
240 $composeMessage->rfc822_header
= $rfc822_header;
241 $composeMessage->addEntity($part1);
242 $composeMessage->addEntity($part2);
246 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
247 global $sendmail_path;
248 $deliver = new Deliver_SendMail();
249 $stream = $deliver->initStream($composeMessage,$sendmail_path);
251 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
252 $deliver = new Deliver_SMTP();
253 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
254 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
255 get_smtp_user($user, $pass);
256 $stream = $deliver->initStream($composeMessage,$domain,0,
257 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
261 $length = $deliver->mail($composeMessage, $stream);
262 $success = $deliver->finalizeStream($stream);
265 $msg = $deliver->dlv_msg
. '<br />' .
266 _("Server replied:") . ' ' . $deliver->dlv_ret_nr
. ' ' .
267 $deliver->dlv_server_msg
;
268 require_once(SM_PATH
. 'functions/display_messages.php');
269 plain_error_message($msg, $color);
272 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
273 sqimap_append ($imapConnection, $sent_folder, $length);
274 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
275 $imap_deliver = new Deliver_IMAP();
276 $imap_deliver->mail($composeMessage, $imapConnection);
277 sqimap_append_done ($imapConnection);
278 unset ($imap_deliver);
284 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
286 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
287 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
291 function formatRecipientString($recipients, $item ) {
292 global $show_more_cc, $show_more, $show_more_bcc,
296 if ((is_array($recipients)) && (isset($recipients[0]))) {
302 $url = set_url_var($PHP_SELF, 'show_more',0);
304 $url = set_url_var($PHP_SELF, 'show_more',1);
306 } else if ($item == 'cc') {
309 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
311 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
313 } else if ($item == 'bcc') {
314 if ($show_more_bcc) {
316 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
318 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
322 $cnt = count($recipients);
323 foreach($recipients as $r) {
324 $add = decodeHeader($r->getAddress(true));
326 $string .= '<br />' . $add;
330 $string .= ' (<a href="'.$url;
332 $string .= '">'._("less").'</a>)';
334 $string .= '">'._("more").'</a>)';
344 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
345 $color, $FirstTimeSee) {
346 global $default_use_mdn, $default_use_priority,
347 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
348 $squirrelmail_language;
350 $mailbox = $aMailbox['NAME'];
352 $header = $message->rfc822_header
;
354 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
356 $from_name = $header->getAddr_s('from');
358 $from_name = $header->getAddr_s('sender');
360 $env[_("From")] = _("Unknown sender");
362 $env[_("From")] = decodeHeader($from_name);
363 $env[_("Date")] = getLongDateString($header->date
);
364 $env[_("To")] = formatRecipientString($header->to
, "to");
365 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
366 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
367 if ($default_use_priority) {
368 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
370 if ($show_xmailer_default) {
371 $env[_("Mailer")] = decodeHeader($header->xmailer
);
373 if ($default_use_mdn) {
374 if ($mdn_user_support) {
376 if ($message->is_mdnsent
) {
377 $env[_("Read receipt")] = _("sent");
379 $env[_("Read receipt")] = _("requested");
380 if (!(handleAsSent($mailbox) ||
381 $message->is_deleted ||
383 $mdn_url = $PHP_SELF . '&sendreceipt=1';
384 if ($FirstTimeSee && $javascript_on) {
385 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
386 $script .= '<!--'. "\n";
387 $script .= 'if(window.confirm("' .
388 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
392 $script .= '// -->'. "\n";
393 $script .= '</script>'. "\n";
396 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
397 _("Send read receipt now") . ']</a>';
404 $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
405 $s .= ' align="center" bgcolor="'.$color[0].'">';
406 foreach ($env as $key => $val) {
409 $s .= html_tag('td', '<b>' . $key . ': </b>', 'right', '', 'valign="top" width="20%"') . "\n";
410 $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
414 echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
415 ' cellspacing="0" border="0" align="center">'."\n";
416 echo '<tr><td height="5" colspan="2" bgcolor="'.
417 $color[4].'"></td></tr><tr><td align="center">'."\n";
419 do_hook('read_body_header');
420 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
422 echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
427 * Format message toolbar
429 * @param string $mailbox Name of current mailbox
430 * @param int $passed_id UID of current message
431 * @param int $passed_ent_id Id of entity within message
432 * @param object $message Current message object
433 * @param object $mbx_response
435 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
436 global $base_uri, $draft_folder, $where, $what, $color, $sort,
437 $startMessage, $PHP_SELF, $save_as_draft,
438 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
439 $username, $delete_prev_next_display,
440 $compose_new_win, $javascript_on, $compose_width, $compose_height;
442 //FIXME cleanup argument list, use $aMailbox where possible
443 $mailbox = $aMailbox['NAME'];
445 $topbar_delimiter = ' | ';
446 $double_delimiter = ' ';
447 $urlMailbox = urlencode($mailbox);
449 $msgs_url = $base_uri . 'src/';
451 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
452 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
454 // Create Prev & Next links
455 // Handle nested entities first (i.e. Mime Attach parts)
456 if (isset($passed_ent_id) && $passed_ent_id) {
457 // code for navigating through attached message/rfc822 messages
458 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
460 $entity_count = array();
463 foreach($message->parent
->entities
as $ent) {
464 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
466 $entity_count[$c] = $ent->entity_id
;
467 $entities[$ent->entity_id
] = $c;
471 $prev_link = _("Previous");
472 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] > 1) {
473 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
474 $prev_link = '<a href="'
475 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
476 . '">' . $prev_link . '</a>';
479 $next_link = _("Next");
480 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] < $c) {
481 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
482 $next_link = '<a href="'
483 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
484 . '">' . $next_link . '</a>';
487 $par_ent_id = $message->parent
->entity_id
;
490 $par_ent_id = substr($par_ent_id,0,-2);
491 if ( $par_ent_id != 0 ) {
492 $up_link = $topbar_delimiter;
493 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
494 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
498 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
499 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
501 // Prev/Next links for regular messages
502 } else if ( true ) { //!(isset($where) && isset($what)) ) {
503 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
504 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
506 $prev_link = _("Previous");
508 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
509 '&mailbox='.$urlMailbox.'&sort='.$sort.
510 "&where=$where&what=$what" .
511 '&startMessage='.$startMessage.'&show_more=0';
512 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
515 $next_link = _("Next");
517 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
518 '&mailbox='.$urlMailbox.'&sort='.$sort.
519 "&where=$where&what=$what" .
520 '&startMessage='.$startMessage.'&show_more=0';
521 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
524 // Only bother with Delete & Prev and Delete & Next IF
525 // top display is enabled.
526 if ( $delete_prev_next_display == 1 &&
527 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
528 $del_prev_link = _("Delete & Prev");
530 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
531 '&mailbox='.$urlMailbox.'&sort='.$sort.
532 '&startMessage='.$startMessage.'&show_more=0'.
533 "&where=$where&what=$what" .
534 '&delete_id='.$passed_id;
535 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
538 $del_next_link = _("Delete & Next");
540 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
541 '&mailbox='.$urlMailbox.'&sort='.$sort.
542 '&startMessage='.$startMessage.'&show_more=0'.
543 "&where=$where&what=$what" .
544 '&delete_id='.$passed_id;
545 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
549 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
550 if ( isset($del_prev_link) && isset($del_next_link) )
551 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
554 // Start with Search Results or Message List link.
555 $msgs_url .= "$where?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
556 "&startMessage=$startMessage";
557 if ($where == 'search.php') {
558 $msgs_str = _("Search Results");
560 $msgs_str = _("Message List");
562 $nav_row .= $double_delimiter .
563 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
565 $nav_row .= '</small></td></tr>';
568 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
569 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
570 $comp_uri = $base_uri.'src/compose.php' .
571 '?passed_id=' . $passed_id .
572 '&mailbox=' . $urlMailbox .
573 '&startMessage=' . $startMessage .
574 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
576 // Start form for reply/reply all/forward..
579 $method='method="post" ';
581 if ($compose_new_win == '1') {
582 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
583 $compose_width = '640';
585 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
586 $compose_height = '550';
588 if ( $javascript_on ) {
589 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"';
590 $comp_uri = 'javascript:void(0)';
591 $method='method="get" ';
592 $onsubmit = 'onsubmit="return false" ';
594 $target = 'target="_blank"';
598 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '
599 . $method.$target.$onsubmit.' style="display: inline">'."\n";
601 // If Draft folder - create Resume link
602 if (($mailbox == $draft_folder) && ($save_as_draft)) {
603 $new_button = 'smaction_draft';
604 $comp_alt_string = _("Resume Draft");
605 } else if (handleAsSent($mailbox)) {
606 // If in Sent folder, edit as new
607 $new_button = 'smaction_edit_new';
608 $comp_alt_string = _("Edit Message as New");
610 // Show Alt URI for Draft/Sent
611 if (isset($comp_alt_string))
612 $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n";
614 $menu_row .= getButton('submit', 'smaction_reply', _("Reply"), $on_click) . "\n";
615 $menu_row .= getButton('submit', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
616 $menu_row .= getButton('submit', 'smaction_forward', _("Forward"), $on_click);
617 if ($enable_forward_as_attachment)
618 $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .' '."\n";
620 $menu_row .= '</form> ';
622 if ( in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
623 // Form for deletion. Form is handled by the originating display in $where. This is right_main.php or search.php
624 $delete_url = $base_uri . "src/$where";
625 $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">';
627 if (!(isset($passed_ent_id) && $passed_ent_id)) {
628 $menu_row .= addHidden('mailbox', $aMailbox['NAME']);
629 $menu_row .= addHidden('msg[0]', $passed_id);
630 $menu_row .= addHidden('startMessage', $startMessage);
631 $menu_row .= getButton('submit', 'delete', _("Delete"));
632 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
634 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
637 $menu_row .= '</form>';
641 $menu_row .= '</small></td><td align="right">';
642 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
643 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
645 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
648 addHidden('mailbox',$aMailbox['NAME']) .
649 addHidden('msg[0]', $passed_id) . _("Move to:") .
650 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
652 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
653 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
655 $menu_row .= sqimap_mailbox_option_list($imapConnection);
657 $menu_row .= '</select> ';
659 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
661 $menu_row .= '</td></tr>';
663 // echo rows, with hooks
664 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
665 if (is_array($ret)) {
666 if (isset($ret[0]) && !empty($ret[0])) {
669 if (isset($ret[1]) && !empty($ret[1])) {
673 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
674 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
675 echo '</table>'."\n";
676 do_hook('read_body_menu_bottom');
679 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
680 global $base_uri, $where, $what;
682 $urlMailbox = urlencode($mailbox);
683 $urlPassed_id = urlencode($passed_id);
684 $urlPassed_ent_id = urlencode($passed_ent_id);
686 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
688 if (!empty($where)) {
689 $query_string .= '&where=' . urlencode($where);
693 $query_string .= '&what=' . urlencode($what);
696 $url = $base_uri.'src/view_header.php?'.$query_string;
699 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ": </b></td>\n" .
700 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
701 '<a href="'.$url.'">'._("View Full Header").'</a>';
703 /* Output the printer friendly link if we are in subtle mode. */
704 $s .= ' | ' .
705 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
707 do_hook("read_body_header_right");
708 $s = "</small></td>\n" .
717 * @deprecated see form functions available in 1.5.1 and 1.4.3.
718 * @param string $type
719 * @param string $name
720 * @param string $value
722 * @param bool $enabled
724 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
725 $disabled = ( $enabled ?
'' : 'disabled ' );
726 $js = ( $js ?
$js.' ' : '' );
727 return '<input '.$disabled.$js.
731 '" style="padding: 0px; margin: 0px" />';
735 /***************************/
736 /* Main of read_body.php */
737 /***************************/
739 /* get the globals we may need */
741 sqgetGlobalVar('key', $key, SQ_COOKIE
);
742 sqgetGlobalVar('username', $username, SQ_SESSION
);
743 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
744 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
745 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
746 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
747 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
752 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
753 if (!sqgetGlobalVar('where', $where, SQ_GET
) ) {
754 $where = 'right_main.php';
757 * Used as entry key to the list of uid's cached in the mailbox cache
758 * we use the cached uid's to get the next and prev message.
760 if (!sqgetGlobalVar('what', $what, SQ_GET
) ){
763 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
764 $show_more = (int) $temp;
766 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
767 $show_more_cc = (int) $temp;
769 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
770 $show_more_bcc = (int) $temp;
772 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
773 $view_hdr = (int) $temp;
776 if ( sqgetGlobalVar('account', $temp, SQ_GET
) ) {
777 $iAccount = (int) $temp;
783 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
784 sqgetGlobalVar('mailbox', $mailbox);
786 if ( sqgetGlobalVar('passed_id', $temp) ) {
787 $passed_id = (int) $temp;
789 if ( sqgetGlobalVar('sort', $temp) ) {
792 if ( sqgetGlobalVar('startMessage', $temp) ) {
793 $startMessage = (int) $temp;
798 * Retrieve mailbox cache
800 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
802 /* end of get globals */
803 global $sqimap_capabilities, $lastTargetMailbox;
805 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
806 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
810 Start code to set the columns to fetch in case of hitting the next/prev link
811 The reason for this is the fact that the cache can be invalidated which means that the headers
812 to fetch aren't there anymore. Before they got calculated when the messagelist was shown.
814 Todo, better central handling of setting the mailbox options so we do not need to do the stuff below
818 * Replace From => To in case it concerns a draft or sent folder
820 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
821 !in_array(SQM_COL_TO
,$index_order)) {
822 $aNewOrder = array(); // nice var name ;)
823 foreach($index_order as $iCol) {
824 if ($iCol == SQM_COL_FROM
) {
827 $aNewOrder[] = $iCol;
829 $aColumns = $aNewOrder;
831 $aColumns = $index_order;
835 'columns' => $aColumns, // columns bound settings
837 'highlight_list' => $message_highlight_list, // row highlighting rules
838 'trash_folder' => $trash_folder,
839 'sent_folder' => $sent_folder,
840 'draft_folder' => $draft_folder));
842 calcFetchColumns($aMailbox,$aProps);
845 End code to set the columns to fetch in case of hitting the next/prev link
851 * Check if cache is still valid, $what contains the key
852 * which gives us acces to the array with uid's. At this moment
853 * 0 is used for a normal message list and search uses 1 as key. This can be
854 * changed / extended in the future.
855 * If on a select of a mailbox we detect that the cache should be invalidated due to
856 * the delete of messages or due to new messages we empty the list with uid's and
857 * that's what we detect below.
859 if (!is_array($aMailbox['UIDSET'][$what])) {
860 fetchMessageHeaders($imapConnection, $aMailbox);
863 $iSetIndex = $aMailbox['SETINDEX'];
864 $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id;
867 * Update the seen state
868 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
870 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
871 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
875 * Process Delete from delete-move-next
876 * but only if delete_id was set
878 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
879 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
883 * $message contains all information about the message
884 * including header and body
887 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
888 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
889 $FirstTimeSee = !$message->is_seen
;
891 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
892 $FirstTimeSee = !$message->is_seen
;
893 $message->is_seen
= true;
894 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
897 if (isset($passed_ent_id) && $passed_ent_id) {
898 $message = $message->getEntity($passed_ent_id);
899 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
900 $message = $message->parent
;
902 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
903 $rfc822_header = new Rfc822Header();
904 $rfc822_header->parseHeader($read);
905 $message->rfc822_header
= $rfc822_header;
906 } else if ($message->type0
== 'message' && $message->type1
== 'rfc822' && isset($message->entities
[0])) {
907 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE);
908 $rfc822_header = new Rfc822Header();
909 $rfc822_header->parseHeader($read);
910 $message->rfc822_header
= $rfc822_header;
914 $header = $message->header
;
916 $header = $message->header
;
919 /****************************************/
920 /* Block for handling incoming url vars */
921 /****************************************/
923 if (isset($sendreceipt)) {
924 if ( !$message->is_mdnsent
) {
925 $final_recipient = '';
926 if ((isset($identity)) && ($identity != 0)) //Main identity
927 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
928 if ($final_recipient == '' )
929 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
930 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
931 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
932 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
933 $message->is_mdnsent
= true;
934 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
938 /***********************************************/
939 /* End of block for handling incoming url vars */
940 /***********************************************/
945 do_hook('read_body_top');
946 if ($show_html_default == 1) {
947 $ent_ar = $message->findDisplayEntity(array());
949 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
951 $cnt = count($ent_ar);
952 for ($i = 0; $i < $cnt; $i++
) {
953 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
955 $messagebody .= '<hr style="height: 1px;" />';
959 displayPageHeader($color, $mailbox,'','');
960 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
961 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
962 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
964 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
966 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
967 echo ' <tr bgcolor="'.$color[4].'"><td>';
968 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
969 echo html_tag( 'table' ,'' , 'left', '', 'width="100%" cellpadding="1" cellspacing="5" border="0"' );
970 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
974 echo ' </table></td></tr>';
978 echo '<tr><td height="5" colspan="2" bgcolor="'.
979 $color[4].'"></td></tr>'."\n";
981 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
982 if ($attachmentsdisplay) {
984 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
986 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
987 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
988 echo ' <b>' . _("Attachments") . ':</b>';
991 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
992 echo $attachmentsdisplay;
993 echo ' </td></tr></table>';
994 echo ' </td></tr></table>';
996 echo '<tr><td height="5" colspan="2" bgcolor="'.
997 $color[4].'"></td></tr>';
1001 /* show attached images inline -- if pref'fed so */
1002 if (($attachment_common_show_images) &&
1003 is_array($attachment_common_show_images_list)) {
1004 foreach ($attachment_common_show_images_list as $img) {
1005 $imgurl = SM_PATH
. 'src/download.php' .
1007 'passed_id=' . urlencode($img['passed_id']) .
1008 '&mailbox=' . urlencode($mailbox) .
1009 '&ent_id=' . urlencode($img['ent_id']) .
1010 '&absolute_dl=true';
1012 echo html_tag( 'table', "\n" .
1013 html_tag( 'tr', "\n" .
1014 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
1017 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
1021 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
1023 do_hook('read_body_bottom');
1024 sqimap_logout($imapConnection);
1027 * Write mailbox with updated seen flag information back to cache.
1029 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1030 sqsession_register($mailbox_cache,'mailbox_cache');