From 35b0a75f72ef1c7c83bf2ad8ba01f6ac1a444122 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 13 Jun 2013 02:23:11 -0400
Subject: [PATCH] Fix default sorting of threaded list when THREAD=REFS isn't supported. The result need to be re-sorted even if sort column is not set. This fixes the issue when new messages aren't displayed on top of the list.

---
 CHANGELOG                            |    1 +
 program/lib/Roundcube/rcube_imap.php |   11 +++++------
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index a0d0a61..a882c39 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix default sorting of threaded list when THREAD=REFS isn't supported
 - Fix list mode switch to 'List' after saving list settings in Larry skin (#1489164)
 - Fix error when there's no writeable addressbook source (#1489162)
 - Fix zipdownload plugin issue with filenames charset (#1489156)
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index b68c3d3..a323a84 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -1336,17 +1336,16 @@
         // THREAD=REFERENCES:     sorting by sent date of root message
         // THREAD=REFS:           sorting by the most recent date in each thread
 
-        if ($this->sort_field && ($this->sort_field != 'date' || $this->get_capability('THREAD') != 'REFS')) {
-            $index = $this->index_direct($this->folder, $this->sort_field, $this->sort_order, false);
+        if ($this->get_capability('THREAD') != 'REFS') {
+            $sortby = $this->sort_field ? $this->sort_field : 'date';
+            $index  = $this->index_direct($this->folder, $sortby, $this->sort_order, false);
 
             if (!$index->is_empty()) {
                 $threads->sort($index);
             }
         }
-        else {
-            if ($this->sort_order != $threads->get_parameters('ORDER')) {
-                $threads->revert();
-            }
+        else if ($this->sort_order != $threads->get_parameters('ORDER')) {
+            $threads->revert();
         }
     }
 

--
Gitblit v1.9.1