aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-10-27 13:26:10 -0500
committerRobin Jarry <robin@jarry.cc>2022-11-09 21:59:24 +0100
commit419d67fc6822651e9a0fa9a65698799fabc9ac87 (patch)
tree67aa0a898447f8a7ae003999718e88456b18d6c8
parent9b49bb1c80e0f713cef59b3617e07ae1e1a3c951 (diff)
downloadaerc-419d67fc6822651e9a0fa9a65698799fabc9ac87.tar.gz
msgviewer: show error if MessageInfo has error
MessageInfo structs can be returned from the workers with parser errors. MessageViews were previously prevented from opening if the error field was not nil, however the addition of message view splits have allowed these messages to have split views created. A panic can occur if a split is open and one of these messages is scrolled over. Prevent access to MessageInfo methods if the Error field is set. Display the error to the user in the split view. The partSwitcher will be nil if an error is set: check for this condition before calling it's methods. Reported-by: Ben Lee-Cohen <ben@lee-cohen.com> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--widgets/msgviewer.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 19be7473..d168f456 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -77,7 +77,7 @@ func NewMessageViewer(acct *AccountView,
hv.Name = header
showInfo = true
}
- if parser := auth.New(header); parser != nil {
+ if parser := auth.New(header); parser != nil && msg.MessageInfo().Error == nil {
details, err := parser(msg.MessageInfo().RFC822Headers, acct.AccountConfig().TrustedAuthRes)
if err != nil {
hv.Value = err.Error()
@@ -115,6 +115,7 @@ func NewMessageViewer(acct *AccountView,
err := createSwitcher(acct, switcher, conf, msg)
if err != nil {
return &MessageViewer{
+ acct: acct,
err: err,
grid: grid,
msg: msg,
@@ -221,6 +222,10 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher,
switcher.showHeaders = conf.Viewer.ShowHeaders
switcher.alwaysShowMime = conf.Viewer.AlwaysShowMime
+ if msg.MessageInfo().Error != nil {
+ return fmt.Errorf("could not view message: %w", msg.MessageInfo().Error)
+ }
+
if len(msg.BodyStructure().Parts) == 0 {
switcher.selected = 0
pv, err := NewPartViewer(acct, conf, msg, msg.BodyStructure(), nil)
@@ -383,7 +388,9 @@ func (mv *MessageViewer) Bindings() string {
}
func (mv *MessageViewer) Close() error {
- mv.switcher.Cleanup()
+ if mv.switcher != nil {
+ mv.switcher.Cleanup()
+ }
return nil
}