Fix crashes when operating on empty folder (#216)
This commit is contained in:
parent
3f30c27bb3
commit
217e85a55d
11 changed files with 45 additions and 15 deletions
|
@ -41,7 +41,10 @@ func (_ Archive) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
if acct == nil {
|
if acct == nil {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
msg := widget.SelectedMessage()
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
archiveDir := acct.AccountConfig().Archive
|
archiveDir := acct.AccountConfig().Archive
|
||||||
store.Next()
|
store.Next()
|
||||||
|
|
|
@ -44,7 +44,10 @@ func (_ Copy) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
msg := widget.SelectedMessage()
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
store.Copy([]uint32{msg.Uid}, args[optind], createParents, func(
|
store.Copy([]uint32{msg.Uid}, args[optind], createParents, func(
|
||||||
msg types.WorkerMessage) {
|
msg types.WorkerMessage) {
|
||||||
|
|
|
@ -35,10 +35,10 @@ func (_ Delete) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
if len(store.Uids) == 0 {
|
msg, err := widget.SelectedMessage()
|
||||||
return errors.New("No message selected")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
msg := widget.SelectedMessage()
|
|
||||||
_, isMsgView := widget.(*widgets.MessageViewer)
|
_, isMsgView := widget.(*widgets.MessageViewer)
|
||||||
if isMsgView {
|
if isMsgView {
|
||||||
aerc.RemoveTab(widget)
|
aerc.RemoveTab(widget)
|
||||||
|
|
|
@ -49,7 +49,10 @@ func (_ Move) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
if acct == nil {
|
if acct == nil {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
msg := widget.SelectedMessage()
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
_, isMsgView := widget.(*widgets.MessageViewer)
|
_, isMsgView := widget.(*widgets.MessageViewer)
|
||||||
if isMsgView {
|
if isMsgView {
|
||||||
|
|
|
@ -112,7 +112,10 @@ func (_ Pipe) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
|
|
||||||
if pipeFull {
|
if pipeFull {
|
||||||
store := provider.Store()
|
store := provider.Store()
|
||||||
msg := provider.SelectedMessage()
|
msg, err := provider.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
store.FetchFull([]uint32{msg.Uid}, func(reader io.Reader) {
|
store.FetchFull([]uint32{msg.Uid}, func(reader io.Reader) {
|
||||||
if background {
|
if background {
|
||||||
doExec(reader)
|
doExec(reader)
|
||||||
|
|
|
@ -30,7 +30,10 @@ func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
msg := widget.SelectedMessage()
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
store.Read([]uint32{msg.Uid}, args[0] == "read", func(
|
store.Read([]uint32{msg.Uid}, args[0] == "read", func(
|
||||||
msg types.WorkerMessage) {
|
msg types.WorkerMessage) {
|
||||||
|
|
|
@ -60,7 +60,10 @@ func (_ reply) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
conf := acct.AccountConfig()
|
conf := acct.AccountConfig()
|
||||||
us, _ := gomail.ParseAddress(conf.From)
|
us, _ := gomail.ParseAddress(conf.From)
|
||||||
store := widget.Store()
|
store := widget.Store()
|
||||||
msg := widget.SelectedMessage()
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
|
acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -34,7 +34,11 @@ func (Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
return errors.New("Usage: unsubscribe")
|
return errors.New("Usage: unsubscribe")
|
||||||
}
|
}
|
||||||
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
headers := widget.SelectedMessage().RFC822Headers
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
headers := msg.RFC822Headers
|
||||||
if !headers.Has("list-unsubscribe") {
|
if !headers.Has("list-unsubscribe") {
|
||||||
return errors.New("No List-Unsubscribe header found")
|
return errors.New("No List-Unsubscribe header found")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -170,8 +171,11 @@ func (acct *AccountView) SelectedAccount() *AccountView {
|
||||||
return acct
|
return acct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acct *AccountView) SelectedMessage() *models.MessageInfo {
|
func (acct *AccountView) SelectedMessage() (*models.MessageInfo, error) {
|
||||||
return acct.msglist.Selected()
|
if len(acct.msglist.Store().Uids) == 0 {
|
||||||
|
return nil, errors.New("no message selected")
|
||||||
|
}
|
||||||
|
return acct.msglist.Selected(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acct *AccountView) SelectedMessagePart() *PartInfo {
|
func (acct *AccountView) SelectedMessagePart() *PartInfo {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -211,8 +212,11 @@ func (mv *MessageViewer) SelectedAccount() *AccountView {
|
||||||
return mv.acct
|
return mv.acct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mv *MessageViewer) SelectedMessage() *models.MessageInfo {
|
func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) {
|
||||||
return mv.msg
|
if mv.msg == nil {
|
||||||
|
return nil, errors.New("no message selected")
|
||||||
|
}
|
||||||
|
return mv.msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mv *MessageViewer) ToggleHeaders() {
|
func (mv *MessageViewer) ToggleHeaders() {
|
||||||
|
|
|
@ -17,6 +17,6 @@ type ProvidesMessage interface {
|
||||||
ui.Drawable
|
ui.Drawable
|
||||||
Store() *lib.MessageStore
|
Store() *lib.MessageStore
|
||||||
SelectedAccount() *AccountView
|
SelectedAccount() *AccountView
|
||||||
SelectedMessage() *models.MessageInfo
|
SelectedMessage() (*models.MessageInfo, error)
|
||||||
SelectedMessagePart() *PartInfo
|
SelectedMessagePart() *PartInfo
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue