Skip to content

Commit

Permalink
fix imap sorting - apply the sorting server-side even after searching…
Browse files Browse the repository at this point in the history
…; disable front-size sorting in imap folders as sort dropdown has different meaning and results are already sorted server-side
  • Loading branch information
kroky committed Jul 23, 2024
1 parent 3d7022f commit 103e98f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 103e98f

Please sign in to comment.