summaryrefslogtreecommitdiff
path: root/srv/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'srv/cmd')
-rw-r--r--srv/cmd/mediocre-blog/main.go42
1 files changed, 24 insertions, 18 deletions
diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go
index 66c17ee..0a5f8b7 100644
--- a/srv/cmd/mediocre-blog/main.go
+++ b/srv/cmd/mediocre-blog/main.go
@@ -62,10 +62,6 @@ func main() {
logger.Fatal(ctx, "-static-dir or -static-proxy-url is required")
case *powSecret == "":
logger.Fatal(ctx, "-pow-secret is required")
- case *smtpAddr == "":
- logger.Fatal(ctx, "-ml-smtp-addr is required")
- case *smtpAuthStr == "":
- logger.Fatal(ctx, "-ml-smtp-auth is required")
}
publicURL, err := url.Parse(*publicURLStr)
@@ -87,14 +83,22 @@ func main() {
}
powTarget := uint32(powTargetUint)
- smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2)
- if len(smtpAuthParts) < 2 {
- logger.Fatal(ctx, "invalid -ml-smtp-auth")
- }
- smtpAuth := sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1])
- smtpSendAs := smtpAuthParts[0]
+ var mailerCfg mailinglist.MailerParams
- // initialization
+ if *smtpAddr != "" {
+ mailerCfg.SMTPAddr = *smtpAddr
+ smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2)
+ if len(smtpAuthParts) < 2 {
+ logger.Fatal(ctx, "invalid -ml-smtp-auth")
+ }
+ mailerCfg.SMTPAuth = sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1])
+ mailerCfg.SendAs = smtpAuthParts[0]
+
+ ctx = mctx.Annotate(ctx,
+ "smtpAddr", mailerCfg.SMTPAddr,
+ "smtpSendAs", mailerCfg.SendAs,
+ )
+ }
ctx = mctx.Annotate(ctx,
"publicURL", publicURL.String(),
@@ -102,10 +106,10 @@ func main() {
"listenAddr", *listenAddr,
"dataDir", *dataDir,
"powTarget", fmt.Sprintf("%x", powTarget),
- "smtpAddr", *smtpAddr,
- "smtpSendAs", smtpSendAs,
)
+ // initialization
+
if *staticDir != "" {
ctx = mctx.Annotate(ctx, "staticDir", *staticDir)
} else {
@@ -127,11 +131,13 @@ func main() {
// sugar
requirePow := func(h http.Handler) http.Handler { return requirePowMiddleware(powMgr, h) }
- mailer := mailinglist.NewMailer(mailinglist.MailerParams{
- SMTPAddr: *smtpAddr,
- SMTPAuth: smtpAuth,
- SendAs: smtpSendAs,
- })
+ var mailer mailinglist.Mailer
+ if *smtpAddr == "" {
+ logger.Info(ctx, "-smtp-addr not given, using NullMailer")
+ mailer = mailinglist.NullMailer
+ } else {
+ mailer = mailinglist.NewMailer(mailerCfg)
+ }
mlStore, err := mailinglist.NewStore(path.Join(*dataDir, "mailinglist.sqlite3"))
if err != nil {