From 9d0fdffeef2f4ae1f8c1b57f558e68ba4bd9ad28 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Fri, 23 Jun 2023 22:39:43 +0200 Subject: imap: only call UidSort with sort criteria Only call UidSort with some sort criteria. If we call it without, some imap severs report it as an error. For example, Fastmail imap with the sort config in aerc.conf commented out reports: "[Fastmail] unexpected error: Missing Sort criteria" and cannot display the messages. Fixes: https://lists.sr.ht/~rjarry/aerc-devel/%3C5955665f-4d1a-4295-86bd-d1a5eabd0d6d%40milic.suse.cz%3E Signed-off-by: Koni Marti Acked-by: Robin Jarry --- worker/imap/open.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worker/imap/open.go b/worker/imap/open.go index 3ad9fc9d..693d93a9 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -48,12 +48,13 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents( return } sortCriteria := translateSortCriterions(msg.SortCriteria) + hasSortCriteria := len(sortCriteria) > 0 var uids []uint32 // If the server supports the SORT extension, do the sorting server side switch { - case imapw.caps.Sort: + case imapw.caps.Sort && hasSortCriteria: uids, err = imapw.client.sort.UidSort(sortCriteria, searchCriteria) if err != nil { imapw.worker.PostMessage(&types.Error{ @@ -67,7 +68,7 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents( uids[i], uids[j] = uids[j], uids[i] } default: - if len(sortCriteria) > 0 { + if hasSortCriteria { imapw.worker.Warnf("SORT is not supported but requested: list messages by UID") } uids, err = imapw.client.UidSearch(searchCriteria) -- cgit