imap: only restrict list-status to a single directory when we can

rjarry mentioned on IRC that my e4b38efb29
commit was a bit too brutal, and regressed check-mail (checking only the
current directory instead of all).

This patch improves it by continuing to use "" as ref for LIST-STATUS
unless CheckMail.Directories contains a single directory, in which case
it uses it as ref.

This keeps most of the performance benefits (since we usually have at
most one directory to check when navigating between folders) without
regressing in terms of functionality (in particular I've checked that
check-mail does look at and updates *all* folders, not only the current
one).

Signed-off-by: Simon Martin <simon@nasilyan.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Simon Martin
2025-04-01 07:55:20 +00:00
committed by Robin Jarry
parent c9a57f76bf
commit 96603ea04e

View File

@@ -21,7 +21,12 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) {
switch {
case w.liststatus:
w.worker.Tracef("Checking mail with LIST-STATUS")
statuses, err = w.client.liststatus.ListStatus(w.client.Mailbox().Name, "*", items, nil)
ref := ""
if len(msg.Directories) == 1 {
// If checking a single directory, restrict the ListStatus to it.
ref = msg.Directories[0]
}
statuses, err = w.client.liststatus.ListStatus(ref, "*", items, nil)
if err != nil {
w.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),