Validiere Mailaddressen in der Konfiguration

This commit is contained in:
Gonne 2022-11-18 10:17:38 +01:00
parent 231c8d7fd6
commit 85b1fc7445
1 changed files with 16 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"html/template"
"io/ioutil"
"log"
"net/mail"
)
// A Config holds all the constants for the programm.
@ -122,6 +123,21 @@ func validateConfig(conf *Config) error {
err = fmt.Errorf("Validating config: Mailer type must be 'Stdout' or 'Smtp', but is '%s'.", conf.Mailer.Type)
log.Println(err.Error())
}
mailFromAddress, mailFromAddressErr := mail.ParseAddress(conf.Mailer.FromAddress)
if !(mailFromAddressErr == nil) {
err = fmt.Errorf("Validating config: Mail FromAddress could not be parsed (%w)", mailFromAddressErr)
log.Println(err)
} else {
if !(mailFromAddress.Name == "") {
err = fmt.Errorf("Validating config: Mail FromAddress must not contain a name value, but has '%s'", mailFromAddress.Name)
log.Println(err)
}
}
_, mailFromNameErr := mail.ParseAddress(string(conf.Mailer.FromName))
if !(mailFromNameErr == nil) {
err = fmt.Errorf("Validating config: Mail FromName could not be parsed (%w)", mailFromNameErr)
log.Println(err)
}
if !(conf.SQL.Type == "SQLite" || conf.SQL.Type == "Mysql") {
err = fmt.Errorf("Validating config: SQL type must be 'SQLite' or 'Mysql', but is '%s'.", conf.SQL.Type)
log.Println(err.Error())