aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-06-21 22:13:05 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-22 10:55:25 +0200
commitdfaab1f1d73e557bbdbcc428f04f701c0c09c136 (patch)
tree84266f8b5930c29e1d6b92f29ca67aabab4aa154 /worker
parent626d118a31d6cb36900e67b93d535434aea75cb3 (diff)
downloadaerc-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')
-rw-r--r--worker/maildir/worker.go34
-rw-r--r--worker/mbox/worker.go12
-rw-r--r--worker/notmuch/worker.go16
-rw-r--r--worker/types/worker.go14
4 files changed, 56 insertions, 20 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 {
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index 5034f66d..8ed04e05 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -162,8 +162,16 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
}
msgInfo, err := messageInfo(m, true)
if err != nil {
- w.worker.PostMessageInfoError(msg, uid, err)
- break
+ w.worker.PostMessage(&types.MessageInfo{
+ Info: &models.MessageInfo{
+ Envelope: &models.Envelope{},
+ Flags: models.SeenFlag,
+ Uid: uid,
+ Error: err,
+ },
+ Message: types.RespondTo(msg),
+ }, nil)
+ continue
} else {
switch {
case len(w.headersExclude) > 0:
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 70dca1e2..1e5f4c2d 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -387,13 +387,13 @@ func (w *worker) handleFetchMessageHeaders(
m, err := w.msgFromUid(uid)
if err != nil {
w.w.Errorf("could not get message: %v", err)
- w.w.PostMessageInfoError(msg, uid, err)
+ w.emitMessageInfoError(msg, uid, err)
continue
}
err = w.emitMessageInfo(m, msg)
if err != nil {
w.w.Errorf("could not emit message info: %v", err)
- w.w.PostMessageInfoError(msg, uid, err)
+ w.emitMessageInfoError(msg, uid, err)
continue
}
}
@@ -684,6 +684,18 @@ func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error {
return nil
}
+func (w *worker) emitMessageInfoError(msg types.WorkerMessage, uid uint32, err error) {
+ w.w.PostMessage(&types.MessageInfo{
+ Info: &models.MessageInfo{
+ Envelope: &models.Envelope{},
+ Flags: models.SeenFlag,
+ Uid: uid,
+ Error: err,
+ },
+ Message: types.RespondTo(msg),
+ }, nil)
+}
+
func (w *worker) emitMessageInfo(m *Message,
parent types.WorkerMessage,
) error {
diff --git a/worker/types/worker.go b/worker/types/worker.go
index 663ac067..f57f9fc3 100644
--- a/worker/types/worker.go
+++ b/worker/types/worker.go
@@ -162,20 +162,6 @@ func (worker *Worker) ProcessAction(msg WorkerMessage) WorkerMessage {
return msg
}
-// PostMessageInfoError posts a MessageInfo message to the worker when an
-// error was encountered fetching the message header
-func (worker *Worker) PostMessageInfoError(msg WorkerMessage, uid uint32, err error) {
- worker.PostMessage(&MessageInfo{
- Info: &models.MessageInfo{
- Envelope: &models.Envelope{},
- Flags: models.SeenFlag,
- Uid: uid,
- Error: err,
- },
- Message: RespondTo(msg),
- }, nil)
-}
-
func (worker *Worker) PathSeparator() string {
return worker.Backend.PathSeparator()
}