feat(rules): add BlocklistRule
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user