aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-20 23:22:07 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-21 10:51:29 +0100
commitb97d6a8ac1c39593be61eb70ffe7013e9306693a (patch)
tree46a65f60b318b736f783656771dba22d0c569f16 /commands/msg
parentc8017f67531c493451c6f25335990a74a1f81699 (diff)
downloadaerc-b97d6a8ac1c39593be61eb70ffe7013e9306693a.tar.gz
reply: select correct part for signed messages
Select the correct body part for signed messages when quote-replying. Simplify logic in the reply command for the part selection. Fixes: https://todo.sr.ht/~rjarry/aerc/214 Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/reply.go47
1 files changed, 18 insertions, 29 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 04c2eba5..ee31a37e 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -1,7 +1,6 @@
package msg
import (
- "bytes"
"errors"
"fmt"
"io"
@@ -157,7 +156,7 @@ func (r reply) Execute(args []string) error {
RFC822Headers: msg.RFC822Headers,
}
- mv, _ := app.SelectedTabContent().(*app.MessageViewer)
+ mv, isMsgViewer := app.SelectedTabContent().(*app.MessageViewer)
addTab := func() error {
composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
@@ -201,29 +200,19 @@ func (r reply) Execute(args []string) error {
r.Template = config.Templates.QuotedReply
}
- if crypto.IsEncrypted(msg.BodyStructure) {
- provider := app.SelectedTabContent().(app.ProvidesMessage)
- mv, ok := provider.(*app.MessageViewer)
- if !ok {
- return fmt.Errorf("message is encrypted. can only quote reply while message is open")
- }
- p := provider.SelectedMessagePart()
- if p == nil {
- return fmt.Errorf("could not fetch message part")
+ var fetchBodyPart func([]int, func(io.Reader))
+
+ if isMsgViewer {
+ fetchBodyPart = mv.MessageView().FetchBodyPart
+ } else {
+ fetchBodyPart = func(part []int, cb func(io.Reader)) {
+ store.FetchBodyPart(msg.Uid, part, cb)
}
- mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
- buf := new(bytes.Buffer)
- _, err := buf.ReadFrom(reader)
- if err != nil {
- log.Warnf("failed to fetch bodypart: %v", err)
- }
- original.Text = buf.String()
- err = addTab()
- if err != nil {
- log.Warnf("failed to add tab: %v", err)
- }
- })
- return nil
+ }
+
+ if crypto.IsEncrypted(msg.BodyStructure) && !isMsgViewer {
+ return fmt.Errorf("message is encrypted. " +
+ "can only quote reply from the message viewer")
}
part := getMessagePart(msg, widget)
@@ -239,18 +228,18 @@ func (r reply) Execute(args []string) error {
return err
}
- store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
- buf := new(bytes.Buffer)
- _, err := buf.ReadFrom(reader)
+ fetchBodyPart(part, func(reader io.Reader) {
+ data, err := io.ReadAll(reader)
if err != nil {
- log.Warnf("failed to fetch bodypart: %v", err)
+ log.Warnf("failed to read bodypart: %v", err)
}
- original.Text = buf.String()
+ original.Text = string(data)
err = addTab()
if err != nil {
log.Warnf("failed to add tab: %v", err)
}
})
+
return nil
} else {
if r.Template == "" {