From 8018757b75262d009bc6611be76bf4696d549caa Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Sun, 15 Mar 2009 20:00:02 +0000 Subject: Change-set to let the IMAP server do the sensible sorting of threads i.e. sort threads by newest in-thread messages rather than simply by the root thread message. --- roundcubemail/program/include/rcube_imap.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'roundcubemail/program/include') diff --git a/roundcubemail/program/include/rcube_imap.php b/roundcubemail/program/include/rcube_imap.php index 2f3a49cb1..b8c44fcae 100644 --- a/roundcubemail/program/include/rcube_imap.php +++ b/roundcubemail/program/include/rcube_imap.php @@ -48,8 +48,8 @@ class rcube_imap var $mailbox = 'INBOX'; var $list_page = 1; var $page_size = 10; - var $sort_field = 'date'; - var $sort_order = 'DESC'; + var $sort_field = NULL; + var $sort_order = NULL; var $delimiter = NULL; var $caching_enabled = FALSE; var $thread_caching_enabled = FALSE; @@ -545,7 +545,7 @@ class rcube_imap if ($sql_arr = $this->db->fetch_array($sql_result)) return $sql_arr[0]; } - list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, $mailbox, 'REFERENCES', 'ALL'); + list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, $mailbox, rcmail::get_instance()->config->get('imap_thread_algorithm'), 'ALL'); $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children); return count($thread_tree); } @@ -620,7 +620,7 @@ class rcube_imap $msg_depth = $this->cache['__threads']['depth']; $has_children = $this->cache['__threads']['has_children']; } else { - list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, $mailbox, 'REFERENCES', 'ALL'); + list ($thread_tree, $msg_depth, $has_children) = iil_C_Thread($this->conn, $mailbox, rcmail::get_instance()->config->get('imap_thread_algorithm'), 'ALL'); } $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children); // the keys of thread_tree are the thread roots @@ -640,6 +640,8 @@ class rcube_imap // sort the roots according to the order defined by $sort_index $sorter = new rcube_thread_root_sorter(); $sorter->set_sequence_numbers($sort_index); + if (isset($this->sort_order)) + $sorter->default_sort = false; $sorter->sort_threads($roots); // get the roots for this page @@ -647,7 +649,7 @@ class rcube_imap } if ($thread_cache_status > 0) { - // get the children of $roots from the cache + // get the children of $roots from the cache $threads = $this->get_thread_cache_threads($mailbox, $roots); $msg_index = array (); $msg_depth = array (); @@ -3528,6 +3530,11 @@ class rcube_thread_root_sorter { var $sequence_numbers = array (); + // If this is true then we override any sorting + // and let the IMAP server do it, otherwise try + // to sort according to the user request. + var $default_sort = true; + /** * Set the predetermined sort order. * @@ -3545,6 +3552,12 @@ class rcube_thread_root_sorter */ function sort_threads(& $threads) { + if ($this->default_sort) + { + $threads = array_reverse($threads); + return; + } + usort($threads, array ( $this, "compare_seqnums" -- cgit v1.2.3