~sircmpwn/aerc

Let user edit arbitrary headers in composer v1 PROPOSED

Thanks!

To git.sr.ht:~sircmpwn/aerc
   a174941..f6df46d  master -> master
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/%3C20190808061559.49505-1-bridges2%40gmail.com%3E/mbox | git am -3
Learn more about email & git

[PATCH] Let user edit arbitrary headers in composer Export this patch

Daniel Bridges
---
 commands/account/compose.go | 36 ++++++++++++++++++++++++++++++++----
 doc/aerc.1.scd              |  6 +++++-
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/commands/account/compose.go b/commands/account/compose.go
index f615c0b..fa673f0 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -1,9 +1,11 @@
 package account
 
 import (
-	"errors"
+	"regexp"
+	"strings"
 
 	"git.sr.ht/~sircmpwn/aerc/widgets"
+	"git.sr.ht/~sircmpwn/getopt"
 )
 
 type Compose struct{}
@@ -20,10 +22,11 @@ func (_ Compose) Complete(aerc *widgets.Aerc, args []string) []string {
 	return nil
 }
 
-// TODO: Accept arguments for default headers, message body
+// TODO: Accept arguments for message body
 func (_ Compose) Execute(aerc *widgets.Aerc, args []string) error {
-	if len(args) != 1 {
-		return errors.New("Usage: compose")
+	body, err := buildBody(args)
+	if err != nil {
+		return err
 	}
 	acct := aerc.SelectedAccount()
 	composer := widgets.NewComposer(
@@ -37,5 +40,30 @@ func (_ Compose) Execute(aerc *widgets.Aerc, args []string) error {
 		}
 		tab.Content.Invalidate()
 	})
+	go composer.SetContents(strings.NewReader(body))
 	return nil
 }
+
+func buildBody(args []string) (string, error) {
+	var body, headers string
+	opts, _, err := getopt.Getopts(args, "H:")
+	if err != nil {
+		return "", err
+	}
+	for _, opt := range opts {
+		switch opt.Option {
+		case 'H':
+			if strings.Index(opt.Value, ":") != -1 {
+				// ensure first colon is followed by a single space
+				re := regexp.MustCompile(`^(.*?):\s*(.*)`)
+				headers += re.ReplaceAllString(opt.Value, "$1: $2") + "\n"
+			} else {
+				headers += opt.Value + ":\n"
+			}
+		}
+	}
+	if headers != "" {
+		body = headers + "\n\n"
+	}
+	return body, nil
+}
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 10e6485..67bfba2 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -139,11 +139,15 @@ message list, the message in the message viewer, etc).
 *cf* <folder>
 	Change the folder shown in the message list.
 
-*compose*
+*compose* [-H]
 	Open the compose window to send a new email. The new email will be sent with
 	the current account's outgoing transport configuration. For details on
 	configuring outgoing mail delivery consult *aerc-config*(5).
 
+	*-H* <header>
+		Add the specified header to the message, e.g. 'compose -H "X-Custom: custom
+		value"'
+
 *filter* [options] <terms...>
 	Similar to *search*, but filters the displayed messages to only the search
 	results. See the documentation for *search* for more details.
-- 
2.20.1
Thanks!

To git.sr.ht:~sircmpwn/aerc
   a174941..f6df46d  master -> master
View this thread in the archives