~migadu/alps-devel

alps: plugins/base: sort search results by date v1 APPLIED

~koukas: 1
 plugins/base: sort search results by date

 1 files changed, 21 insertions(+), 5 deletions(-)
#1036875 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~migadu/alps-devel/patches/43402/mbox | git am -3
Learn more about email & git

[PATCH alps] plugins/base: sort search results by date Export this patch

From: Konstantinos Koukas <contact@koukas.org>

Implement server-side sorting of search results using the SORT
extension to IMAP, if the server supports it. Otherwise, fall back to
the unordered SEARCH command.

Sort messages by sent date, in descending order.
---
 plugins/base/imap.go | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index 8ea88e9..efa1de3 100644
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -471,12 +471,28 @@ func searchMessages(conn *imapclient.Client, mboxName, query string, page, messa
		return nil, 0, err
	}

	criteria := PrepareSearch(query)
	data, err := conn.Search(criteria, nil).Wait()
	if err != nil {
		return nil, 0, fmt.Errorf("UID SEARCH failed: %v", err)
	searchCriteria := PrepareSearch(query)
	var nums []uint32

	if !conn.Caps().Has(imap.CapSort) {
		data, err := conn.Search(searchCriteria, nil).Wait()
		if err != nil {
			return nil, 0, fmt.Errorf("UID SEARCH failed: %v", err)
		}
		nums = data.AllNums()
	} else {
		sortOptions := &imapclient.SortOptions{
			SearchCriteria: searchCriteria,
			SortCriteria: []imapclient.SortCriterion{
				{Key: imapclient.SortKeyDate, Reverse: true},
			},
		}
		nums, err = conn.Sort(sortOptions).Wait()
		if err != nil {
			return nil, 0, fmt.Errorf("SORT failed: %v", err)
		}
	}
	nums := data.AllNums()

	total = len(nums)

	from := page * messagesPerPage
-- 
2.38.5
alps/patches/.build.yml: SUCCESS in 1m17s

[plugins/base: sort search results by date][0] from [~koukas][1]

[0]: https://lists.sr.ht/~migadu/alps-devel/patches/43402
[1]: mailto:contact@koukas.org

✓ #1036875 SUCCESS alps/patches/.build.yml https://builds.sr.ht/~migadu/job/1036875
Shouldn't we use UIDSort instead of Sort?

Apart from this, sounds good.