diff --git a/modules/core/site.js b/modules/core/site.js index 04f45c3faf..90474018b3 100644 --- a/modules/core/site.js +++ b/modules/core/site.js @@ -601,7 +601,8 @@ function Message_List() { } }); } - if (element) { + // apply JS pagination only on aggregate folders; imap ones already have the messages sorted + if (hm_list_path().substring(0, 5) != 'imap_' && element) { $(row, msg_rows).insertBefore(element); } else { diff --git a/modules/imap/hm-imap.php b/modules/imap/hm-imap.php index b5098446a2..15b63ec729 100644 --- a/modules/imap/hm-imap.php +++ b/modules/imap/hm-imap.php @@ -1008,6 +1008,7 @@ public function search($target='ALL', $uids=false, $terms=array(), $esearch=arra } } } + $original_uids_order = $uids; if (!empty($uids)) { if (is_array($uids)) { $uids = implode(',', $uids); @@ -1088,6 +1089,17 @@ public function search($target='ALL', $uids=false, $terms=array(), $esearch=arra if ($esearch_enabled) { $res = $esearch_res; } + // keep original sort order of UIDS as fetch command might not return in requested order + // this is needed for pagination to work + if (! empty($original_uids_order)) { + $unordered = $res; + $res = []; + foreach ($original_uids_order as $uid) { + if (in_array($uid, $unordered)) { + $res[] = $uid; + } + } + } return $this->cache_return_val($res, $cache_command); } return $res;