pgp: fail gracefully from email decryption

Aerc panics when there's an error on email decryption.
Instead, an error message should be shown.
This commit is contained in:
Ray Ganardi 2020-05-19 13:06:46 +02:00 committed by Drew DeVault
parent 83e7c7661d
commit 58db517c8d
5 changed files with 31 additions and 11 deletions

View file

@ -39,7 +39,11 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
return nil return nil
} }
lib.NewMessageStoreView(msg, store, aerc.DecryptKeys, lib.NewMessageStoreView(msg, store, aerc.DecryptKeys,
func(view lib.MessageView) { func(view lib.MessageView, err error) {
if err != nil {
aerc.PushError(err.Error())
return
}
viewer := widgets.NewMessageViewer(acct, aerc.Config(), view) viewer := widgets.NewMessageViewer(acct, aerc.Config(), view)
aerc.NewTab(viewer, msg.Envelope.Subject) aerc.NewTab(viewer, msg.Envelope.Subject)
}) })

View file

@ -66,7 +66,11 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
return nil return nil
} }
lib.NewMessageStoreView(next, store, aerc.DecryptKeys, lib.NewMessageStoreView(next, store, aerc.DecryptKeys,
func(view lib.MessageView) { func(view lib.MessageView, err error) {
if err != nil {
aerc.PushError(err.Error())
return
}
nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject) aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
}) })

View file

@ -38,7 +38,11 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
return nil return nil
} }
lib.NewMessageStoreView(nextMsg, store, aerc.DecryptKeys, lib.NewMessageStoreView(nextMsg, store, aerc.DecryptKeys,
func(view lib.MessageView) { func(view lib.MessageView, err error) {
if err != nil {
aerc.PushError(err.Error())
return
}
nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
aerc.ReplaceTab(mv, nextMv, nextMsg.Envelope.Subject) aerc.ReplaceTab(mv, nextMv, nextMsg.Envelope.Subject)
}) })

View file

@ -59,7 +59,7 @@ type MessageStoreView struct {
func NewMessageStoreView(messageInfo *models.MessageInfo, func NewMessageStoreView(messageInfo *models.MessageInfo,
store *MessageStore, decryptKeys openpgp.PromptFunction, store *MessageStore, decryptKeys openpgp.PromptFunction,
cb func(MessageView)) { cb func(MessageView, error)) {
msv := &MessageStoreView{messageInfo, store, msv := &MessageStoreView{messageInfo, store,
nil, nil, messageInfo.BodyStructure} nil, nil, messageInfo.BodyStructure}
@ -69,26 +69,30 @@ func NewMessageStoreView(messageInfo *models.MessageInfo,
reader := fm.Content.Reader reader := fm.Content.Reader
pgpReader, err := pgpmail.Read(reader, Keyring, decryptKeys, nil) pgpReader, err := pgpmail.Read(reader, Keyring, decryptKeys, nil)
if err != nil { if err != nil {
panic(err) cb(nil, err)
return
} }
msv.message, err = ioutil.ReadAll(pgpReader.MessageDetails.UnverifiedBody) msv.message, err = ioutil.ReadAll(pgpReader.MessageDetails.UnverifiedBody)
if err != nil { if err != nil {
panic(err) cb(nil, err)
return
} }
decrypted, err := message.Read(bytes.NewBuffer(msv.message)) decrypted, err := message.Read(bytes.NewBuffer(msv.message))
if err != nil { if err != nil {
panic(err) cb(nil, err)
return
} }
bs, err := lib.ParseEntityStructure(decrypted) bs, err := lib.ParseEntityStructure(decrypted)
if err != nil { if err != nil {
panic(err) cb(nil, err)
return
} }
msv.bodyStructure = bs msv.bodyStructure = bs
msv.details = pgpReader.MessageDetails msv.details = pgpReader.MessageDetails
cb(msv) cb(msv, nil)
}) })
} else { } else {
cb(msv) cb(msv, nil)
} }
store.Read([]uint32{messageInfo.Uid}, true, nil) store.Read([]uint32{messageInfo.Uid}, true, nil)
} }

View file

@ -166,7 +166,11 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
return return
} }
lib.NewMessageStoreView(msg, store, ml.aerc.DecryptKeys, lib.NewMessageStoreView(msg, store, ml.aerc.DecryptKeys,
func(view lib.MessageView) { func(view lib.MessageView, err error) {
if err != nil {
ml.aerc.PushError(err.Error())
return
}
viewer := NewMessageViewer(acct, ml.aerc.Config(), view) viewer := NewMessageViewer(acct, ml.aerc.Config(), view)
ml.aerc.NewTab(viewer, msg.Envelope.Subject) ml.aerc.NewTab(viewer, msg.Envelope.Subject)
}) })