diff --git a/cmd/orchid/conf.go b/cmd/orchid/conf.go index 6eb4471..6e7b573 100644 --- a/cmd/orchid/conf.go +++ b/cmd/orchid/conf.go @@ -20,6 +20,6 @@ type acmeConfig struct { } type mailConfig struct { - simplemail.Mail - To simplemail.FromAddress `yaml:"to"` + simplemail.Mail `yaml:",inline"` + To simplemail.FromAddress `yaml:"to"` } diff --git a/cmd/orchid/mail-templates/failed-to-find.go.html b/cmd/orchid/mail-templates/failed-to-find.go.html index e69de29..312406a 100644 --- a/cmd/orchid/mail-templates/failed-to-find.go.html +++ b/cmd/orchid/mail-templates/failed-to-find.go.html @@ -0,0 +1,10 @@ + + +
+World
+ + diff --git a/cmd/orchid/mail-templates/failed-to-find.go.txt b/cmd/orchid/mail-templates/failed-to-find.go.txt index e69de29..ab79fac 100644 --- a/cmd/orchid/mail-templates/failed-to-find.go.txt +++ b/cmd/orchid/mail-templates/failed-to-find.go.txt @@ -0,0 +1 @@ +Failed to find diff --git a/cmd/orchid/mail-templates/failed-to-renew.go.html b/cmd/orchid/mail-templates/failed-to-renew.go.html new file mode 100644 index 0000000..e69de29 diff --git a/cmd/orchid/mail-templates/failed-to-renew.go.txt b/cmd/orchid/mail-templates/failed-to-renew.go.txt new file mode 100644 index 0000000..e69de29 diff --git a/cmd/orchid/serve.go b/cmd/orchid/serve.go index a3e2524..84438b6 100644 --- a/cmd/orchid/serve.go +++ b/cmd/orchid/serve.go @@ -3,6 +3,7 @@ package main import ( "context" "embed" + "errors" "flag" "github.com/1f349/mjwt" "github.com/1f349/orchid" @@ -10,13 +11,14 @@ import ( "github.com/1f349/orchid/logger" "github.com/1f349/orchid/renewal" "github.com/1f349/orchid/servers" + "github.com/1f349/overlapfs" "github.com/1f349/simplemail" "github.com/1f349/violet/utils" "github.com/google/subcommands" _ "github.com/mattn/go-sqlite3" - "github.com/mrmelon54/cdfs" "github.com/mrmelon54/exit-reload" "gopkg.in/yaml.v3" + "io/fs" "os" "path/filepath" "sync" @@ -75,10 +77,28 @@ func normalLoad(conf startUpConfig, wd string) { logger.Logger.Fatal("Failed to load MJWT verifier public key from file", "path", filepath.Join(wd, "keys"), "err", err) } - mail, err := simplemail.New(&conf.Mail.Mail, wd, cdfs.CD(mailTemplates, "mail-templates")) + // get mail templates + mailDir := filepath.Join(wd, "mail-templates") + err = os.Mkdir(mailDir, os.ModePerm) + if err != nil && !errors.Is(err, os.ErrExist) { + return + } + wdFs := os.DirFS(mailDir) + mailTemplatesSub, err := fs.Sub(mailTemplates, "mail-templates") + if err != nil { + logger.Logger.Fatal("Failed to load embedded mail templates", "err", err) + } + templatesFS := overlapfs.OverlapFS{A: mailTemplatesSub, B: wdFs} + + // create mail sender + mail, err := simplemail.New(&conf.Mail.Mail, templatesFS) if err != nil { logger.Logger.Fatal("Failed to load email sender", "err", err) } + err = mail.Send("failed-to-find", "Test subject", conf.Mail.To.Address, map[string]any{}) + if err != nil { + logger.Logger.Fatal("Failed to send start up mail", "err", err) + } // open sqlite database db, err := orchid.InitDB(filepath.Join(wd, "orchid.db.sqlite")) diff --git a/go.mod b/go.mod index 449d163..544027c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,8 @@ go 1.23.1 require ( github.com/1f349/mjwt v0.4.1 - github.com/1f349/simplemail v0.0.4 + github.com/1f349/overlapfs v0.0.1 + github.com/1f349/simplemail v0.0.5 github.com/1f349/violet v0.0.14 github.com/AlecAivazis/survey/v2 v2.3.7 github.com/charmbracelet/log v0.4.0 @@ -24,7 +25,6 @@ require ( ) require ( - github.com/1f349/overlapfs v0.0.1 // indirect github.com/1f349/rsa-helper v0.0.2 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/becheran/wildmatch-go v1.0.0 // indirect diff --git a/go.sum b/go.sum index 03611f8..2c06266 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/1f349/overlapfs v0.0.1 h1:LAxBolrXFAgU0yqZtXg/C/aaPq3eoQSPpBc49BHuTp0 github.com/1f349/overlapfs v0.0.1/go.mod h1:I6aItQycr7nrzplmfNXp/QF9tTmKRSgY3fXmu/7Ky2o= github.com/1f349/rsa-helper v0.0.2 h1:N/fLQqg5wrjIzG6G4zdwa5Xcv9/jIPutCls9YekZr9U= github.com/1f349/rsa-helper v0.0.2/go.mod h1:VUQ++1tYYhYrXeOmVFkQ82BegR24HQEJHl5lHbjg7yg= -github.com/1f349/simplemail v0.0.4 h1:wPL/BjqC+VkKd2+4/CAY6Srqah/jffAo8OARvgiB1bQ= -github.com/1f349/simplemail v0.0.4/go.mod h1:ppAIqkvVkI6L99EefbR5NgOjpePNK/RKgeoehj5A+kU= +github.com/1f349/simplemail v0.0.5 h1:cr+8pdWhFE/+XVSO7ZTjntySbmIbTqmDy2SR9cHAPLE= +github.com/1f349/simplemail v0.0.5/go.mod h1:ppAIqkvVkI6L99EefbR5NgOjpePNK/RKgeoehj5A+kU= github.com/1f349/violet v0.0.14 h1:MpBZ4n1dJjdiIwYMTfh0PBIFll3kjqowxR6DLasafqE= github.com/1f349/violet v0.0.14/go.mod h1:iAREhm+wxnGXkmuvmBhOuhUx2T7/5w7stLYNgQGbqC8= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=