aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch/worker.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-05-30 07:34:18 -0500
committerRobin Jarry <robin@jarry.cc>2022-05-31 14:32:51 +0200
commit2551dd1bfa2c68a6ba8644a0c45b24fce8874674 (patch)
treeed752720e1a08708505fd9574b49629d5df84997 /worker/notmuch/worker.go
parent30d57889741cfa8284eec9b32b29144fe01002a2 (diff)
downloadaerc-2551dd1bfa2c68a6ba8644a0c45b24fce8874674.tar.gz
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 <tim@timculverhouse.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/notmuch/worker.go')
-rw-r--r--worker/notmuch/worker.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 4091ea43..c1426f28 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -6,10 +6,12 @@ package notmuch
import (
"bufio"
"bytes"
+ "context"
"fmt"
"io/ioutil"
"net/url"
"os"
+ "os/exec"
"path/filepath"
"strings"
"time"
@@ -128,6 +130,9 @@ func (w *worker) handleMessage(msg types.WorkerMessage) error {
return w.handleSearchDirectory(msg)
case *types.ModifyLabels:
return w.handleModifyLabels(msg)
+ case *types.CheckMail:
+ go w.handleCheckMail(msg)
+ return nil
// not implemented, they are generally not used
// in a notmuch based workflow
@@ -616,3 +621,24 @@ func (w *worker) sort(uids []uint32,
}
return sortedUids, nil
}
+
+func (w *worker) handleCheckMail(msg *types.CheckMail) {
+ ctx, cancel := context.WithTimeout(context.Background(), msg.Timeout)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, "sh", "-c", msg.Command)
+ ch := make(chan error)
+ go func() {
+ err := cmd.Run()
+ ch <- err
+ }()
+ select {
+ case <-ctx.Done():
+ w.err(msg, fmt.Errorf("checkmail: timed out"))
+ case err := <-ch:
+ if err != nil {
+ w.err(msg, fmt.Errorf("checkmail: error running command: %v", err))
+ } else {
+ w.done(msg)
+ }
+ }
+}