diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-05 23:10:39 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-07-17 10:24:17 +0200 |
commit | 4c514ce4d15fd14cad528cf426bc3f853efe7f64 (patch) | |
tree | fa52247b470a6af233a6e242962ed20e4831a555 /commands/account/compose.go | |
parent | 11e5390fa0acbcc609ca177777548dd2d725afbc (diff) | |
download | aerc-4c514ce4d15fd14cad528cf426bc3f853efe7f64.tar.gz |
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 <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'commands/account/compose.go')
-rw-r--r-- | commands/account/compose.go | 19 |
1 files changed, 12 insertions, 7 deletions
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 } |