1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2026-03-01 02:34:26 +01:00
aerc/lib/send/jmap.go
Robin Jarry 9a823672f9 messages: generalize cancellation context
Move the cancellation context from individual message types to the base
Message struct. Previously, only a few message types (OpenDirectory,
FetchDirectoryContents, FetchDirectoryThreaded, SearchDirectory,
FetchMessageHeaders, FetchMessageFlags) had a Context field, requiring
special handling in workers.

Now all worker messages carry a context through the base Message type,
set via PostAction's new first parameter. Workers access it uniformly
via the Context() method which returns context.Background() when unset.

Add a Close() method to MessageStoreView that cancels pending fetch
operations when the message viewer is closed, preventing wasted work on
messages the user is no longer viewing.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Simon Martin <simon@nasilyan.com>
2026-02-09 14:46:27 +01:00

42 lines
834 B
Go

package send
import (
"context"
"fmt"
"io"
"github.com/emersion/go-message/mail"
"git.sr.ht/~rjarry/aerc/worker/types"
)
func newJmapSender(
worker *types.Worker, from *mail.Address, rcpts []*mail.Address,
copyTo []string,
) (io.WriteCloser, error) {
var writer io.WriteCloser
done := make(chan error)
worker.PostAction(context.TODO(),
&types.StartSendingMessage{From: from, Rcpts: rcpts, CopyTo: copyTo},
func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
return
case *types.Unsupported:
done <- fmt.Errorf("unsupported by worker")
case *types.Error:
done <- msg.Error
case *types.MessageWriter:
writer = msg.Writer
default:
done <- fmt.Errorf("unexpected worker message: %#v", msg)
}
close(done)
},
)
err := <-done
return writer, err
}