+ if ($mbxresponse['EXISTS'] == 0) {
+ $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
+ echo ' <tr><td>';
+ echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
+ echo ' <tr><td><br />';
+ echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
+ echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
+ . '</tr>';
+ echo ' </table>';
+ echo ' <br /></td></tr>';
+ echo ' </table></td></tr>';
+ echo ' </table>';
+ return;
+ }
+
+ if ($mbxresponse['EXISTS'] > 0) {
+ /* if $start_msg is lower than $num_msgs, we probably deleted all messages
+ * in the last page. We need to re-adjust the start_msg
+ */
+
+ if($start_msg > $num_msgs) {
+ $start_msg -= $show_num;
+ if($start_msg < 1) {
+ $start_msg = 1;
+ }
+ }
+
+ /* This code and the next if() block check for
+ * server-side sorting methods. The $id array is
+ * formatted and $sort is set to 6 to disable
+ * SM internal sorting
+ */
+
+ if ($thread_sort_messages == 1) {
+ $mode = 'thread';
+ } else if ($allow_server_sort == 1) {
+ $mode = 'server_sort';
+ } else {
+ $mode = '';
+ }
+
+ if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
+ $id = $mbxresponse['SORT_ARRAY'];
+ if (sqsession_is_registered('msgs')) {
+ sqsession_unregister('msgs');
+ }
+ $id_slice = array_slice($id,$start_msg-1, $show_num);
+ if (count($id_slice)) {
+ $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$show_num);
+ } else {
+ return false;
+ }
+ sqsession_register($msgs, 'msgs');
+ } else {
+ if (sqsession_is_registered('server_sort_array')) {
+ sqsession_unregister('server_sort_array');
+ }
+ $id = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
+ if ($id !== false) {
+ sqsession_register($id, 'server_sort_array');
+ $id_slice = array_slice($id,$start_msg-1, $show_num);
+ if (count($id_slice)) {
+ $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$show_num);
+ } else {
+ return false;
+ }
+ sqsession_register($msgs, 'msgs');
+ } else {
+ echo $error;
+ return false;
+ }
+
+ }
+ } /* if exists > 0 */
+
+ $res = getEndMessage($start_msg, $show_num, $num_msgs);
+ $start_msg = $res[0];
+ $end_msg = $res[1];
+
+ $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
+ $num_msgs, $show_num, $sort);
+
+ $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
+
+ do_hook('mailbox_index_before');
+?>
+<table border="0" width="100%" cellpadding="0" cellspacing="0">
+<tr>
+ <td>
+ <?php mail_message_listing_beginning($imapConnection, $mbxresponse, $mailbox, $sort,
+ $msg_cnt_str, $paginator_str, $start_msg); ?>
+ </td>
+</tr>
+<tr><td height="5" bgcolor="<?php echo $color[4]; ?>"></td></tr>
+<tr>
+ <td>
+ <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[9]; ?>">
+ <tr>
+ <td>
+ <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[5]; ?>">
+ <tr>
+ <td>
+ <?php
+ printHeader($mailbox, $sort, $color, !$thread_sort_messages, $start_msg);
+ displayMessageArray($imapConnection, $num_msgs, $start_msg,
+ $id, $msgs, $mailbox, $sort, $show_num,0,0);
+ ?>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <?php
+ mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
+ ?>
+ </td>
+</tr>
+</table>
+<?php
+ //$t = elapsed($start);
+ //echo("elapsed time = $t seconds\n");
+}
+
+
+/**
+* Generic function to convert the msgs array into an HTML table.
+*
+* @param resource $imapConnection
+* @param int $num_msgs total number of messages in the mailbox
+* @param int $start_msg offset in messages to sisplay
+* @param array $msort sorted array which is used to map the index to the unsorted $msgs index
+* @param string $mailbox mail folder name
+* @param int $sort sort order. 6 means no sorting or server side / thread sort
+* @param array $color
+* @param int $show_num number of messages to show
+* @param mixed $where
+* @param mixed $what
+*/
+
+// fix me:
+// $color not used
+// remove thread stuff
+// remove $msgs global and add it as argument (i hate globals)
+function displayMessageArray($imapConnection, $num_msgs, $start_msg,
+ $id, $msgs, $mailbox, $sort,
+ $show_num, $where=0, $what=0) {
+
+ // if client side sorting and no sort we only fetch num_msgs so the start_msg in the $msgs
+ // array must be corrected
+ $i = $start_msg -1;
+
+ /*
+ * Loop through and display the info for each message.
+ * ($t is used for the checkbox number)
+ */
+
+ $iEnd = $i + $show_num;
+ for ($j=$i,$t=0;$j<$iEnd;++$j) {
+ if (isset($id[$j])) {
+ $last = (isset($id[$j+1]) || $j == $iEnd) ? false : true;
+ $msg = $msgs[$id[$j]];
+ printMessageInfo($t, $last, $msg, $mailbox,
+ $start_msg, $where, $what);
+ ++$t;
+ } else {
+ break;
+ }