aboutsummaryrefslogtreecommitdiff
path: root/commands/msg/unsubscribe.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/msg/unsubscribe.go')
-rw-r--r--commands/msg/unsubscribe.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 505392d4..41159f03 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -12,13 +12,15 @@ import (
"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"
)
// Unsubscribe helps people unsubscribe from mailing lists by way of the
// List-Unsubscribe header.
-type Unsubscribe struct{}
+type Unsubscribe struct {
+ Edit bool `opt:"-e"`
+ NoEdit bool `opt:"-E"`
+}
func init() {
register(Unsubscribe{})
@@ -35,23 +37,9 @@ func (Unsubscribe) Complete(aerc *widgets.Aerc, args []string) []string {
}
// Execute runs the Unsubscribe command
-func (Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error {
- 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
- }
- }
+func (u Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error {
+ editHeaders := (config.Compose.EditHeaders || u.Edit) && !u.NoEdit
+
widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
msg, err := widget.SelectedMessage()
if err != nil {