From 45ff7360013e9caa5e9b9ef6ff9e936170823854 Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Thu, 28 Apr 2022 09:28:16 +0200 Subject: [PATCH] also notify when received from whitelist --- app/notifier/mailnotifier.go | 31 ++++++++++++++------- app/notifier/notification.html | 8 +++--- app/notifier/notifier.go | 42 ++++++++++++++++++++++++----- app/notifier/notifier_test.go | 27 +++++++++++++++++-- app/webmention/handler.go | 6 ++--- app/webmention/recv/receive.go | 9 +++++-- app/webmention/recv/receive_test.go | 2 +- mocks/stringnotifier.go | 10 ++++--- 8 files changed, 104 insertions(+), 31 deletions(-) diff --git a/app/notifier/mailnotifier.go b/app/notifier/mailnotifier.go index 36347db..46991cc 100644 --- a/app/notifier/mailnotifier.go +++ b/app/notifier/mailnotifier.go @@ -4,7 +4,7 @@ import ( "brainbaking.com/go-jamming/app/mf" "brainbaking.com/go-jamming/common" "encoding/base64" - "github.com/rs/zerolog/log" + "fmt" "net/mail" "net/smtp" ) @@ -53,15 +53,28 @@ func sendMail(from, subject, body, toName, toAddress string) error { return c.Quit() } -func (mn *MailNotifier) NotifyReceived(wm mf.Mention, indieweb *mf.IndiewebData) { - err := sendMail( +func (mn *MailNotifier) NotifyReceived(wm mf.Mention, indieweb *mf.IndiewebData) error { + if len(mn.Conf.AdminEmail) == 0 { + return fmt.Errorf("no adminEmail provided") + } + + return sendMail( mn.Conf.AdminEmail, - "Webmention in moderation from "+wm.SourceDomain(), - BuildNotification(wm, indieweb, mn.Conf), + "Webmention received from "+wm.SourceDomain(), + buildReceivedMsg(wm, indieweb, mn.Conf), + "Go-Jamming User", + mn.Conf.AdminEmail) +} + +func (mn *MailNotifier) NotifyInModeration(wm mf.Mention, indieweb *mf.IndiewebData) error { + if len(mn.Conf.AdminEmail) == 0 { + return fmt.Errorf("no adminEmail provided") + } + + return sendMail( + mn.Conf.AdminEmail, + "Webmention in moderation from "+wm.SourceDomain(), + buildInModerationMsg(wm, indieweb, mn.Conf), "Go-Jamming User", mn.Conf.AdminEmail) - - if err != nil { - log.Err(err).Msg("Unable to send notification mail, check localhost postfix settings?") - } } diff --git a/app/notifier/notification.html b/app/notifier/notification.html index a449303..d5f2c96 100644 --- a/app/notifier/notification.html +++ b/app/notifier/notification.html @@ -2,7 +2,7 @@ - Webmention in moderation from {{ .SourceDomain }} + Webmention {{ .Action }} from {{ .SourceDomain }}