Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cypht search shows latest results when searching in a mail box #765

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ function filter_message_part($vals) {
}}

/**
* Sort callback to sort by internal date
* Sort callback to sort by internal date from most recent to oldest
* @subpackage imap/functions
* @param array $a first message detail
* @param array $b second message detail
Expand All @@ -701,7 +701,7 @@ function filter_message_part($vals) {
if (!hm_exists('sort_by_internal_date')) {
function sort_by_internal_date($a, $b) {
if ($a['internal_date'] == $b['internal_date']) return 0;
return (strtotime($a['internal_date']) < strtotime($b['internal_date']))? -1 : 1;
return (strtotime($a['internal_date']) > strtotime($b['internal_date']))? -1 : 1;
}}

/**
Expand Down
8 changes: 7 additions & 1 deletion modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,13 @@ public function search($target='ALL', $uids=false, $terms=array(), $esearch=arra
if ($esearch_enabled) {
$res = $esearch_res;
}
return $this->cache_return_val($res, $cache_command);
$found_messages_uids = $this->cache_return_val($res, $cache_command);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we get all search results here? If they are paginated, sorting won't work afterwards.
Also, isn't there an IMAP command to search AND sort in one go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we get all search results here? If they are paginated, sorting won't work afterwards. Also, isn't there an IMAP command to search AND sort in one go?

According to my researches, yes: we get all of them, since the IMAP response ($status) is "OK" there.
Pagination is being processed when formatting as I observed.

Search and sort in one go with IMAP command: I'll look into this possibility and share my findings, so that you can advise.

$found_messages_list = self::get_message_list($found_messages_uids);
usort($found_messages_list, 'sort_by_internal_date');

$found_messages_sorted_uids = array_column($found_messages_list, 'uid');

return $found_messages_sorted_uids;
}
return $res;
}
Expand Down