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/msg/unsubscribe.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'commands/msg/unsubscribe.go') diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go index cefa69cb..505392d4 100644 --- a/commands/msg/unsubscribe.go +++ b/commands/msg/unsubscribe.go @@ -8,9 +8,11 @@ import ( "strings" "time" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" + "git.sr.ht/~sircmpwn/getopt" "github.com/emersion/go-message/mail" ) @@ -34,8 +36,21 @@ func (Unsubscribe) Complete(aerc *widgets.Aerc, args []string) []string { // Execute runs the Unsubscribe command func (Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error { - if len(args) != 1 { - return errors.New("Usage: unsubscribe") + editHeaders := config.Compose.EditHeaders + opts, optind, err := getopt.Getopts(args, "eE") + if err != nil { + return err + } + if len(args) != optind { + return errors.New("Usage: unsubscribe [-e|-E]") + } + for _, opt := range opts { + switch opt.Option { + case 'e': + editHeaders = true + case 'E': + editHeaders = false + } } widget := aerc.SelectedTabContent().(widgets.ProvidesMessage) msg, err := widget.SelectedMessage() @@ -61,7 +76,7 @@ func (Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error { var err error switch strings.ToLower(method.Scheme) { case "mailto": - err = unsubscribeMailto(aerc, method) + err = unsubscribeMailto(aerc, method, editHeaders) case "http", "https": err = unsubscribeHTTP(aerc, method) default: @@ -133,7 +148,7 @@ func parseUnsubscribeMethods(header string) (methods []*url.URL) { } } -func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error { +func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL, editHeaders bool) error { widget := aerc.SelectedTabContent().(widgets.ProvidesMessage) acct := widget.SelectedAccount() if acct == nil { @@ -151,6 +166,7 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error { acct, acct.AccountConfig(), acct.Worker(), + editHeaders, "", h, nil, -- cgit