diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-06-21 22:13:04 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-06-22 10:55:25 +0200 |
commit | 626d118a31d6cb36900e67b93d535434aea75cb3 (patch) | |
tree | 445b473f62e1d629b94fb4bdc347803d352aa2a6 /worker | |
parent | 822bd3620a456fefcdb828f2768c0677e4442f05 (diff) | |
download | aerc-626d118a31d6cb36900e67b93d535434aea75cb3.tar.gz |
imap: add folder-map
Add the folder-map functionality to the imap backend. If the folder-map
config option is specified, the folder-map worker middleware is used.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/configure.go | 22 | ||||
-rw-r--r-- | worker/imap/idler.go | 4 | ||||
-rw-r--r-- | worker/imap/observer.go | 4 | ||||
-rw-r--r-- | worker/imap/worker.go | 2 |
4 files changed, 27 insertions, 5 deletions
diff --git a/worker/imap/configure.go b/worker/imap/configure.go index 783485a7..94b5ac60 100644 --- a/worker/imap/configure.go +++ b/worker/imap/configure.go @@ -1,13 +1,18 @@ package imap import ( + "bufio" "fmt" "net/url" + "os" "strconv" "strings" "time" + "git.sr.ht/~rjarry/aerc/worker/lib" + "git.sr.ht/~rjarry/aerc/worker/middleware" "git.sr.ht/~rjarry/aerc/worker/types" + "github.com/mitchellh/go-homedir" "golang.org/x/oauth2" ) @@ -158,5 +163,22 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { w.idler = newIdler(w.config, w.worker) w.observer = newObserver(w.config, w.worker) + if name, ok := msg.Config.Params["folder-map"]; ok { + file, err := homedir.Expand(name) + if err != nil { + return err + } + f, err := os.Open(file) + if err != nil { + return err + } + defer f.Close() + fmap, order, err := lib.ParseFolderMap(bufio.NewReader(f)) + if err != nil { + return err + } + w.worker = middleware.NewFolderMapper(w.worker, fmap, order) + } + return nil } diff --git a/worker/imap/idler.go b/worker/imap/idler.go index 30600764..aa61776d 100644 --- a/worker/imap/idler.go +++ b/worker/imap/idler.go @@ -24,14 +24,14 @@ type idler struct { sync.Mutex config imapConfig client *imapClient - worker *types.Worker + worker types.WorkerInteractor stop chan struct{} done chan error waiting bool idleing bool } -func newIdler(cfg imapConfig, w *types.Worker) *idler { +func newIdler(cfg imapConfig, w types.WorkerInteractor) *idler { return &idler{config: cfg, worker: w, done: make(chan error)} } diff --git a/worker/imap/observer.go b/worker/imap/observer.go index 1c481bed..7367ff58 100644 --- a/worker/imap/observer.go +++ b/worker/imap/observer.go @@ -18,14 +18,14 @@ type observer struct { sync.Mutex config imapConfig client *imapClient - worker *types.Worker + worker types.WorkerInteractor done chan struct{} autoReconnect bool retries int running bool } -func newObserver(cfg imapConfig, w *types.Worker) *observer { +func newObserver(cfg imapConfig, w types.WorkerInteractor) *observer { return &observer{config: cfg, worker: w, done: make(chan struct{})} } diff --git a/worker/imap/worker.go b/worker/imap/worker.go index d30140a1..f08c0ec9 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -66,7 +66,7 @@ type IMAPWorker struct { client *imapClient selected *imap.MailboxStatus updates chan client.Update - worker *types.Worker + worker types.WorkerInteractor seqMap SeqMap delimiter string |