From 6f4da5938773b41d912707fa9ef38d401b4805da Mon Sep 17 00:00:00 2001 From: Aine Date: Mon, 10 Oct 2022 09:41:22 +0300 Subject: [PATCH] feedback, typos, renaming --- README.md | 4 ++-- bot/bot.go | 4 +++- bot/command.go | 20 +++++++++--------- bot/email.go | 4 ++-- bot/settings_room.go | 50 ++++++++++++++++++++++---------------------- smtp/msasession.go | 14 ++++++------- smtp/mta.go | 2 +- utils/email.go | 14 ++++++------- 8 files changed, 57 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 192ab15..40800a7 100644 --- a/README.md +++ b/README.md @@ -257,8 +257,8 @@ If you want to change them - check available options in the help message (`!pm h * **!pm spamcheck:mx** - only accept email from servers which seem prepared to receive it (those having valid MX records) (`true` - enable, `false` - disable) * **!pm spamcheck:smtp** - only accept email from servers which seem prepared to receive it (those listening on an SMTP port) (`true` - enable, `false` - disable) * **!pm spamlist:emails** - Get or set `spamlist:emails` of the room (comma-separated list), eg: `spammer@example.com,sspam@example.org` -* **!pm spamlist:hosts** - Get or set `spamlist:hosts` of the room (comma-separated list), eg: `gmail.com,hotmail.com,outlook.com` -* **!pm spamlist:localparts** - Get or set `spamlist:localparts` of the room (comma-separated list), eg: `notspam,noreply,no-rely` +* **!pm spamlist:hosts** - Get or set `spamlist:hosts` of the room (comma-separated list), eg: `spammer.com,scammer.com,morespam.com` +* **!pm spamlist:mailboxes** - Get or set `spamlist:mailboxes` of the room (comma-separated list), eg: `notspam,noreply,no-reply` --- diff --git a/bot/bot.go b/bot/bot.go index dbcb11c..fe8f7a8 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -73,7 +73,9 @@ func (b *Bot) Error(ctx context.Context, roomID id.RoomID, message string, args b.log.Error(message, args...) err := fmt.Errorf(message, args...) - sentry.GetHubFromContext(ctx).CaptureException(err) + if hub := sentry.GetHubFromContext(ctx); hub != nil { + sentry.GetHubFromContext(ctx).CaptureException(err) + } if roomID != "" { b.SendError(ctx, roomID, err.Error()) } diff --git a/bot/command.go b/bot/command.go index ffbe068..df135b3 100644 --- a/bot/command.go +++ b/bot/command.go @@ -145,40 +145,40 @@ func (b *Bot) initCommands() commandList { }, {allowed: b.allowOwner}, // delimiter { - key: roomOptionSecurityMX, + key: roomOptionSpamcheckMX, description: "only accept email from servers which seem prepared to receive it (those having valid MX records) (`true` - enable, `false` - disable)", sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, { - key: roomOptionSecuritySMTP, + key: roomOptionSpamcheckSMTP, description: "only accept email from servers which seem prepared to receive it (those listening on an SMTP port) (`true` - enable, `false` - disable)", sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, { - key: roomOptionSpamEmails, + key: roomOptionSpamlistEmails, description: fmt.Sprintf( "Get or set `%s` of the room (comma-separated list), eg: `spammer@example.com,sspam@example.org`", - roomOptionSpamEmails, + roomOptionSpamlistEmails, ), sanitizer: utils.SanitizeStringSlice, allowed: b.allowOwner, }, { - key: roomOptionSpamHosts, + key: roomOptionSpamlistHosts, description: fmt.Sprintf( - "Get or set `%s` of the room (comma-separated list), eg: `gmail.com,hotmail.com,outlook.com`", - roomOptionSpamHosts, + "Get or set `%s` of the room (comma-separated list), eg: `spammer.com,scammer.com,morespam.com`", + roomOptionSpamlistHosts, ), sanitizer: utils.SanitizeStringSlice, allowed: b.allowOwner, }, { - key: roomOptionSpamLocalparts, + key: roomOptionSpamlistLocalparts, description: fmt.Sprintf( - "Get or set `%s` of the room (comma-separated list), eg: `notspam,noreply,no-rely`", - roomOptionSpamLocalparts, + "Get or set `%s` of the room (comma-separated list), eg: `notspam,noreply,no-reply`", + roomOptionSpamlistLocalparts, ), sanitizer: utils.SanitizeStringSlice, allowed: b.allowOwner, diff --git a/bot/email.go b/bot/email.go index d69da1d..9f9c892 100644 --- a/bot/email.go +++ b/bot/email.go @@ -59,8 +59,8 @@ func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) { return roomID, ok } -// GetOptions returns room settings -func (b *Bot) GetOptions(roomID id.RoomID) utils.ValidationOptions { +// GetIFOptions returns incoming email filtering options (room settings) +func (b *Bot) GetIFOptions(roomID id.RoomID) utils.IncomingFilteringOptions { cfg, err := b.getRoomSettings(roomID) if err != nil { b.log.Error("cannot retrieve room settings: %v", err) diff --git a/bot/settings_room.go b/bot/settings_room.go index 1dfea96..3298d4f 100644 --- a/bot/settings_room.go +++ b/bot/settings_room.go @@ -13,21 +13,21 @@ const acRoomSettingsKey = "cc.etke.postmoogle.settings" // option keys const ( - roomOptionOwner = "owner" - roomOptionMailbox = "mailbox" - roomOptionNoSend = "nosend" - roomOptionNoSender = "nosender" - roomOptionNoRecipient = "norecipient" - roomOptionNoSubject = "nosubject" - roomOptionNoHTML = "nohtml" - roomOptionNoThreads = "nothreads" - roomOptionNoFiles = "nofiles" - roomOptionPassword = "password" - roomOptionSecuritySMTP = "spamcheck:smtp" - roomOptionSecurityMX = "spamcheck:mx" - roomOptionSpamEmails = "spamlist:emails" - roomOptionSpamHosts = "spamlist:hosts" - roomOptionSpamLocalparts = "spamlist:localparts" + roomOptionOwner = "owner" + roomOptionMailbox = "mailbox" + roomOptionNoSend = "nosend" + roomOptionNoSender = "nosender" + roomOptionNoRecipient = "norecipient" + roomOptionNoSubject = "nosubject" + roomOptionNoHTML = "nohtml" + roomOptionNoThreads = "nothreads" + roomOptionNoFiles = "nofiles" + roomOptionPassword = "password" + roomOptionSpamcheckSMTP = "spamcheck:smtp" + roomOptionSpamcheckMX = "spamcheck:mx" + roomOptionSpamlistEmails = "spamlist:emails" + roomOptionSpamlistHosts = "spamlist:hosts" + roomOptionSpamlistLocalparts = "spamlist:mailboxes" ) type roomSettings map[string]string @@ -82,24 +82,24 @@ func (s roomSettings) NoFiles() bool { return utils.Bool(s.Get(roomOptionNoFiles)) } -func (s roomSettings) SecuritySMTP() bool { - return utils.Bool(s.Get(roomOptionSecuritySMTP)) +func (s roomSettings) SpamcheckSMTP() bool { + return utils.Bool(s.Get(roomOptionSpamcheckSMTP)) } -func (s roomSettings) SecurityMX() bool { - return utils.Bool(s.Get(roomOptionSecurityMX)) +func (s roomSettings) SpamcheckMX() bool { + return utils.Bool(s.Get(roomOptionSpamcheckMX)) } -func (s roomSettings) SpamEmails() []string { - return utils.StringSlice(s.Get(roomOptionSpamEmails)) +func (s roomSettings) SpamlistEmails() []string { + return utils.StringSlice(s.Get(roomOptionSpamlistEmails)) } -func (s roomSettings) SpamHosts() []string { - return utils.StringSlice(s.Get(roomOptionSpamHosts)) +func (s roomSettings) SpamlistHosts() []string { + return utils.StringSlice(s.Get(roomOptionSpamlistHosts)) } -func (s roomSettings) SpamLocalparts() []string { - return utils.StringSlice(s.Get(roomOptionSpamLocalparts)) +func (s roomSettings) SpamlistLocalparts() []string { + return utils.StringSlice(s.Get(roomOptionSpamlistLocalparts)) } // ContentOptions converts room display settings to content options diff --git a/smtp/msasession.go b/smtp/msasession.go index 1c4df92..51d98be 100644 --- a/smtp/msasession.go +++ b/smtp/msasession.go @@ -58,7 +58,7 @@ func (s *msasession) Rcpt(to string) error { return smtp.ErrAuthRequired } - validations := s.bot.GetOptions(roomID) + validations := s.bot.GetIFOptions(roomID) if !s.validate(validations) { return smtp.ErrAuthRequired } @@ -81,15 +81,15 @@ func (s *msasession) parseAttachments(parts []*enmime.Part) []*utils.File { return files } -func (s *msasession) validate(options utils.ValidationOptions) bool { +func (s *msasession) validate(options utils.IncomingFilteringOptions) bool { spam := validator.Spam{ - Emails: options.SpamEmails(), - Hosts: options.SpamHosts(), - Localparts: options.SpamLocalparts(), + Emails: options.SpamlistEmails(), + Hosts: options.SpamlistHosts(), + Localparts: options.SpamlistLocalparts(), } enforce := validator.Enforce{ - MX: options.SecurityMX(), - SMTP: options.SecuritySMTP(), + MX: options.SpamcheckMX(), + SMTP: options.SpamcheckMX(), } v := validator.New(spam, enforce, s.to, s.log) diff --git a/smtp/mta.go b/smtp/mta.go index f095d91..c219b77 100644 --- a/smtp/mta.go +++ b/smtp/mta.go @@ -16,7 +16,7 @@ import ( type Bot interface { AllowAuth(string, string) bool GetMapping(string) (id.RoomID, bool) - GetOptions(id.RoomID) utils.ValidationOptions + GetIFOptions(id.RoomID) utils.IncomingFilteringOptions Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error SetMTA(mta utils.MTA) } diff --git a/utils/email.go b/utils/email.go index 6f7e279..12c9814 100644 --- a/utils/email.go +++ b/utils/email.go @@ -19,13 +19,13 @@ type MTA interface { Send(from, to, data string) error } -// ValidationOptions for incoming mail -type ValidationOptions interface { - SecuritySMTP() bool - SecurityMX() bool - SpamEmails() []string - SpamHosts() []string - SpamLocalparts() []string +// IncomingFilteringOptions for incoming mail +type IncomingFilteringOptions interface { + SpamcheckSMTP() bool + SpamcheckMX() bool + SpamlistEmails() []string + SpamlistHosts() []string + SpamlistLocalparts() []string } // Email object