diff options
author | Karel Balej <balejk@matfyz.cz> | 2024-01-30 20:11:27 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-02-12 22:58:40 +0100 |
commit | 3553e4f27165b18be84123d0ca015a019d35e41c (patch) | |
tree | 7c007d4bc65e242d65f0bb2a8ba1a99f7a7bb4ad /lib/send/jmap.go | |
parent | 324e620c5a62fee07970c436f792c7383a3fb1e5 (diff) | |
download | aerc-3553e4f27165b18be84123d0ca015a019d35e41c.tar.gz |
send: move code to lib for reuse
Move the code which handles the preparation of a sender into which the
message can be written into lib to allow for reuse. Also hide the
sending backend a bit more from the `:send` command code by introducing
a NewSender function which determines which backend should be used and
invokes the appropriate sender factory function.
Rename send() to sendHelper() to avoid collision.
Signed-off-by: Karel Balej <balejk@matfyz.cz>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/send/jmap.go')
-rw-r--r-- | lib/send/jmap.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/send/jmap.go b/lib/send/jmap.go new file mode 100644 index 00000000..9682629e --- /dev/null +++ b/lib/send/jmap.go @@ -0,0 +1,40 @@ +package send + +import ( + "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, +) (io.WriteCloser, error) { + var writer io.WriteCloser + done := make(chan error) + + worker.PostAction( + &types.StartSendingMessage{From: from, Rcpts: rcpts}, + 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 +} |