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: "(" <paren@disroot.org>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-10-19 22:23:13 +02:00 committed by Robin Jarry
parent 7585a54832
commit e055089d2f

View file

@ -2,12 +2,15 @@ package lib
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"strings"
"github.com/ProtonMail/go-crypto/openpgp" "github.com/ProtonMail/go-crypto/openpgp"
_ "github.com/emersion/go-message/charset" _ "github.com/emersion/go-message/charset"
"git.sr.ht/~rjarry/aerc/lib/crypto" "git.sr.ht/~rjarry/aerc/lib/crypto"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/lib" "git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~rjarry/aerc/worker/types" "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) reader, err := lib.FetchEntityPartReader(msg, part)
if err != nil { 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) cb(reader)
} }