From 786bde62f2a296a3fb100fead8ffa1a29bc55778 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 14 Jul 2019 15:06:24 +0200 Subject: [PATCH] Fix wrong messages order after returning to a multi-folder search result (#6836) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_imap.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 23f0bc4e1..d48c0d0ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -71,6 +71,7 @@ CHANGELOG Roundcube Webmail - Fix bug in converting multi-page Tiff images to Jpeg (#6824) - Fix bug where handling multiple messages from multi-folder search result could not work (#6845) - Fix bug where unread count wasn't updated after moving multi-folder result (#6846) +- Fix wrong messages order after returning to a multi-folder search result (#6836) RELEASE 1.4-rc1 --------------- diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 3b408e99c..b81cf4d07 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -1103,8 +1103,10 @@ class rcube_imap extends rcube_storage } // slice resultset first... + $index = array_slice($search_set->get(), $from, $slice_length); $fetch = array(); - foreach (array_slice($search_set->get(), $from, $slice_length) as $msg_id) { + + foreach ($index as $msg_id) { list($uid, $folder) = explode('-', $msg_id, 2); $fetch[$folder][] = $uid; } @@ -1114,6 +1116,11 @@ class rcube_imap extends rcube_storage foreach ($fetch as $folder => $a_index) { $a_msg_headers = array_merge($a_msg_headers, array_values($this->fetch_headers($folder, $a_index))); } + + // Re-sort the result according to the original search set order + usort($a_msg_headers, function($a, $b) use ($index) { + return array_search($a->uid . '-' . $a->folder, $index) - array_search($b->uid . '-' . $b->folder, $index); + }); } if ($slice) {