mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
df016be29e
* fix(notification): incorrect date header format The date header in the email envelopes was incorrectly formatted missing a space between the `Date:` header and the value of this header. This also refactors the notification templates system allowing people to manually override the envelope itself. * test: fix tests and linting issues * fix: misc issues * refactor: misc refactoring * docs: add example for envelope with message id * refactor: organize smtp notifier * refactor: move subject interpolation * refactor: include additional placeholders * docs: fix missing link * docs: gravity * fix: rcpt to command * refactor: remove mid * refactor: apply suggestions Co-authored-by: Amir Zarrinkafsh <nightah@me.com> * refactor: include pid Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
49 lines
889 B
Go
49 lines
889 B
Go
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"text/template"
|
|
)
|
|
|
|
func templateExists(path string) (exists bool) {
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if info.IsDir() {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
//nolint:unparam
|
|
func loadTemplate(name, category, overridePath string) (t *template.Template, err error) {
|
|
if overridePath != "" {
|
|
tPath := filepath.Join(overridePath, name)
|
|
|
|
if templateExists(tPath) {
|
|
if t, err = template.ParseFiles(tPath); err != nil {
|
|
return nil, fmt.Errorf("could not parse template at path '%s': %w", tPath, err)
|
|
}
|
|
|
|
return t, nil
|
|
}
|
|
}
|
|
|
|
data, err := embedFS.ReadFile(path.Join("src", category, name))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if t, err = template.New(name).Parse(string(data)); err != nil {
|
|
panic(fmt.Errorf("failed to parse internal template: %w", err))
|
|
}
|
|
|
|
return t, nil
|
|
}
|