c26d08103b
aerc.SelectedAccount() is used in lots of places. Most of them without checking the return value. In some cases, the currently selected tab is not related to any account (widget.Terminal for example). This can lead to unexpected crashes when accessing account specific configuration. When possible, return an error when no account is currently selected. If no error can be returned, fallback to non-account specific configuration. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package account
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib"
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
|
)
|
|
|
|
type ViewMessage struct{}
|
|
|
|
func init() {
|
|
register(ViewMessage{})
|
|
}
|
|
|
|
func (ViewMessage) Aliases() []string {
|
|
return []string{"view-message", "view"}
|
|
}
|
|
|
|
func (ViewMessage) Complete(aerc *widgets.Aerc, args []string) []string {
|
|
return nil
|
|
}
|
|
|
|
func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
|
|
if len(args) != 1 {
|
|
return errors.New("Usage: view-message")
|
|
}
|
|
acct := aerc.SelectedAccount()
|
|
if acct == nil {
|
|
return errors.New("No account selected")
|
|
}
|
|
if acct.Messages().Empty() {
|
|
return nil
|
|
}
|
|
store := acct.Messages().Store()
|
|
msg := acct.Messages().Selected()
|
|
if msg == nil {
|
|
return nil
|
|
}
|
|
_, deleted := store.Deleted[msg.Uid]
|
|
if deleted {
|
|
return nil
|
|
}
|
|
if msg.Error != nil {
|
|
aerc.PushError(msg.Error.Error())
|
|
return nil
|
|
}
|
|
lib.NewMessageStoreView(msg, store, aerc.DecryptKeys,
|
|
func(view lib.MessageView, err error) {
|
|
if err != nil {
|
|
aerc.PushError(err.Error())
|
|
return
|
|
}
|
|
viewer := widgets.NewMessageViewer(acct, aerc.Config(), view)
|
|
aerc.NewTab(viewer, msg.Envelope.Subject)
|
|
})
|
|
return nil
|
|
}
|