diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-06-21 22:13:05 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-06-22 10:55:25 +0200 |
commit | dfaab1f1d73e557bbdbcc428f04f701c0c09c136 (patch) | |
tree | 84266f8b5930c29e1d6b92f29ca67aabab4aa154 /worker/maildir | |
parent | 626d118a31d6cb36900e67b93d535434aea75cb3 (diff) | |
download | aerc-dfaab1f1d73e557bbdbcc428f04f701c0c09c136.tar.gz |
maildir: add folder-map
Add the folder-map functionality to the maildir backend. If the
folder-map config option is specified, the folder-map worker middleware
is used.
Unroll the worker.PostMessageInfoError function for a streamlined
WorkerInteractor interface.
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/maildir')
-rw-r--r-- | worker/maildir/worker.go | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 46cfd472..7e75a8ca 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -1,6 +1,7 @@ package maildir import ( + "bufio" "bytes" "context" "errors" @@ -17,6 +18,7 @@ import ( "time" "github.com/emersion/go-maildir" + "github.com/mitchellh/go-homedir" aercLib "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/iterator" @@ -24,6 +26,7 @@ import ( "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/handlers" "git.sr.ht/~rjarry/aerc/worker/lib" + "git.sr.ht/~rjarry/aerc/worker/middleware" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -40,7 +43,7 @@ type Worker struct { selected *maildir.Dir selectedName string selectedInfo *models.DirectoryInfo - worker *types.Worker + worker types.WorkerInteractor watcher types.FSWatcher watcherDebounce *time.Timer fsEvents chan struct{} @@ -355,6 +358,24 @@ func (w *Worker) handleConfigure(msg *types.Configure) error { w.headers = msg.Config.Headers w.headersExclude = msg.Config.HeadersExclude w.worker.Debugf("configured base maildir: %s", dir) + + 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 } @@ -634,7 +655,16 @@ func (w *Worker) handleFetchMessageHeaders( info, err := w.msgInfoFromUid(uid) if err != nil { w.worker.Errorf("could not get message info: %v", err) - w.worker.PostMessageInfoError(msg, uid, err) + log.Errorf("could not get message info: %v", err) + w.worker.PostMessage(&types.MessageInfo{ + Info: &models.MessageInfo{ + Envelope: &models.Envelope{}, + Flags: models.SeenFlag, + Uid: uid, + Error: err, + }, + Message: types.RespondTo(msg), + }, nil) continue } switch { |