";
-
- echo "\n\n\n |
";
-
- echo "";
- echo "";
- echo "";
- echo " Num | ";
- /** FROM HEADER **/
- echo " From";
- if ($sort == 2)
- echo " | \n";
- else if ($sort == 3)
- echo " \n";
- else
- echo " \n";
- /** DATE HEADER **/
- echo " Date";
- if ($sort == 0)
- echo " | \n";
- else if ($sort == 1)
- echo " \n";
- else
- echo " \n";
- /** SUBJECT HEADER **/
- echo " Subject\n";
- if ($sort == 4)
- echo " | \n";
- else if ($sort == 5)
- echo " \n";
- else
- echo " \n";
- echo " ";
-
- // loop through and display the info for each message.
- $t = 0; // $t is used for the checkbox number
- if ($numMessages == 0) { // if there's no messages in this folder
- echo " THIS FOLDER IS EMPTY   | ";
- } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
- $i = $startMessage - 1;
- printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
- } else {
- for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
- printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
+ }
+
+ /* 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';
+ } elseif ($allow_server_sort == 1) {
+ $mode = 'serversort';
+ } else {
+ $mode = '';
+ }
+
+ sqsession_unregister('msort');
+ sqsession_unregister('msgs');
+ switch ($mode) {
+ case 'thread':
+ $id = get_thread_sort($imapConnection);
+ $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
+ if ($msgs === false) {
+ echo '' .
+ _("Thread sorting is not supported by your IMAP server. Please report this to the system administrator.").
+ '';
+ $thread_sort_messages = 0;
+ $msort = $msgs = array();
+ } else {
+ $msort= $msgs;
+ $sort = 6;
+ }
+ break;
+ case 'serversort':
+ $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
+ $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
+ if ($msgs === false) {
+ echo '' .
+ _( "Server-side sorting is not supported by your IMAP server. Please report this to the system administrator.").
+ '';
+ $sort = $server_sort_order;
+ $allow_server_sort = FALSE;
+ $msort = $msgs = array();
+ $id = array();
+ } else {
+ $msort = $msgs;
+ $sort = 6;
+ }
+ break;
+ default:
+ if (!$use_cache) {
+ $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
+ $num_msgs, $sort, $mbxresponse);
+ $msort = calc_msort($msgs, $sort);
+ } /* !use cache */
+ break;
+ } // switch
+ sqsession_register($msort, 'msort');
+ sqsession_register($msgs, 'msgs');
+ } /* 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');
+ echo '';
+ echo '';
+
+ mail_message_listing_beginning($imapConnection, $mailbox, $sort,
+ $msg_cnt_str, $paginator_str, $start_msg);
+ echo ' | ';
+ /* line between the button area and the list */
+ echo ' | ';
+
+ echo '';
+ echo ' ';
+ echo ' ';
+ echo ' ';
+ echo '';
+ printHeader($mailbox, $srt, $color, !$thread_sort_messages);
+
+ displayMessageArray($imapConnection, $num_msgs, $start_msg,
+ $msort, $mailbox, $sort, $color, $show_num,0,0);
+ echo ' | | ';
+
+ mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
+ echo ' | ';
+ $t = elapsed($start);
+ //echo("elapsed time = $t seconds\n");
+}
+
+function calc_msort($msgs, $sort) {
+
+ /*
+ * 0 = Date (up)
+ * 1 = Date (dn)
+ * 2 = Name (up)
+ * 3 = Name (dn)
+ * 4 = Subject (up)
+ * 5 = Subject (dn)
+ */
+
+ if (($sort == 0) || ($sort == 1)) {
+ foreach ($msgs as $item) {
+ $msort[] = $item['TIME_STAMP'];
+ }
+ } elseif (($sort == 2) || ($sort == 3)) {
+ foreach ($msgs as $item) {
+ $msort[] = $item['FROM-SORT'];
+ }
+ } elseif (($sort == 4) || ($sort == 5)) {
+ foreach ($msgs as $item) {
+ $msort[] = $item['SUBJECT-SORT'];
+ }
+ } else {
+ $msort = $msgs;
+ }
+ if ($sort < 6) {
+ if ($sort % 2) {
+ asort($msort);
+ } else {
+ arsort($msort);
+ }
+ }
+ return $msort;
+}
+
+function fillMessageArray($imapConnection, $id, $count) {
+ return sqimap_get_small_header_list($imapConnection, $id);
+}
+
+
+/* Generic function to convert the msgs array into an HTML table. */
+function displayMessageArray($imapConnection, $num_msgs, $start_msg,
+ $msort, $mailbox, $sort, $color,
+ $show_num, $where=0, $what=0) {
+ global $imapServerAddress, $use_mailbox_cache, $index_order,
+ $indent_array, $thread_sort_messages, $allow_server_sort,
+ $server_sort_order, $PHP_SELF;
+
+ $res = getEndMessage($start_msg, $show_num, $num_msgs);
+ $start_msg = $res[0];
+ $end_msg = $res[1];
+
+ $urlMailbox = urlencode($mailbox);
+
+ /* get indent level for subject display */
+ if ($thread_sort_messages == 1 && $num_msgs) {
+ $indent_array = get_parent_level($imapConnection);
+ }
+
+ $real_startMessage = $start_msg;
+ if ($sort == 6) {
+ if ($end_msg - $start_msg < $show_num - 1) {
+ $end_msg = $end_msg - $start_msg + 1;
+ $start_msg = 1;
+ } else if ($start_msg > $show_num) {
+ $end_msg = $show_num;
+ $start_msg = 1;
+ }
+ }
+ $endVar = $end_msg + 1;
+
+ /*
+ * Loop through and display the info for each message.
+ * ($t is used for the checkbox number)
+ */
+ $t = 0;
+
+ /* messages display */
+
+ if (!$num_msgs) {
+ /* if there's no messages in this folder */
+ echo html_tag( 'tr',
+ html_tag( 'td',
+ " " . _("THIS FOLDER IS EMPTY") . " ",
+ 'center',
+ $color[4],
+ 'COLSPAN="' . count($index_order) . '"'
+ )
+ );
+ } elseif ($start_msg == $end_msg) {
+ /* if there's only one message in the box, handle it differently. */
+ if ($sort != 6) {
+ $i = $start_msg;
+ } else {
+ $i = 1;
+ }
+ reset($msort);
+ $k = 0;
+ do {
+ $key = key($msort);
+ next($msort);
+ $k++;
+ } while (isset ($key) && ($k < $i));
+ printMessageInfo($imapConnection, $t, true, $key, $mailbox,
+ $real_startMessage, $where, $what);
+ } else {
+ $i = $start_msg;
+ reset($msort);
+ $k = 0;
+ do {
+ $key = key($msort);
+ next($msort);
+ $k++;
+ } while (isset ($key) && ($k < $i));
+ $not_last = true;
+ do {
+ if (!$i || $i == $endVar-1) $not_last = false;
+ printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
+ $real_startMessage, $where, $what);
+ $key = key($msort);
$t++;
- }
- }
- echo " ";
-
- echo " |