aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/configure.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-06-21 22:13:04 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-22 10:55:25 +0200
commit626d118a31d6cb36900e67b93d535434aea75cb3 (patch)
tree445b473f62e1d629b94fb4bdc347803d352aa2a6 /worker/imap/configure.go
parent822bd3620a456fefcdb828f2768c0677e4442f05 (diff)
downloadaerc-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/imap/configure.go')
-rw-r--r--worker/imap/configure.go22
1 files changed, 22 insertions, 0 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
}