feat(rules): add Rule interface, Pipeline, and WhitelistRule
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package rules
|
||||
|
||||
import "strings"
|
||||
|
||||
// WhitelistRule accepts emails from configured senders.
|
||||
// An empty list accepts all senders.
|
||||
type WhitelistRule struct {
|
||||
emails map[string]bool
|
||||
}
|
||||
|
||||
// NewWhitelistRule creates a whitelist rule from a list of email addresses.
|
||||
func NewWhitelistRule(emails []string) *WhitelistRule {
|
||||
m := make(map[string]bool, len(emails))
|
||||
for _, e := range emails {
|
||||
m[strings.ToLower(e)] = true
|
||||
}
|
||||
return &WhitelistRule{emails: m}
|
||||
}
|
||||
|
||||
func (r *WhitelistRule) Name() string { return "whitelist" }
|
||||
|
||||
func (r *WhitelistRule) Evaluate(ctx EmailContext) RuleResult {
|
||||
if len(r.emails) == 0 {
|
||||
return Accept()
|
||||
}
|
||||
if r.emails[strings.ToLower(ctx.Sender)] {
|
||||
return Accept()
|
||||
}
|
||||
return Reject("not whitelisted")
|
||||
}
|
||||
Reference in New Issue
Block a user