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/msg | |
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/msg')
-rw-r--r-- | commands/msg/forward.go | 13 | ||||
-rw-r--r-- | commands/msg/invite.go | 21 | ||||
-rw-r--r-- | commands/msg/recall.go | 16 | ||||
-rw-r--r-- | commands/msg/reply.go | 13 | ||||
-rw-r--r-- | commands/msg/unsubscribe.go | 24 |
5 files changed, 71 insertions, 16 deletions
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 <template>] [-e|-E]") + } attachAll := false attachFull := false template := "" + editHeaders := config.Compose.EditHeaders for _, opt := range opts { switch opt.Option { case 'A': @@ -54,6 +58,10 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error { attachFull = true case 'T': template = opt.Value + case 'e': + editHeaders = true + case 'E': + editHeaders = false } } @@ -100,7 +108,8 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error { addTab := func() (*widgets.Composer, error) { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), template, h, &original, nil) + acct.AccountConfig(), acct.Worker(), editHeaders, + template, h, &original, nil) if err != nil { aerc.PushError("Error: " + err.Error()) return nil, err diff --git a/commands/msg/invite.go b/commands/msg/invite.go index 6273d520..309fe643 100644 --- a/commands/msg/invite.go +++ b/commands/msg/invite.go @@ -12,6 +12,7 @@ import ( "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" + "git.sr.ht/~sircmpwn/getopt" "github.com/emersion/go-message/mail" ) @@ -48,6 +49,23 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { return fmt.Errorf("no invitation found (missing text/calendar)") } + editHeaders := config.Compose.EditHeaders + opts, optind, err := getopt.Getopts(args, "eE") + if err != nil { + return err + } + if len(args) != optind { + return errors.New("Usage: accept|accept-tentative|decline [-e|-E]") + } + for _, opt := range opts { + switch opt.Option { + case 'e': + editHeaders = true + case 'E': + editHeaders = false + } + } + subject := trimLocalizedRe(msg.Envelope.Subject, acct.AccountConfig().LocalizedRe) switch args[0] { case "accept": @@ -138,7 +156,8 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { addTab := func(cr *calendar.Reply) error { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), "", h, &original, cr.PlainText) + acct.AccountConfig(), acct.Worker(), editHeaders, + "", h, &original, cr.PlainText) if err != nil { aerc.PushError("Error: " + err.Error()) return err diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 71f8b8a5..c095caf1 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -10,6 +10,7 @@ import ( _ "github.com/emersion/go-message/charset" "github.com/pkg/errors" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" @@ -33,19 +34,24 @@ func (Recall) Complete(aerc *widgets.Aerc, args []string) []string { func (Recall) Execute(aerc *widgets.Aerc, args []string) error { force := false + editHeaders := config.Compose.EditHeaders - opts, optind, err := getopt.Getopts(args, "f") + opts, optind, err := getopt.Getopts(args, "feE") 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: recall [-f]") + return errors.New("Usage: recall [-f] [-e|-E]") } widget := aerc.SelectedTabContent().(widgets.ProvidesMessage) @@ -130,7 +136,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { msg.FetchBodyPart(path, func(reader io.Reader) { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), + acct.AccountConfig(), acct.Worker(), editHeaders, "", msgInfo.RFC822Headers, nil, reader) if err != nil { aerc.PushError(err.Error()) diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 8cdb50d4..b2a61a80 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -38,12 +38,12 @@ func (reply) Complete(aerc *widgets.Aerc, args []string) []string { } func (reply) Execute(aerc *widgets.Aerc, args []string) error { - opts, optind, err := getopt.Getopts(args, "acqT:") + opts, optind, err := getopt.Getopts(args, "acqT:eE") if err != nil { return err } if optind != len(args) { - return errors.New("Usage: reply [-acq -T <template>]") + return errors.New("Usage: reply [-acq -T <template>] [-e|-E]") } var ( quote bool @@ -51,6 +51,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { closeOnReply bool template string ) + editHeaders := config.Compose.EditHeaders for _, opt := range opts { switch opt.Option { case 'a': @@ -61,6 +62,10 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { quote = true case 'T': template = opt.Value + case 'e': + editHeaders = true + case 'E': + editHeaders = false } } @@ -175,8 +180,8 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer) addTab := func() error { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), template, h, - &original, nil) + acct.AccountConfig(), acct.Worker(), editHeaders, + template, h, &original, nil) if err != nil { aerc.PushError("Error: " + err.Error()) return err 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, |