pgp: fix pipe|open|save command behavior

Signed and/or encrypted PGP messages did not behave properly for pipe,
open, and save commands. Specifically, the proper Message Part would not
be passed to the command in the MessageViewer. This is due to the
encapsulation of the body structure. This patch fixes the behavior for
piping|opening|saving of message parts.

Fixes: https://todo.sr.ht/~rjarry/aerc/47
Reported-by: ~ph14nix
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-06-23 11:26:19 -05:00 committed by Robin Jarry
parent e9b0186782
commit 8f9bb2b289
4 changed files with 14 additions and 11 deletions

View File

@ -182,12 +182,15 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
} }
}() }()
} else if pipePart { } else if pipePart {
mv, ok := provider.(*widgets.MessageViewer)
if !ok {
return fmt.Errorf("can only pipe message part from a message view")
}
p := provider.SelectedMessagePart() p := provider.SelectedMessagePart()
if p == nil { if p == nil {
return fmt.Errorf("could not fetch message part") return fmt.Errorf("could not fetch message part")
} }
store := provider.Store() mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
if background { if background {
doExec(reader) doExec(reader)
} else { } else {

View File

@ -49,8 +49,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
return nil return nil
} }
store := mv.Store() mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
extension := "" extension := ""
// try to determine the correct extension based on mimetype // try to determine the correct extension based on mimetype
if part, err := p.Msg.BodyStructure.PartAtIndex(p.Index); err == nil { if part, err := p.Msg.BodyStructure.PartAtIndex(p.Index); err == nil {

View File

@ -13,7 +13,6 @@ import (
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/widgets"
@ -105,8 +104,6 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
return fmt.Errorf("SelectedTab is not a MessageViewer") return fmt.Errorf("SelectedTab is not a MessageViewer")
} }
store := mv.Store()
if params.attachments { if params.attachments {
parts := mv.AttachmentParts() parts := mv.AttachmentParts()
if len(parts) == 0 { if len(parts) == 0 {
@ -114,7 +111,7 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
} }
params.trailingSlash = true params.trailingSlash = true
for _, pi := range parts { for _, pi := range parts {
if err := savePart(pi, path, store, aerc, &params); err != nil { if err := savePart(pi, path, mv, aerc, &params); err != nil {
return err return err
} }
} }
@ -122,13 +119,13 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
} }
pi := mv.SelectedMessagePart() pi := mv.SelectedMessagePart()
return savePart(pi, path, store, aerc, &params) return savePart(pi, path, mv, aerc, &params)
} }
func savePart( func savePart(
pi *widgets.PartInfo, pi *widgets.PartInfo,
path string, path string,
store *lib.MessageStore, mv *widgets.MessageViewer,
aerc *widgets.Aerc, aerc *widgets.Aerc,
params *saveParams, params *saveParams,
) error { ) error {
@ -151,7 +148,7 @@ func savePart(
} }
ch := make(chan error, 1) ch := make(chan error, 1)
store.FetchBodyPart(pi.Msg.Uid, pi.Index, func(reader io.Reader) { mv.MessageView().FetchBodyPart(pi.Index, func(reader io.Reader) {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
ch <- err ch <- err

View File

@ -290,6 +290,10 @@ func (mv *MessageViewer) SelectedAccount() *AccountView {
return mv.acct return mv.acct
} }
func (mv *MessageViewer) MessageView() lib.MessageView {
return mv.msg
}
func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) { func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) {
if mv.msg == nil { if mv.msg == nil {
return nil, errors.New("no message selected") return nil, errors.New("no message selected")