27 lines
644 B
Go
27 lines
644 B
Go
package rules
|
|
|
|
import "strings"
|
|
|
|
// BlocklistRule rejects emails from configured senders.
|
|
type BlocklistRule struct {
|
|
emails map[string]bool
|
|
}
|
|
|
|
// NewBlocklistRule creates a blocklist rule from a list of email addresses.
|
|
func NewBlocklistRule(emails []string) *BlocklistRule {
|
|
m := make(map[string]bool, len(emails))
|
|
for _, e := range emails {
|
|
m[strings.ToLower(e)] = true
|
|
}
|
|
return &BlocklistRule{emails: m}
|
|
}
|
|
|
|
func (r *BlocklistRule) Name() string { return "blocklist" }
|
|
|
|
func (r *BlocklistRule) Evaluate(ctx EmailContext) RuleResult {
|
|
if r.emails[strings.ToLower(ctx.Sender)] {
|
|
return Reject("blocked sender")
|
|
}
|
|
return Accept()
|
|
}
|