diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-11-28 21:15:37 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-02 22:59:44 +0100 |
commit | ec04654bd52a24ea7c5c0a22a465d3244df1e511 (patch) | |
tree | 8a7011a37d96aa0e5a6ee8cac190ad8a7944f652 /worker | |
parent | 32b9653ea705d512614b351da7bae95773e7eb6e (diff) | |
download | aerc-ec04654bd52a24ea7c5c0a22a465d3244df1e511.tar.gz |
imap: use list-status for list-directories if available
Use the LIST-STATUS extension when listing directories. This enables the
UI to show message counts for every mailbox, in a similar behavior to
the maildir and notmuch backends.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/list.go | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/worker/imap/list.go b/worker/imap/list.go index a03468ab..04e6c39b 100644 --- a/worker/imap/list.go +++ b/worker/imap/list.go @@ -32,14 +32,54 @@ func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) { done <- nil }() - err := imapw.client.List("", "*", mailboxes) - if err != nil { - <-done - imapw.worker.PostMessage(&types.Error{ - Message: types.RespondTo(msg), - Error: err, - }, nil) - return + switch { + case imapw.liststatus: + items := []imap.StatusItem{ + imap.StatusMessages, + imap.StatusRecent, + imap.StatusUnseen, + } + statuses, err := imapw.client.liststatus.ListStatus( + "", + "*", + items, + mailboxes, + ) + if err != nil { + <-done + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + return + + } + for _, status := range statuses { + imapw.worker.PostMessage(&types.DirectoryInfo{ + Info: &models.DirectoryInfo{ + Flags: status.Flags, + Name: status.Name, + ReadOnly: status.ReadOnly, + AccurateCounts: true, + + Exists: int(status.Messages), + Recent: int(status.Recent), + Unseen: int(status.Unseen), + Caps: imapw.caps, + }, + SkipSort: true, + }, nil) + } + default: + err := imapw.client.List("", "*", mailboxes) + if err != nil { + <-done + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + return + } } <-done imapw.worker.PostMessage( |