postpone: re-open review mode on error

re-opens the review UI when the postpone operation fails. Before, the
composer would close, even on error, and we would lose the email draft.
Now, the user can decide on how to proceed when postponing fails.

References: https://lists.sr.ht/~rjarry/aerc-devel/patches/28824
Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
Koni Marti 2022-02-04 13:18:52 +01:00 committed by Robin Jarry
parent dfb7240d48
commit 4bd4f4664a

View file

@ -33,6 +33,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTab().(*widgets.Composer)
config := composer.Config() config := composer.Config()
tabName := aerc.TabNames()[aerc.SelectedTabIndex()]
if config.Postpone == "" { if config.Postpone == "" {
return errors.New("No Postpone location configured") return errors.New("No Postpone location configured")
@ -67,12 +68,17 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
return return
} }
handleErr := func(err error) {
aerc.PushError(err.Error())
aerc.Logger().Println("Postponing failed:", err)
aerc.NewTab(composer, tabName)
}
aerc.RemoveTab(composer) aerc.RemoveTab(composer)
ctr := datacounter.NewWriterCounter(ioutil.Discard) ctr := datacounter.NewWriterCounter(ioutil.Discard)
err = composer.WriteMessage(header, ctr) err = composer.WriteMessage(header, ctr)
if err != nil { if err != nil {
aerc.PushError(errors.Wrap(err, "WriteMessage").Error()) handleErr(errors.Wrap(err, "WriteMessage"))
composer.Close()
return return
} }
nbytes := int(ctr.Count()) nbytes := int(ctr.Count())
@ -90,9 +96,8 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
r.Close() r.Close()
composer.Close() composer.Close()
case *types.Error: case *types.Error:
aerc.PushError(msg.Error.Error())
r.Close() r.Close()
composer.Close() handleErr(msg.Error)
} }
}) })
composer.WriteMessage(header, w) composer.WriteMessage(header, w)