diff options
author | Jeff Martin <jeffmartin@gmail.com> | 2020-08-21 11:58:30 -0700 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-08-31 22:00:28 +0200 |
commit | 0acb28645fe73d488b82d2915add6c262028bbe3 (patch) | |
tree | cd197771f4172e2da75c9fec6c5862cd377d7b51 /worker/lib/parse.go | |
parent | 43c4f2f3ab8bd914ce1b5c1841724f3c55550e9c (diff) | |
download | aerc-0acb28645fe73d488b82d2915add6c262028bbe3.tar.gz |
handle message unknown charset error
This change handles message parse errors by printing the error when the
user tries to view the message. Specifically only handling unknown
charset errors in this patch, but there are many types of invalid
messages that can be handled in this way.
aerc currently leaves certain messages in the msglist in the pending
(spinner) state, and I'm unable to view or modify the message. aerc also
only prints parse errors with message when they are initially loaded.
This UX is a little better, because you can still see the header info
about the message, and if you try to view it, you will see the specific
error.
Diffstat (limited to 'worker/lib/parse.go')
-rw-r--r-- | worker/lib/parse.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go index b003d962..edd36495 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -94,7 +94,7 @@ func ParseEntityStructure(e *message.Entity) (*models.BodyStructure, error) { } ps, err := ParseEntityStructure(part) if err != nil { - return nil, fmt.Errorf("could not parse child entity structure: %v", err) + return nil, fmt.Errorf("could not parse child entity structure: %w", err) } body.Parts = append(body.Parts, ps) } @@ -224,6 +224,7 @@ type RawMessage interface { // MessageInfo populates a models.MessageInfo struct for the message. // based on the reader returned by NewReader func MessageInfo(raw RawMessage) (*models.MessageInfo, error) { + var parseErr error r, err := raw.NewReader() if err != nil { return nil, err @@ -233,7 +234,9 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) { return nil, fmt.Errorf("could not read message: %v", err) } bs, err := ParseEntityStructure(msg) - if err != nil { + if errors.As(err, new(message.UnknownEncodingError)) { + parseErr = err + } else if err != nil { return nil, fmt.Errorf("could not get structure: %v", err) } h := &mail.Header{msg.Header} @@ -268,5 +271,6 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) { RFC822Headers: &mail.Header{msg.Header}, Size: 0, Uid: raw.UID(), + Error: parseErr, }, nil } |