Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion notify/shoutrrr/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
// Package shoutrrr provides the shoutrrr notification service to services.
package shoutrrr

// smtpAuthUnknown is the smtp 'auth' value meaning "no method given".
// Shoutrrr resolves it to Plain/None while parsing the URL, so it must not be sent as a param.
const smtpAuthUnknown = "Unknown"

var (
barkNtfyParamScheme = []string{"http", "https"}
barkParamSound = []string{"alarm", "anticipate", "bell", "birdsong", "bloom", "calypso", "chime", "choo", "descent", "electronic", "fanfare", "glass", "gotosleep", "healthnotification", "horn", "ladder", "mailsent", "minuet", "multiwaynotification", "newmail", "newsflash", "noir", "paymentsuccess", "shake", "sherwoodforest", "silence", "spell", "suspense", "telegraph", "tiptoes", "typewriters", "update"}
genericParamRequestmethod = []string{"CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "TRACE"}
ntfyParamPriority = []string{"min", "low", "default", "high", "max"}
smtpParamAuth = []string{"None", "Unknown", "Plain", "CramMD5", "OAuth2"}
smtpParamAuth = []string{"None", smtpAuthUnknown, "Plain", "CRAMMD5", "OAuth2"}
smtpParamEncryption = []string{"Auto", "ExplicitTLS", "ImplicitTLS", "None"}
telegramParamParsemode = []string{"None", "HTML", "Markdown"}
zulipParamType = []string{"channel", "direct"}
Expand Down
22 changes: 21 additions & 1 deletion notify/shoutrrr/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@ func (s *Shoutrrr) BuildURL() (url string) {
query,
)
case "smtp":
// smtp://username:password@host[:port]/?fromaddress=X&toaddresses=Y[&fromname=X]
// smtp://username:password@host[:port]/?fromaddress=X&toaddresses=Y[&fromname=X][&timeout=Z][&encryption=E][&skiptlsverify=S]
login := s.GetURLField("password")
login = s.GetURLField("username") + util.ValueUnlessZero(login, ":"+login)
port := s.GetURLField("port")
fromAddress := s.GetParam("fromaddress")
fromName := s.GetParam("fromname")
toAddresses := s.GetParam("toaddresses")
// These must travel in the URL rather than the params.
// timeout - Shoutrrr doesn't parse params as durations.
// encryption/skiptlsverify - Shoutrrr dials with the config it parsed from
// the URL, applying the params only to a clone used afterwards.
timeout := s.GetParam("timeout")
encryption := s.GetParam("encryption")
skipTLSVerify := s.GetParam("skiptlsverify")
query := buildQuery(
queryParam("fromaddress", fromAddress),
queryParam("fromname", fromName),
queryParam("toaddresses", toAddresses),
queryParam("timeout", timeout),
queryParam("encryption", encryption),
queryParam("skiptlsverify", skipTLSVerify),
)

url = fmt.Sprintf(
Expand Down Expand Up @@ -354,6 +364,16 @@ func (s *Shoutrrr) BuildParams(info serviceinfo.ServiceInfo) *types.Params {
params[key] = util.TemplateString(value, info)
}

if s.GetType() == "smtp" {
// timeout is carried in the URL by BuildURL.
delete(params, "timeout")
// 'Unknown' auth means "no method given" and Shoutrrr
// resolves that to Plain/None when it parses the URL.
if strings.EqualFold(params["auth"], smtpAuthUnknown) {
delete(params, "auth")
}
}

return &params
}

Expand Down
Loading
Loading