diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-09-21 00:27:58 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-09-25 11:54:23 +0200 |
commit | e5b0725824ac9ccf218732238e4b3b525fa6ad46 (patch) | |
tree | 54ae2d8ea02616c32a74a3d4fcfb3dce50d1c376 /worker/lib/parse.go | |
parent | 41822a6123d5b6779be436d738bf26747de87b0a (diff) | |
download | aerc-e5b0725824ac9ccf218732238e4b3b525fa6ad46.tar.gz |
charset: handle unknown charsets more user-friendly
Do not throw an error when the charset is unknown; the message entity
can still be read, but log the error instead.
Reported-by: falsifian
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/lib/parse.go')
-rw-r--r-- | worker/lib/parse.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go index 30d06a98..3eaa2aef 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "github.com/emersion/go-message" _ "github.com/emersion/go-message/charset" @@ -252,7 +253,7 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) { return nil, err } defer r.Close() - msg, err := message.Read(r) + msg, err := ReadMessage(r) if err != nil { return nil, fmt.Errorf("could not read message: %w", err) } @@ -307,3 +308,17 @@ func NewCRLFReader(r io.Reader) io.Reader { } return &buf } + +// ReadMessage is a wrapper for the message.Read function to read a message +// from r. The message's encoding and charset are automatically decoded to +// UTF-8. If an unknown charset is encountered, the error is logged but a nil +// error is returned since the entity object can still be read. +func ReadMessage(r io.Reader) (*message.Entity, error) { + entity, err := message.Read(r) + if message.IsUnknownCharset(err) { + logging.Warnf("unknown charset encountered") + } else if err != nil { + return nil, fmt.Errorf("could not read message: %w", err) + } + return entity, nil +} |