diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-11-28 21:15:38 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-02 22:59:44 +0100 |
commit | 17718981c5d1db0775407d45f83dcd026758ab47 (patch) | |
tree | 4d44e7d7739feadfead8d2378e772dcf7c451cee /worker/imap | |
parent | ec04654bd52a24ea7c5c0a22a465d3244df1e511 (diff) | |
download | aerc-17718981c5d1db0775407d45f83dcd026758ab47.tar.gz |
imap: use list-status for check-mail
Use list-status to perform check-mail commands, if it is available. This
provides a significant performance benefit by only requiring one IMAP
command vs one command for each mailbox.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/imap')
-rw-r--r-- | worker/imap/checkmail.go | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go index 34cf63d1..8f9e1b2b 100644 --- a/worker/imap/checkmail.go +++ b/worker/imap/checkmail.go @@ -13,36 +13,55 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { imap.StatusRecent, imap.StatusUnseen, } - var remaining []string - for _, dir := range msg.Directories { - if len(w.worker.Actions) > 0 { - remaining = append(remaining, dir) - continue - } - - log.Tracef("Getting status of directory %s", dir) - status, err := w.client.Status(dir, items) + var ( + statuses []*imap.MailboxStatus + err error + remaining []string + ) + switch { + case w.liststatus: + log.Tracef("Checking mail with LIST-STATUS") + statuses, err = w.client.liststatus.ListStatus("", "*", items, nil) if err != nil { w.worker.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, }, nil) - } else { - w.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: w.caps, - }, - SkipSort: true, - }, nil) + return } + default: + for _, dir := range msg.Directories { + if len(w.worker.Actions) > 0 { + remaining = append(remaining, dir) + continue + } + log.Tracef("Getting status of directory %s", dir) + status, err := w.client.Status(dir, items) + if err != nil { + w.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + continue + } + statuses = append(statuses, status) + } + } + for _, status := range statuses { + w.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: w.caps, + }, + SkipSort: true, + }, nil) } if len(remaining) > 0 { w.worker.PostMessage(&types.CheckMailDirectories{ |