aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/state/templates.go19
-rw-r--r--lib/templates/functions.go9
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/state/templates.go b/lib/state/templates.go
index 7b877c76..22d06589 100644
--- a/lib/state/templates.go
+++ b/lib/state/templates.go
@@ -12,11 +12,16 @@ import (
"github.com/emersion/go-message/mail"
)
+type Composer interface {
+ AddAttachment(string)
+}
+
type DataSetter interface {
Data() models.TemplateData
SetHeaders(*mail.Header, *models.OriginalMail)
SetInfo(*models.MessageInfo, int, bool)
SetThreading(string, bool, int, bool)
+ SetComposer(Composer)
SetAccount(*config.AccountConfig)
SetFolder(*models.Directory)
SetRUE([]string, func(string) (int, int, int))
@@ -53,6 +58,8 @@ type templateData struct {
state *AccountState
pendingKeys []config.KeyStroke
+
+ composer Composer
}
func NewDataSetter() DataSetter {
@@ -102,6 +109,10 @@ func (d *templateData) SetFolder(folder *models.Directory) {
d.folder = folder
}
+func (d *templateData) SetComposer(c Composer) {
+ d.composer = c
+}
+
func (d *templateData) SetRUE(folders []string,
cb func(string) (int, int, int),
) {
@@ -117,6 +128,14 @@ func (d *templateData) SetPendingKeys(keys []config.KeyStroke) {
d.pendingKeys = keys
}
+func (d *templateData) Attach(s string) string {
+ if d.composer != nil {
+ d.composer.AddAttachment(s)
+ return ""
+ }
+ return fmt.Sprintf("Failed to attach: %s", s)
+}
+
func (d *templateData) Account() string {
if d.account != nil {
return d.account.Name
diff --git a/lib/templates/functions.go b/lib/templates/functions.go
index f083c8fb..692974fd 100644
--- a/lib/templates/functions.go
+++ b/lib/templates/functions.go
@@ -240,6 +240,14 @@ func join(sep string, elems []string) string {
return strings.Join(elems, sep)
}
+func split(sep string, s string) []string {
+ sp := strings.Split(s, sep)
+ for i := range sp {
+ sp[i] = strings.TrimSpace(sp[i])
+ }
+ return sp
+}
+
// removes a signature from the piped in message
func trimSignature(message string) string {
var res strings.Builder
@@ -335,6 +343,7 @@ var templateFuncs = template.FuncMap{
"humanReadable": humanReadable,
"cwd": cwd,
"join": join,
+ "split": split,
"trimSignature": trimSignature,
"compactDir": compactDir,
"match": parse.MatchCache,