Fix segfault on :view-message for unloaded message

This also fixes segfault on :view-message on empty directory

Signed-off-by: Tom Lebreux <tomlebreux@cock.li>
This commit is contained in:
Tom Lebreux 2019-04-08 23:14:14 -04:00 committed by Drew DeVault
parent ec09ec8b0e
commit 3cd0d5bc28
2 changed files with 10 additions and 0 deletions

View File

@ -17,8 +17,14 @@ func ViewMessage(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: view-message") return errors.New("Usage: view-message")
} }
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct.Messages().Empty() {
return nil
}
store := acct.Messages().Store() store := acct.Messages().Store()
msg := acct.Messages().Selected() msg := acct.Messages().Selected()
if msg == nil {
return nil
}
viewer := widgets.NewMessageViewer(aerc.Config(), store, msg) viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
aerc.NewTab(viewer, runewidth.Truncate( aerc.NewTab(viewer, runewidth.Truncate(
msg.Envelope.Subject, 32, "…")) msg.Envelope.Subject, 32, "…"))

View File

@ -138,6 +138,10 @@ func (ml *MessageList) Store() *lib.MessageStore {
return ml.store return ml.store
} }
func (ml *MessageList) Empty() bool {
return ml.store == nil || len(ml.store.Uids) == 0
}
func (ml *MessageList) Selected() *types.MessageInfo { func (ml *MessageList) Selected() *types.MessageInfo {
return ml.store.Messages[ml.store.Uids[len(ml.store.Uids)-ml.selected-1]] return ml.store.Messages[ml.store.Uids[len(ml.store.Uids)-ml.selected-1]]
} }