From e055089d2f3478735c6d3fa85e99e9dc10a62731 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 19 Oct 2022 22:23:13 +0200 Subject: lib: fallback on raw msg when decoding fails Avoid panic when part decoding fails: panic: quotedprintable: invalid unescaped byte 0x0c in body User-friendlier fallback when a (decoding) error occurs while reading a message part. Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCNJRVKUG8T68.3TVA2T10DTTBA%40guix-framework%3E Reported-by: "(" Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/messageview.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/messageview.go') diff --git a/lib/messageview.go b/lib/messageview.go index e4f9cbeb..247cecbe 100644 --- a/lib/messageview.go +++ b/lib/messageview.go @@ -2,12 +2,15 @@ package lib import ( "bytes" + "fmt" "io" + "strings" "github.com/ProtonMail/go-crypto/openpgp" _ "github.com/emersion/go-message/charset" "git.sr.ht/~rjarry/aerc/lib/crypto" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/lib" "git.sr.ht/~rjarry/aerc/worker/types" @@ -140,7 +143,14 @@ func (msv *MessageStoreView) FetchBodyPart(part []int, cb func(io.Reader)) { } reader, err := lib.FetchEntityPartReader(msg, part) if err != nil { - panic(err) + errMsg := fmt.Errorf("Failed to fetch message part: %w", err) + logging.Errorf(errMsg.Error()) + if msv.message != nil { + logging.Warnf("Displaying raw message part") + reader = bytes.NewReader(msv.message) + } else { + reader = strings.NewReader(errMsg.Error()) + } } cb(reader) } -- cgit