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>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package notification
|
|
|
|
import (
|
|
"fmt"
|
|
"net/mail"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
)
|
|
|
|
// FileNotifier a notifier to send emails to SMTP servers.
|
|
type FileNotifier struct {
|
|
path string
|
|
}
|
|
|
|
// NewFileNotifier create an FileNotifier writing the notification into a file.
|
|
func NewFileNotifier(configuration schema.FileSystemNotifierConfiguration) *FileNotifier {
|
|
return &FileNotifier{
|
|
path: configuration.Filename,
|
|
}
|
|
}
|
|
|
|
// StartupCheck implements the startup check provider interface.
|
|
func (n *FileNotifier) StartupCheck() (err error) {
|
|
dir := filepath.Dir(n.path)
|
|
if _, err := os.Stat(dir); err != nil {
|
|
if os.IsNotExist(err) {
|
|
if err = os.MkdirAll(dir, fileNotifierMode); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
return err
|
|
}
|
|
} else if _, err = os.Stat(n.path); err != nil {
|
|
if !os.IsNotExist(err) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return os.WriteFile(n.path, []byte(""), fileNotifierMode)
|
|
}
|
|
|
|
// Send send a identity verification link to a user.
|
|
func (n *FileNotifier) Send(recipient mail.Address, subject, body, _ string) error {
|
|
content := fmt.Sprintf("Date: %s\nRecipient: %s\nSubject: %s\nBody: %s", time.Now(), recipient, subject, body)
|
|
|
|
return os.WriteFile(n.path, []byte(content), fileNotifierMode)
|
|
}
|