aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-06-21 22:13:01 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-22 10:55:25 +0200
commit697b56b6d3071aab78a3b81114ba39618b59848f (patch)
treeb355c44c3d1f5bb295b2f31c2655a3fdd6854f0c /worker/imap
parent0fc5ffb260f764f2e7313506aa0f73ad98cbea40 (diff)
downloadaerc-697b56b6d3071aab78a3b81114ba39618b59848f.tar.gz
worker: add WorkerInteractor interface
Add a WorkerInteractor interface. Avoid exposing any public fields in the types.Worker. This will set the stage to implement a middleware pattern for the workers, i.e. to map folder names between the ui and the backend. 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')
-rw-r--r--worker/imap/checkmail.go2
-rw-r--r--worker/imap/configure.go1
-rw-r--r--worker/imap/connect.go2
-rw-r--r--worker/imap/worker.go3
4 files changed, 5 insertions, 3 deletions
diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go
index b457dc4c..ae20a5b8 100644
--- a/worker/imap/checkmail.go
+++ b/worker/imap/checkmail.go
@@ -31,7 +31,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) {
}
default:
for _, dir := range msg.Directories {
- if len(w.worker.Actions) > 0 {
+ if len(w.worker.Actions()) > 0 {
remaining = append(remaining, dir)
continue
}
diff --git a/worker/imap/configure.go b/worker/imap/configure.go
index 1581794f..783485a7 100644
--- a/worker/imap/configure.go
+++ b/worker/imap/configure.go
@@ -12,6 +12,7 @@ import (
)
func (w *IMAPWorker) handleConfigure(msg *types.Configure) error {
+ w.config.name = msg.Config.Name
u, err := url.Parse(msg.Config.Source)
if err != nil {
return err
diff --git a/worker/imap/connect.go b/worker/imap/connect.go
index 84d69fe5..818952ac 100644
--- a/worker/imap/connect.go
+++ b/worker/imap/connect.go
@@ -82,7 +82,7 @@ func (w *IMAPWorker) connect() (*client.Client, error) {
}
} else if w.config.xoauth2.Enabled {
if err := w.config.xoauth2.Authenticate(
- username, password, w.worker.Name, c); err != nil {
+ username, password, w.config.name, c); err != nil {
return nil, err
}
} else if err := c.Login(username, password); err != nil {
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index dc1891ca..d30140a1 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -38,6 +38,7 @@ type imapClient struct {
}
type imapConfig struct {
+ name string
scheme string
insecure bool
addr string
@@ -290,7 +291,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
func (w *IMAPWorker) Run() {
for {
select {
- case msg := <-w.worker.Actions:
+ case msg := <-w.worker.Actions():
msg = w.worker.ProcessAction(msg)
if err := w.handleMessage(msg); errors.Is(err, errUnsupported) {