summary refs log tree commit diff stats
path: root/commands/account
diff options
context:
space:
mode:
authorDaniel Bridges <bridges2@gmail.com>2019-08-07 23:15:59 -0700
committerDrew DeVault <sir@cmpwn.com>2019-08-12 08:57:04 +0900
commit5b523880b4b4cd2abd9457b4b09c384af33be14b (patch)
treed7e939351465b461353d35d3d3ee0508cf6dcdee /commands/account
parenta1749411e61d20f701442c9c7e58464f4e0203b8 (diff)
downloadaerc-5b523880b4b4cd2abd9457b4b09c384af33be14b.tar.gz
Let user edit arbitrary headers in composer
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/compose.go36
1 files changed, 32 insertions, 4 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
+}
871cb51a052709241a'>a2d56f6 ^
99b126d ^

1076f2b
650a1fb ^
3d48f33 ^

82064af ^
1076f2b

4d55eee ^
db876f9 ^
dbf7e03 ^

4d55eee ^






dbf7e03 ^

4d55eee ^
dbf7e03 ^
4d55eee ^


dbf7e03 ^
ad4962c ^
4d55eee ^
dbf7e03 ^

4d55eee ^



dc5c070 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61