diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-07-26 11:18:24 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-08-03 22:31:34 +0200 |
commit | d29c9d1a2ff82234ad1810abc6a57199340e7fd5 (patch) | |
tree | 5d87ff8313f12c288bc41466453b0ed139a20c8b /lib/state | |
parent | 0e09c05937913a938bc4987db2b6d193ed0501bd (diff) | |
download | aerc-d29c9d1a2ff82234ad1810abc6a57199340e7fd5.tar.gz |
templates: attach directly from templates
Attach a file from templates. Add a split template function.
{{- .Attach "LICENSE" -}}
or
{{range (exec "find ./doc -type f -name *.scd" "" | split "\n") -}}
{{with . }}
{{- $.Attach . -}}
{{- end}}
{{- end}}
Fixes: https://todo.sr.ht/~rjarry/aerc/109
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/state')
-rw-r--r-- | lib/state/templates.go | 19 |
1 files changed, 19 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 |