From f479ae8c6e550dade0f183da9d3d7760f406d806 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Sun, 23 Oct 2022 21:27:09 +0200 Subject: lib: prepare attachments for multiple reads Prepare attachments for multiple reads. The data for lib.PartAttachment is stored as an io.Reader which can only be read once. This will cause an issue when we want to call composer.WriteMessage multiple times, i.e. for a message preview. We fix this by keeping a copy of the data and create a new reader everytime the attachment is read. Signed-off-by: Koni Marti Acked-by: Robin Jarry --- commands/msg/recall.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'commands/msg/recall.go') diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 866266f5..b5c92f21 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -211,8 +211,12 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64()) } mu.Lock() - composer.AddPartAttachment(name, mime, params, reader) + err := composer.AddPartAttachment(name, mime, params, reader) mu.Unlock() + if err != nil { + logging.Errorf(err.Error()) + aerc.PushError(err.Error()) + } }) } }) -- cgit