diff --git a/CHANGELOG b/CHANGELOG index 320621d54..2fae40860 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ CHANGELOG Roundcube Webmail - Fix bug where Next/Prev button in mail view didn't work with multi-folder search result (#6793) - Fix bug where selection of columns on messages list wasn't working - Fix bug in converting multi-page Tiff images to Jpeg (#6824) +- Fix wrong messages order after returning to a multi-folder search result (#6836) RELEASE 1.3.9 ------------- diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 2dcf31576..e0b469e94 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -1056,8 +1056,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; } @@ -1067,6 +1069,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) {