feat(notification): add durable mail delivery state
This commit is contained in:
1 parent
391c8a6cec
commit
2db585fbff
41 files changed
+4903
-108
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -36,6 +37,9 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
// defaultEmailAccount labels the only provider account of a stand that
|
||||
// never switched accounts.
|
||||
defaultEmailAccount = "default"
|
||||
defaultEmailTimeout = 10 * time.Second
|
||||
// One attempt waits at least long enough for a TLS handshake and an API
|
||||
// answer, and at most one minute so that a hung provider cannot hold a
|
||||
@@ -44,6 +48,10 @@ const (
|
||||
maxEmailTimeout = time.Minute
|
||||
)
|
||||
|
||||
// emailAccountPattern matches domain.NewMailProviderAccount: a lowercase
|
||||
// label that cannot hold the mixed-case characters of an API key.
|
||||
var emailAccountPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
|
||||
// loadMail reads the common mail settings and only the settings of the
|
||||
// selected transport, so settings of an inactive transport, including its
|
||||
// secrets, never reach Config.
|
||||
@@ -55,6 +63,7 @@ func (config *Config) loadMail(lookup LookupEnv) error {
|
||||
provider := strings.ToLower(strings.TrimSpace(valueOrDefault(lookup, "EMAIL_PROVIDER", "")))
|
||||
config.EmailProvider = EmailProvider(provider)
|
||||
config.EmailFrom = strings.TrimSpace(valueOrDefault(lookup, "EMAIL_FROM", ""))
|
||||
config.EmailAccount = strings.TrimSpace(valueOrDefault(lookup, "EMAIL_ACCOUNT", defaultEmailAccount))
|
||||
// One trailing slash is accepted and dropped so that the stored value is
|
||||
// an origin that links can be appended to.
|
||||
config.AppPublicURL = strings.TrimSuffix(strings.TrimSpace(valueOrDefault(lookup, "APP_PUBLIC_URL", "")), "/")
|
||||
@@ -109,6 +118,10 @@ func (config Config) ValidateMail() error {
|
||||
if err := validateEmailFrom(config.EmailFrom); err != nil {
|
||||
return err
|
||||
}
|
||||
// The value is not echoed: an API key pasted here must not reach logs.
|
||||
if !emailAccountPattern.MatchString(config.EmailAccount) {
|
||||
return errors.New("Config.ValidateMail - EMAIL_ACCOUNT must be a label of 1 to 64 lowercase letters, digits, '.', '_', or '-' that starts with a letter or digit")
|
||||
}
|
||||
if err := validateAppPublicURL(config.AppPublicURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user