diff options
Diffstat (limited to 'commands/msg/reply.go')
-rw-r--r-- | commands/msg/reply.go | 65 |
1 files changed, 21 insertions, 44 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go index b2a61a80..dc7750f7 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -9,8 +9,6 @@ import ( "strings" "time" - "git.sr.ht/~sircmpwn/getopt" - "git.sr.ht/~rjarry/aerc/commands/account" "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" @@ -23,7 +21,14 @@ import ( "github.com/emersion/go-message/mail" ) -type reply struct{} +type reply struct { + All bool `opt:"-a"` + Close bool `opt:"-c"` + Quote bool `opt:"-q"` + Template string `opt:"-T"` + Edit bool `opt:"-e"` + NoEdit bool `opt:"-E"` +} func init() { register(reply{}) @@ -37,37 +42,8 @@ func (reply) Complete(aerc *widgets.Aerc, args []string) []string { return nil } -func (reply) Execute(aerc *widgets.Aerc, args []string) error { - 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>] [-e|-E]") - } - var ( - quote bool - replyAll bool - closeOnReply bool - template string - ) - editHeaders := config.Compose.EditHeaders - for _, opt := range opts { - switch opt.Option { - case 'a': - replyAll = true - case 'c': - closeOnReply = true - case 'q': - quote = true - case 'T': - template = opt.Value - case 'e': - editHeaders = true - case 'E': - editHeaders = false - } - } +func (r reply) Execute(aerc *widgets.Aerc, args []string) error { + editHeaders := (config.Compose.EditHeaders || r.Edit) && !r.NoEdit widget := aerc.SelectedTabContent().(widgets.ProvidesMessage) acct := widget.SelectedAccount() @@ -132,7 +108,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { recSet.AddList(to) - if replyAll { + if r.All { // order matters, due to the deduping // in order of importance, first parse the To, then the Cc header @@ -181,12 +157,12 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { addTab := func() error { composer, err := widgets.NewComposer(aerc, acct, acct.AccountConfig(), acct.Worker(), editHeaders, - template, h, &original, nil) + r.Template, h, &original, nil) if err != nil { aerc.PushError("Error: " + err.Error()) return err } - if mv != nil && closeOnReply { + if mv != nil && r.Close { aerc.RemoveTab(mv, true) } @@ -206,18 +182,19 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { } case c.Sent(): store.Answered([]uint32{msg.Uid}, true, nil) - case mv != nil && closeOnReply: + case mv != nil && r.Close: + view := account.ViewMessage{Peek: true} //nolint:errcheck // who cares? - account.ViewMessage{}.Execute(aerc, []string{"-p"}) + view.Execute(aerc, []string{"view", "-p"}) } }) return nil } - if quote { - if template == "" { - template = config.Templates.QuotedReply + if r.Quote { + if r.Template == "" { + r.Template = config.Templates.QuotedReply } if crypto.IsEncrypted(msg.BodyStructure) { @@ -272,8 +249,8 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { }) return nil } else { - if template == "" { - template = config.Templates.NewMessage + if r.Template == "" { + r.Template = config.Templates.NewMessage } return addTab() } |