aboutsummaryrefslogtreecommitdiffstats
path: root/worker/middleware/gmailworker.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-20 11:31:03 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-25 21:55:17 +0100
commit1980744f7bf9e147abf649d37a2fa7dddd4e7254 (patch)
treedba9967e81d4c65c287dd5c9c1e26c5f269891b7 /worker/middleware/gmailworker.go
parent3452c9233f623c4049098b66911ae82fc14e119c (diff)
downloadaerc-1980744f7bf9e147abf649d37a2fa7dddd4e7254.tar.gz
idler: improve the imap idler
Rewrite the imap idler to make it more fault tolerant and prevent hangs (and possibly short writes). Fixes: https://todo.sr.ht/~rjarry/aerc/208 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Karel Balej <balejk@matfyz.cz> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/middleware/gmailworker.go')
-rw-r--r--worker/middleware/gmailworker.go24
1 files changed, 5 insertions, 19 deletions
diff --git a/worker/middleware/gmailworker.go b/worker/middleware/gmailworker.go
index 807f7bff..f9924732 100644
--- a/worker/middleware/gmailworker.go
+++ b/worker/middleware/gmailworker.go
@@ -8,20 +8,14 @@ import (
"github.com/emersion/go-imap/client"
)
-type idler interface {
- Start()
- Stop() error
-}
-
type gmailWorker struct {
types.WorkerInteractor
mu sync.Mutex
client *client.Client
- idler idler
}
// NewGmailWorker returns an IMAP middleware for the X-GM-EXT-1 extension
-func NewGmailWorker(base types.WorkerInteractor, c *client.Client, i idler,
+func NewGmailWorker(base types.WorkerInteractor, c *client.Client,
) types.WorkerInteractor {
base.Infof("loading worker middleware: X-GM-EXT-1")
@@ -29,37 +23,30 @@ func NewGmailWorker(base types.WorkerInteractor, c *client.Client, i idler,
for iter := base; iter != nil; iter = iter.Unwrap() {
if g, ok := iter.(*gmailWorker); ok {
base.Infof("already loaded; resetting")
- err := g.reset(c, i)
+ err := g.reset(c)
if err != nil {
base.Errorf("reset failed: %v", err)
}
return base
}
}
- return &gmailWorker{WorkerInteractor: base, client: c, idler: i}
+ return &gmailWorker{WorkerInteractor: base, client: c}
}
func (g *gmailWorker) Unwrap() types.WorkerInteractor {
return g.WorkerInteractor
}
-func (g *gmailWorker) reset(c *client.Client, i idler) error {
+func (g *gmailWorker) reset(c *client.Client) error {
g.mu.Lock()
defer g.mu.Unlock()
g.client = c
- g.idler = i
return nil
}
func (g *gmailWorker) ProcessAction(msg types.WorkerMessage) types.WorkerMessage {
- switch msg := msg.(type) {
- case *types.FetchMessageHeaders:
+ if msg, ok := msg.(*types.FetchMessageHeaders); ok && len(msg.Uids) > 0 {
g.mu.Lock()
- err := g.idler.Stop()
- if err != nil {
- g.Errorf("idler reported an error: %v", err)
- break
- }
handler := xgmext.NewHandler(g.client)
uids, err := handler.FetchEntireThreads(msg.Uids)
@@ -71,7 +58,6 @@ func (g *gmailWorker) ProcessAction(msg types.WorkerMessage) types.WorkerMessage
msg.Uids = uids
}
- g.idler.Start()
g.mu.Unlock()
}
return g.WorkerInteractor.ProcessAction(msg)