diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-01-20 23:22:08 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-01-21 10:51:29 +0100 |
commit | 2d8b81f619fc3c8b5a36932e000a86fe111e5bb9 (patch) | |
tree | 8a8251963b4b90cf417c0bac5aa193cf1819bd6a /commands/msg/forward.go | |
parent | b97d6a8ac1c39593be61eb70ffe7013e9306693a (diff) | |
download | aerc-2d8b81f619fc3c8b5a36932e000a86fe111e5bb9.tar.gz |
forward: select correct part for signed messages
Select the correct body part for signed messages when forwarding.
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/forward.go')
-rw-r--r-- | commands/msg/forward.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go index 093ca2e2..bc3f9a68 100644 --- a/commands/msg/forward.go +++ b/commands/msg/forward.go @@ -16,6 +16,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/crypto" "git.sr.ht/~rjarry/aerc/lib/format" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/models" @@ -147,6 +148,22 @@ func (f forward) Execute(args []string) error { f.Template = config.Templates.Forwards } + var fetchBodyPart func([]int, func(io.Reader)) + + mv, isMsgViewer := widget.(*app.MessageViewer) + if isMsgViewer { + fetchBodyPart = mv.MessageView().FetchBodyPart + } else { + fetchBodyPart = func(part []int, cb func(io.Reader)) { + store.FetchBodyPart(msg.Uid, part, cb) + } + } + + if crypto.IsEncrypted(msg.BodyStructure) && !isMsgViewer { + return fmt.Errorf("message is encrypted. " + + "can only forward from the message viewer") + } + part := getMessagePart(msg, widget) if part == nil { part = lib.FindFirstNonMultipart(msg.BodyStructure, nil) @@ -157,7 +174,8 @@ func (f forward) Execute(args []string) error { if err != nil { return err } - store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) { + + fetchBodyPart(part, func(reader io.Reader) { buf := new(bytes.Buffer) scanner := bufio.NewScanner(reader) for scanner.Scan() { @@ -184,7 +202,7 @@ func (f forward) Execute(args []string) error { log.Errorf("cannot get PartAtIndex %v: %v", p, err) continue } - store.FetchBodyPart(msg.Uid, p, func(reader io.Reader) { + fetchBodyPart(p, func(reader io.Reader) { mime := bs.FullMIMEType() params := lib.SetUtf8Charset(bs.Params) name, ok := params["name"] |