From 2551dd1bfa2c68a6ba8644a0c45b24fce8874674 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 30 May 2022 07:34:18 -0500 Subject: feat: add background mail polling option for all workers Check for new mail (recent, unseen, exists counts) with an external command, or for imap with the STATUS command, at start or on reconnection and every X time duration IMAP: The selected folder is skipped, per specification. Additional config options are included for including/excluding folders explicitly. Maildir/Notmuch: An external command will be run in the background to check for new mail. An optional timeout can be used with maildir/notmuch. Default is 10s New account options: check-mail check-mail-cmd (maildir/notmuch only) check-mail-timeout (maildir/notmuch only), default 10s check-mail-include (IMAP only) check-mail-exclude (IMAP only) If unset, or set less than or equal to 0, check-mail will be ignored Signed-off-by: Tim Culverhouse Tested-by: Moritz Poldrack Acked-by: Robin Jarry --- worker/imap/checkmail.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 worker/imap/checkmail.go (limited to 'worker/imap/checkmail.go') diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go new file mode 100644 index 00000000..d9dcfd33 --- /dev/null +++ b/worker/imap/checkmail.go @@ -0,0 +1,40 @@ +package imap + +import ( + "git.sr.ht/~rjarry/aerc/models" + "git.sr.ht/~rjarry/aerc/worker/types" + "github.com/emersion/go-imap" +) + +func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { + items := []imap.StatusItem{ + imap.StatusMessages, + imap.StatusRecent, + imap.StatusUnseen, + } + for _, dir := range msg.Directories { + w.worker.Logger.Printf("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) + } 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), + }, + SkipSort: true, + }, nil) + } + } + w.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) +} -- cgit