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
1 changed files with 11 additions and 1 deletions

View File

@ -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)
}