diff options
author | Ray Ganardi <ray@ganardi.xyz> | 2020-04-26 11:50:25 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-05-01 11:01:28 -0400 |
commit | b650bb30a2d3ebd527c66dc7f7b229ca238fe297 (patch) | |
tree | b5a358f488acedc41cdf4b1061b4bdc59427fe6b | |
parent | 63fb2b20062a0fe72893fbe8a1a829f98d03fe12 (diff) | |
download | aerc-b650bb30a2d3ebd527c66dc7f7b229ca238fe297.tar.gz |
Implement :header command
Usage: *header* [-f] <field> [value]
Add a new email header. If the header already exists, -f must be
specified to replace the given value.
-rw-r--r-- | commands/compose/header.go | 74 | ||||
-rw-r--r-- | doc/aerc.1.scd | 4 |
2 files changed, 78 insertions, 0 deletions
diff --git a/commands/compose/header.go b/commands/compose/header.go new file mode 100644 index 00000000..5188a8a2 --- /dev/null +++ b/commands/compose/header.go @@ -0,0 +1,74 @@ +package compose + +import ( + "fmt" + "strings" + + "git.sr.ht/~sircmpwn/aerc/commands" + "git.sr.ht/~sircmpwn/aerc/widgets" + "git.sr.ht/~sircmpwn/getopt" +) + +type Header struct{} + +var ( + headers = []string{ + "From", + "To", + "Cc", + "Bcc", + "Subject", + "Comments", + "Keywords", + } +) + +func init() { + register(Header{}) +} + +func (Header) Aliases() []string { + return []string{"header"} +} + +func (Header) Complete(aerc *widgets.Aerc, args []string) []string { + return commands.CompletionFromList(headers, args) +} + +func (Header) Execute(aerc *widgets.Aerc, args []string) error { + if len(args) < 2 { + return fmt.Errorf("Usage: %s [-f] field [value]", args[0]) + } + + opts, optind, err := getopt.Getopts(args, "f") + if err != nil { + return err + } + var ( + force bool = false + ) + for _, opt := range opts { + switch opt.Option { + case 'f': + force = true + } + } + + composer, _ := aerc.SelectedTab().(*widgets.Composer) + + if !force { + headers, _, err := composer.PrepareHeader() + if err != nil { + return err + } + + if headers.Has(strings.Title(args[optind])) { + return fmt.Errorf("Header %s already exists", args[optind]) + } + } + + composer.AddEditor(strings.Title(args[optind]), + strings.Join(args[optind+1:], " "), false) + + return nil +} diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index ec3f1718..3eb8b24d 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -318,6 +318,10 @@ message list, the message in the message viewer, etc). configuration. For details on configuring outgoing mail delivery consult *aerc-config*(5). +*header* [-f] <field> [value] + Add a new email header. If the header already exists, -f must be + specified to replace the given value. + *toggle-headers* Toggles the visibility of the message headers. |