diff options
author | Robin Jarry <robin@jarry.cc> | 2021-10-28 14:59:54 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2021-10-28 16:38:23 +0200 |
commit | 074b0a1bd8da38547c6e3eed9836149327012228 (patch) | |
tree | 0082759cd8b160c4e7513cb87a1bc600e9bb4f06 /lib/format | |
parent | fc84b19bba0e0953ec06de27f1ec9c9f8d1a96ef (diff) | |
download | aerc-074b0a1bd8da38547c6e3eed9836149327012228.tar.gz |
view,list: fix crash when viewing incomplete imap messages
With IMAP, due to an unidentified reason, some messages to not have any body accessible. When viewing them, aerc crashes: git.sr.ht/~sircmpwn/aerc/lib.usePGP lib/messageview.go:37 git.sr.ht/~sircmpwn/aerc/lib.NewMessageStoreView lib/messageview.go:67 git.sr.ht/~sircmpwn/aerc/commands/account.ViewMessage.Execute commands/account/view.go:45 git.sr.ht/~sircmpwn/aerc/commands.(*Commands).ExecuteCommand commands/commands.go:66 main.execCommand aerc.go:61 main.main.func2 aerc.go:160 aerc crashed: runtime error: invalid memory address or nil pointer dereference Check the pointer before dereferencing. Also, add a global check in ParseMessageFormat where a similar issue may occur. Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/format')
-rw-r--r-- | lib/format/format.go | 52 |
1 files changed, 4 insertions, 48 deletions
diff --git a/lib/format/format.go b/lib/format/format.go index 1639886..4ee62ac 100644 --- a/lib/format/format.go +++ b/lib/format/format.go @@ -58,6 +58,10 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, } envelope := ctx.MsgInfo.Envelope + if envelope == nil { + return "", nil, + errors.New("no envelope available for this message") + } var c rune for i, ni := 0, 0; i < len(format); { @@ -105,10 +109,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, case '%': retval = append(retval, '%') case 'a': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") @@ -117,10 +117,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, retval = append(retval, 's') args = append(args, addr.Address) case 'A': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } var addr *mail.Address if len(envelope.ReplyTo) == 0 { if len(envelope.From) == 0 { @@ -156,10 +152,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, dummyIfZeroDate(date.Local(), timeFmt, thisDayTimeFmt, thisYearTimeFmt)) case 'f': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") @@ -168,10 +160,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, retval = append(retval, 's') args = append(args, addr) case 'F': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") @@ -196,17 +184,9 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, args = append(args, strings.Join(ctx.MsgInfo.Labels, ", ")) case 'i': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } retval = append(retval, 's') args = append(args, envelope.MessageId) case 'n': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") @@ -221,33 +201,17 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, retval = append(retval, 's') args = append(args, val) case 'r': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } addrs := FormatAddresses(envelope.To) retval = append(retval, 's') args = append(args, addrs) case 'R': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } addrs := FormatAddresses(envelope.Cc) retval = append(retval, 's') args = append(args, addrs) case 's': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } retval = append(retval, 's') args = append(args, envelope.Subject) case 't': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.To) == 0 { return "", nil, errors.New("found no address for recipient") @@ -259,10 +223,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, retval = append(retval, 's') args = append(args, ctx.AccountName) case 'u': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") @@ -275,10 +235,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, retval = append(retval, 's') args = append(args, mailbox) case 'v': - if envelope == nil { - return "", nil, - errors.New("no envelope available for this message") - } if len(envelope.From) == 0 { return "", nil, errors.New("found no address for sender") |