From 626d118a31d6cb36900e67b93d535434aea75cb3 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 21 Jun 2023 22:13:04 +0200 Subject: 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 Tested-by: Bence Ferdinandy Signed-off-by: Robin Jarry --- worker/imap/configure.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'worker/imap/configure.go') 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 } -- cgit