aboutsummaryrefslogtreecommitdiffstats
path: root/config/templates.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/templates.go')
-rw-r--r--config/templates.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/config/templates.go b/config/templates.go
new file mode 100644
index 00000000..2f581e44
--- /dev/null
+++ b/config/templates.go
@@ -0,0 +1,62 @@
+package config
+
+import (
+ "path"
+ "strings"
+
+ "git.sr.ht/~rjarry/aerc/lib/templates"
+ "git.sr.ht/~rjarry/aerc/logging"
+ "github.com/go-ini/ini"
+)
+
+type TemplateConfig struct {
+ TemplateDirs []string `ini:"template-dirs" delim:":"`
+ NewMessage string `ini:"new-message"`
+ QuotedReply string `ini:"quoted-reply"`
+ Forwards string `ini:"forwards"`
+}
+
+func defaultTemplatesConfig() TemplateConfig {
+ return TemplateConfig{
+ TemplateDirs: []string{},
+ NewMessage: "new_message",
+ QuotedReply: "quoted_reply",
+ Forwards: "forward_as_body",
+ }
+}
+
+func (config *AercConfig) parseTemplates(file *ini.File) error {
+ if templatesSec, err := file.GetSection("templates"); err == nil {
+ if err := templatesSec.MapTo(&config.Templates); err != nil {
+ return err
+ }
+ templateDirs := templatesSec.Key("template-dirs").String()
+ if templateDirs != "" {
+ config.Templates.TemplateDirs = strings.Split(templateDirs, ":")
+ }
+ }
+
+ // append default paths to template-dirs
+ for _, dir := range SearchDirs {
+ config.Templates.TemplateDirs = append(
+ config.Templates.TemplateDirs, path.Join(dir, "templates"),
+ )
+ }
+
+ // we want to fail during startup if the templates are not ok
+ // hence we do dummy executes here
+ t := config.Templates
+ if err := templates.CheckTemplate(t.NewMessage, t.TemplateDirs); err != nil {
+ return err
+ }
+ if err := templates.CheckTemplate(t.QuotedReply, t.TemplateDirs); err != nil {
+ return err
+ }
+ if err := templates.CheckTemplate(t.Forwards, t.TemplateDirs); err != nil {
+ return err
+ }
+
+ logging.Debugf("aerc.conf: [templates] %#v", config.Templates)
+
+ return nil
+}