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,41 @@
|
||||
package rules
|
||||
|
||||
// EmailContext contains the data available to rules for evaluation.
|
||||
type EmailContext struct {
|
||||
Sender string
|
||||
Subject string
|
||||
MessageID string
|
||||
}
|
||||
|
||||
// RuleResult is the output of evaluating a single rule.
|
||||
type RuleResult struct {
|
||||
Accepted bool
|
||||
Reason string
|
||||
Metadata map[string]string
|
||||
}
|
||||
|
||||
// Accept returns a passing RuleResult.
|
||||
func Accept() RuleResult {
|
||||
return RuleResult{Accepted: true}
|
||||
}
|
||||
|
||||
// Reject returns a failing RuleResult with a reason.
|
||||
func Reject(reason string) RuleResult {
|
||||
return RuleResult{Accepted: false, Reason: reason}
|
||||
}
|
||||
|
||||
// WithMetadata attaches a key-value pair to the result.
|
||||
func (r RuleResult) WithMetadata(key, value string) RuleResult {
|
||||
if r.Metadata == nil {
|
||||
r.Metadata = map[string]string{key: value}
|
||||
} else {
|
||||
r.Metadata[key] = value
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Rule evaluates an email against operator-configurable policy.
|
||||
type Rule interface {
|
||||
Name() string
|
||||
Evaluate(ctx EmailContext) RuleResult
|
||||
}
|
||||
Reference in New Issue
Block a user