feedback, typos, renaming
This commit is contained in:
@@ -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: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 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: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:hosts** - Get or set `spamlist:hosts` of the room (comma-separated list), eg: `spammer.com,scammer.com,morespam.com`
|
||||||
* **!pm spamlist:localparts** - Get or set `spamlist:localparts` of the room (comma-separated list), eg: `notspam,noreply,no-rely`
|
* **!pm spamlist:mailboxes** - Get or set `spamlist:mailboxes` of the room (comma-separated list), eg: `notspam,noreply,no-reply`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,9 @@ func (b *Bot) Error(ctx context.Context, roomID id.RoomID, message string, args
|
|||||||
b.log.Error(message, args...)
|
b.log.Error(message, args...)
|
||||||
err := fmt.Errorf(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 != "" {
|
if roomID != "" {
|
||||||
b.SendError(ctx, roomID, err.Error())
|
b.SendError(ctx, roomID, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,40 +145,40 @@ func (b *Bot) initCommands() commandList {
|
|||||||
},
|
},
|
||||||
{allowed: b.allowOwner}, // delimiter
|
{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)",
|
description: "only accept email from servers which seem prepared to receive it (those having valid MX records) (`true` - enable, `false` - disable)",
|
||||||
sanitizer: utils.SanitizeBoolString,
|
sanitizer: utils.SanitizeBoolString,
|
||||||
allowed: b.allowOwner,
|
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)",
|
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,
|
sanitizer: utils.SanitizeBoolString,
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: roomOptionSpamEmails,
|
key: roomOptionSpamlistEmails,
|
||||||
description: fmt.Sprintf(
|
description: fmt.Sprintf(
|
||||||
"Get or set `%s` of the room (comma-separated list), eg: `spammer@example.com,sspam@example.org`",
|
"Get or set `%s` of the room (comma-separated list), eg: `spammer@example.com,sspam@example.org`",
|
||||||
roomOptionSpamEmails,
|
roomOptionSpamlistEmails,
|
||||||
),
|
),
|
||||||
sanitizer: utils.SanitizeStringSlice,
|
sanitizer: utils.SanitizeStringSlice,
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: roomOptionSpamHosts,
|
key: roomOptionSpamlistHosts,
|
||||||
description: fmt.Sprintf(
|
description: fmt.Sprintf(
|
||||||
"Get or set `%s` of the room (comma-separated list), eg: `gmail.com,hotmail.com,outlook.com`",
|
"Get or set `%s` of the room (comma-separated list), eg: `spammer.com,scammer.com,morespam.com`",
|
||||||
roomOptionSpamHosts,
|
roomOptionSpamlistHosts,
|
||||||
),
|
),
|
||||||
sanitizer: utils.SanitizeStringSlice,
|
sanitizer: utils.SanitizeStringSlice,
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: roomOptionSpamLocalparts,
|
key: roomOptionSpamlistLocalparts,
|
||||||
description: fmt.Sprintf(
|
description: fmt.Sprintf(
|
||||||
"Get or set `%s` of the room (comma-separated list), eg: `notspam,noreply,no-rely`",
|
"Get or set `%s` of the room (comma-separated list), eg: `notspam,noreply,no-reply`",
|
||||||
roomOptionSpamLocalparts,
|
roomOptionSpamlistLocalparts,
|
||||||
),
|
),
|
||||||
sanitizer: utils.SanitizeStringSlice,
|
sanitizer: utils.SanitizeStringSlice,
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
|
|||||||
return roomID, ok
|
return roomID, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOptions returns room settings
|
// GetIFOptions returns incoming email filtering options (room settings)
|
||||||
func (b *Bot) GetOptions(roomID id.RoomID) utils.ValidationOptions {
|
func (b *Bot) GetIFOptions(roomID id.RoomID) utils.IncomingFilteringOptions {
|
||||||
cfg, err := b.getRoomSettings(roomID)
|
cfg, err := b.getRoomSettings(roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.log.Error("cannot retrieve room settings: %v", err)
|
b.log.Error("cannot retrieve room settings: %v", err)
|
||||||
|
|||||||
@@ -13,21 +13,21 @@ const acRoomSettingsKey = "cc.etke.postmoogle.settings"
|
|||||||
|
|
||||||
// option keys
|
// option keys
|
||||||
const (
|
const (
|
||||||
roomOptionOwner = "owner"
|
roomOptionOwner = "owner"
|
||||||
roomOptionMailbox = "mailbox"
|
roomOptionMailbox = "mailbox"
|
||||||
roomOptionNoSend = "nosend"
|
roomOptionNoSend = "nosend"
|
||||||
roomOptionNoSender = "nosender"
|
roomOptionNoSender = "nosender"
|
||||||
roomOptionNoRecipient = "norecipient"
|
roomOptionNoRecipient = "norecipient"
|
||||||
roomOptionNoSubject = "nosubject"
|
roomOptionNoSubject = "nosubject"
|
||||||
roomOptionNoHTML = "nohtml"
|
roomOptionNoHTML = "nohtml"
|
||||||
roomOptionNoThreads = "nothreads"
|
roomOptionNoThreads = "nothreads"
|
||||||
roomOptionNoFiles = "nofiles"
|
roomOptionNoFiles = "nofiles"
|
||||||
roomOptionPassword = "password"
|
roomOptionPassword = "password"
|
||||||
roomOptionSecuritySMTP = "spamcheck:smtp"
|
roomOptionSpamcheckSMTP = "spamcheck:smtp"
|
||||||
roomOptionSecurityMX = "spamcheck:mx"
|
roomOptionSpamcheckMX = "spamcheck:mx"
|
||||||
roomOptionSpamEmails = "spamlist:emails"
|
roomOptionSpamlistEmails = "spamlist:emails"
|
||||||
roomOptionSpamHosts = "spamlist:hosts"
|
roomOptionSpamlistHosts = "spamlist:hosts"
|
||||||
roomOptionSpamLocalparts = "spamlist:localparts"
|
roomOptionSpamlistLocalparts = "spamlist:mailboxes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type roomSettings map[string]string
|
type roomSettings map[string]string
|
||||||
@@ -82,24 +82,24 @@ func (s roomSettings) NoFiles() bool {
|
|||||||
return utils.Bool(s.Get(roomOptionNoFiles))
|
return utils.Bool(s.Get(roomOptionNoFiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s roomSettings) SecuritySMTP() bool {
|
func (s roomSettings) SpamcheckSMTP() bool {
|
||||||
return utils.Bool(s.Get(roomOptionSecuritySMTP))
|
return utils.Bool(s.Get(roomOptionSpamcheckSMTP))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s roomSettings) SecurityMX() bool {
|
func (s roomSettings) SpamcheckMX() bool {
|
||||||
return utils.Bool(s.Get(roomOptionSecurityMX))
|
return utils.Bool(s.Get(roomOptionSpamcheckMX))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s roomSettings) SpamEmails() []string {
|
func (s roomSettings) SpamlistEmails() []string {
|
||||||
return utils.StringSlice(s.Get(roomOptionSpamEmails))
|
return utils.StringSlice(s.Get(roomOptionSpamlistEmails))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s roomSettings) SpamHosts() []string {
|
func (s roomSettings) SpamlistHosts() []string {
|
||||||
return utils.StringSlice(s.Get(roomOptionSpamHosts))
|
return utils.StringSlice(s.Get(roomOptionSpamlistHosts))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s roomSettings) SpamLocalparts() []string {
|
func (s roomSettings) SpamlistLocalparts() []string {
|
||||||
return utils.StringSlice(s.Get(roomOptionSpamLocalparts))
|
return utils.StringSlice(s.Get(roomOptionSpamlistLocalparts))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentOptions converts room display settings to content options
|
// ContentOptions converts room display settings to content options
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func (s *msasession) Rcpt(to string) error {
|
|||||||
return smtp.ErrAuthRequired
|
return smtp.ErrAuthRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
validations := s.bot.GetOptions(roomID)
|
validations := s.bot.GetIFOptions(roomID)
|
||||||
if !s.validate(validations) {
|
if !s.validate(validations) {
|
||||||
return smtp.ErrAuthRequired
|
return smtp.ErrAuthRequired
|
||||||
}
|
}
|
||||||
@@ -81,15 +81,15 @@ func (s *msasession) parseAttachments(parts []*enmime.Part) []*utils.File {
|
|||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *msasession) validate(options utils.ValidationOptions) bool {
|
func (s *msasession) validate(options utils.IncomingFilteringOptions) bool {
|
||||||
spam := validator.Spam{
|
spam := validator.Spam{
|
||||||
Emails: options.SpamEmails(),
|
Emails: options.SpamlistEmails(),
|
||||||
Hosts: options.SpamHosts(),
|
Hosts: options.SpamlistHosts(),
|
||||||
Localparts: options.SpamLocalparts(),
|
Localparts: options.SpamlistLocalparts(),
|
||||||
}
|
}
|
||||||
enforce := validator.Enforce{
|
enforce := validator.Enforce{
|
||||||
MX: options.SecurityMX(),
|
MX: options.SpamcheckMX(),
|
||||||
SMTP: options.SecuritySMTP(),
|
SMTP: options.SpamcheckMX(),
|
||||||
}
|
}
|
||||||
v := validator.New(spam, enforce, s.to, s.log)
|
v := validator.New(spam, enforce, s.to, s.log)
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
type Bot interface {
|
type Bot interface {
|
||||||
AllowAuth(string, string) bool
|
AllowAuth(string, string) bool
|
||||||
GetMapping(string) (id.RoomID, 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
|
Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error
|
||||||
SetMTA(mta utils.MTA)
|
SetMTA(mta utils.MTA)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ type MTA interface {
|
|||||||
Send(from, to, data string) error
|
Send(from, to, data string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidationOptions for incoming mail
|
// IncomingFilteringOptions for incoming mail
|
||||||
type ValidationOptions interface {
|
type IncomingFilteringOptions interface {
|
||||||
SecuritySMTP() bool
|
SpamcheckSMTP() bool
|
||||||
SecurityMX() bool
|
SpamcheckMX() bool
|
||||||
SpamEmails() []string
|
SpamlistEmails() []string
|
||||||
SpamHosts() []string
|
SpamlistHosts() []string
|
||||||
SpamLocalparts() []string
|
SpamlistLocalparts() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Email object
|
// Email object
|
||||||
|
|||||||
Reference in New Issue
Block a user