From 4c514ce4d15fd14cad528cf426bc3f853efe7f64 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 5 Jul 2023 23:10:39 +0200 Subject: compose: allow changing edit-headers on the fly Add -e|-E flags to all compose commands to allow switching between edit-headers = true/false without restarting aerc. Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy Tested-by: Koni Marti --- commands/account/compose.go | 19 ++++++++++++------- commands/account/recover.go | 15 +++++++++++---- commands/compose/edit.go | 25 +++++++++++++++++++++---- commands/msg/forward.go | 13 +++++++++++-- commands/msg/invite.go | 21 ++++++++++++++++++++- commands/msg/recall.go | 16 +++++++++++----- commands/msg/reply.go | 13 +++++++++---- commands/msg/unsubscribe.go | 24 ++++++++++++++++++++---- 8 files changed, 115 insertions(+), 31 deletions(-) (limited to 'commands') diff --git a/commands/account/compose.go b/commands/account/compose.go index 3c603f34..5da0f163 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -30,7 +30,7 @@ func (Compose) Complete(aerc *widgets.Aerc, args []string) []string { } func (Compose) Execute(aerc *widgets.Aerc, args []string) error { - body, template, err := buildBody(args) + body, template, editHeaders, err := buildBody(args) if err != nil { return err } @@ -51,7 +51,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { headers := mail.HeaderFromMap(msg.Header) composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), + acct.AccountConfig(), acct.Worker(), editHeaders, template, &headers, nil, msg.Body) if err != nil { return err @@ -60,11 +60,12 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { return nil } -func buildBody(args []string) (string, string, error) { +func buildBody(args []string) (string, string, bool, error) { var body, template, headers string - opts, optind, err := getopt.Getopts(args, "H:T:") + editHeaders := config.Compose.EditHeaders + opts, optind, err := getopt.Getopts(args, "H:T:eE") if err != nil { - return "", "", err + return "", "", false, err } for _, opt := range opts { switch opt.Option { @@ -78,11 +79,15 @@ func buildBody(args []string) (string, string, error) { } case 'T': template = opt.Value + case 'e': + editHeaders = true + case 'E': + editHeaders = false } } posargs := args[optind:] if len(posargs) > 1 { - return "", template, errors.New("Usage: compose [-H header] [-T template] [body]") + return "", "", false, errors.New("Usage: compose [-H header] [-T template] [-e|-E] [body]") } if len(posargs) == 1 { body = posargs[0] @@ -94,5 +99,5 @@ func buildBody(args []string) (string, string, error) { body = headers + "\n\n" } } - return body, template, nil + return body, template, editHeaders, nil } diff --git a/commands/account/recover.go b/commands/account/recover.go index 3e4e9136..9fdaa3e9 100644 --- a/commands/account/recover.go +++ b/commands/account/recover.go @@ -8,6 +8,7 @@ import ( "path/filepath" "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~sircmpwn/getopt" ) @@ -23,7 +24,7 @@ func (Recover) Aliases() []string { } func (Recover) Options() string { - return "f" + return "feE" } func (r Recover) Complete(aerc *widgets.Aerc, args []string) []string { @@ -45,19 +46,25 @@ func (r Recover) Execute(aerc *widgets.Aerc, args []string) error { } force := false + editHeaders := config.Compose.EditHeaders opts, optind, err := getopt.Getopts(args, r.Options()) if err != nil { return err } for _, opt := range opts { - if opt.Option == 'f' { + switch opt.Option { + case 'f': force = true + case 'e': + editHeaders = true + case 'E': + editHeaders = false } } if len(args) <= optind { - return errors.New("Usage: recover [-f] ") + return errors.New("Usage: recover [-f] [-E|-e] ") } acct := aerc.SelectedAccount() @@ -83,7 +90,7 @@ func (r Recover) Execute(aerc *widgets.Aerc, args []string) error { } composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), + acct.AccountConfig(), acct.Worker(), editHeaders, "", nil, nil, bytes.NewReader(data)) if err != nil { return err diff --git a/commands/compose/edit.go b/commands/compose/edit.go index 6f877346..1e8e0672 100644 --- a/commands/compose/edit.go +++ b/commands/compose/edit.go @@ -3,7 +3,9 @@ package compose import ( "errors" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/widgets" + "git.sr.ht/~sircmpwn/getopt" ) type Edit struct{} @@ -21,14 +23,29 @@ func (Edit) Complete(aerc *widgets.Aerc, args []string) []string { } func (Edit) Execute(aerc *widgets.Aerc, args []string) error { - if len(args) != 1 { - return errors.New("Usage: edit") - } composer, ok := aerc.SelectedTabContent().(*widgets.Composer) if !ok { return errors.New("only valid while composing") } - err := composer.ShowTerminal() + + editHeaders := config.Compose.EditHeaders + opts, optind, err := getopt.Getopts(args, "eE") + if err != nil { + return err + } + if len(args) != optind { + return errors.New("Usage: edit [-e|-E]") + } + for _, opt := range opts { + switch opt.Option { + case 'e': + editHeaders = true + case 'E': + editHeaders = false + } + } + + err = composer.ShowTerminal(editHeaders) if err != nil { return err } diff --git a/commands/msg/forward.go b/commands/msg/forward.go index ed0043fe..86c52059 100644 --- a/commands/msg/forward.go +++ b/commands/msg/forward.go @@ -39,13 +39,17 @@ func (forward) Complete(aerc *widgets.Aerc, args []string) []string { } func (forward) Execute(aerc *widgets.Aerc, args []string) error { - opts, optind, err := getopt.Getopts(args, "AFT:") + opts, optind, err := getopt.Getopts(args, "AFT:eE") if err != nil { return err } + if len(args) != optind { + return errors.New("Usage: forward [-A|-F] [-T