aboutsummaryrefslogtreecommitdiff
path: root/commands/account
diff options
context:
space:
mode:
authorSrivathsan Murali <sri@vathsan.com>2019-11-03 13:51:14 +0100
committerDrew DeVault <sir@cmpwn.com>2019-11-10 10:15:49 -0500
commit3ba69edab5f0c787424dac9649e43a7743da13ca (patch)
treebccbdd4e1844cc89f011839f0d6557012a14d1d0 /commands/account
parentad68a9e4e471eb708893ad16601ab14a4672a2da (diff)
Add Templates with Parsing
+ Changes NewComposer to return error. + Add lib to handle templates using "text/template". + Add -T option to following commands - compose. - reply - forward + Quoted replies using templates. + Forwards as body using templates + Default templates are installed similar to filters. + Templates Config in aerc.conf. - Required templates are parsed while loading config. + Add aerc-templates.7 manual for using template data.
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/compose.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go
index 039eb92..24e460b 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -24,13 +24,17 @@ func (Compose) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
- body, err := buildBody(args)
+ body, template, err := buildBody(args)
if err != nil {
return err
}
acct := aerc.SelectedAccount()
- composer := widgets.NewComposer(aerc,
- aerc.Config(), acct.AccountConfig(), acct.Worker(), nil)
+
+ composer, err := widgets.NewComposer(aerc,
+ aerc.Config(), acct.AccountConfig(), acct.Worker(), template, nil)
+ if err != nil {
+ return err
+ }
tab := aerc.NewTab(composer, "New email")
composer.OnHeaderChange("Subject", func(subject string) {
if subject == "" {
@@ -44,11 +48,11 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
return nil
}
-func buildBody(args []string) (string, error) {
- var body, headers string
- opts, optind, err := getopt.Getopts(args, "H:")
+func buildBody(args []string) (string, string, error) {
+ var body, template, headers string
+ opts, optind, err := getopt.Getopts(args, "H:T:")
if err != nil {
- return "", err
+ return "", "", err
}
for _, opt := range opts {
switch opt.Option {
@@ -60,11 +64,13 @@ func buildBody(args []string) (string, error) {
} else {
headers += opt.Value + ":\n"
}
+ case 'T':
+ template = opt.Value
}
}
posargs := args[optind:]
if len(posargs) > 1 {
- return "", errors.New("Usage: compose [-H] [body]")
+ return "", template, errors.New("Usage: compose [-H] [body]")
}
if len(posargs) == 1 {
body = posargs[0]
@@ -76,5 +82,5 @@ func buildBody(args []string) (string, error) {
body = headers + "\n\n"
}
}
- return body, nil
+ return body, template, nil
}