mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
policy: Accept Root config instead of SMTP for #33
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// Addressing handles email address policy.
|
||||
type Addressing struct {
|
||||
Config config.SMTP
|
||||
Config *config.Root
|
||||
}
|
||||
|
||||
// NewRecipient parses an address into a Recipient.
|
||||
@@ -41,10 +41,12 @@ func (a *Addressing) NewRecipient(address string) (*Recipient, error) {
|
||||
// ShouldAcceptDomain indicates if Inbucket accepts mail destined for the specified domain.
|
||||
func (a *Addressing) ShouldAcceptDomain(domain string) bool {
|
||||
domain = strings.ToLower(domain)
|
||||
if a.Config.DefaultAccept && !stringutil.SliceContains(a.Config.RejectDomains, domain) {
|
||||
if a.Config.SMTP.DefaultAccept &&
|
||||
!stringutil.SliceContains(a.Config.SMTP.RejectDomains, domain) {
|
||||
return true
|
||||
}
|
||||
if !a.Config.DefaultAccept && stringutil.SliceContains(a.Config.AcceptDomains, domain) {
|
||||
if !a.Config.SMTP.DefaultAccept &&
|
||||
stringutil.SliceContains(a.Config.SMTP.AcceptDomains, domain) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -53,10 +55,12 @@ func (a *Addressing) ShouldAcceptDomain(domain string) bool {
|
||||
// ShouldStoreDomain indicates if Inbucket stores mail destined for the specified domain.
|
||||
func (a *Addressing) ShouldStoreDomain(domain string) bool {
|
||||
domain = strings.ToLower(domain)
|
||||
if a.Config.DefaultStore && !stringutil.SliceContains(a.Config.DiscardDomains, domain) {
|
||||
if a.Config.SMTP.DefaultStore &&
|
||||
!stringutil.SliceContains(a.Config.SMTP.DiscardDomains, domain) {
|
||||
return true
|
||||
}
|
||||
if !a.Config.DefaultStore && stringutil.SliceContains(a.Config.StoreDomains, domain) {
|
||||
if !a.Config.SMTP.DefaultStore &&
|
||||
stringutil.SliceContains(a.Config.SMTP.StoreDomains, domain) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -11,9 +11,11 @@ import (
|
||||
func TestShouldAcceptDomain(t *testing.T) {
|
||||
// Test with default accept.
|
||||
ap := &policy.Addressing{
|
||||
Config: config.SMTP{
|
||||
DefaultAccept: true,
|
||||
RejectDomains: []string{"a.deny.com", "deny.com"},
|
||||
Config: &config.Root{
|
||||
SMTP: config.SMTP{
|
||||
DefaultAccept: true,
|
||||
RejectDomains: []string{"a.deny.com", "deny.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
testCases := []struct {
|
||||
@@ -36,9 +38,11 @@ func TestShouldAcceptDomain(t *testing.T) {
|
||||
}
|
||||
// Test with default reject.
|
||||
ap = &policy.Addressing{
|
||||
Config: config.SMTP{
|
||||
DefaultAccept: false,
|
||||
AcceptDomains: []string{"a.allow.com", "allow.com"},
|
||||
Config: &config.Root{
|
||||
SMTP: config.SMTP{
|
||||
DefaultAccept: false,
|
||||
AcceptDomains: []string{"a.allow.com", "allow.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
testCases = []struct {
|
||||
@@ -64,9 +68,11 @@ func TestShouldAcceptDomain(t *testing.T) {
|
||||
func TestShouldStoreDomain(t *testing.T) {
|
||||
// Test with storage enabled.
|
||||
ap := &policy.Addressing{
|
||||
Config: config.SMTP{
|
||||
DefaultStore: false,
|
||||
StoreDomains: []string{"store.com", "a.store.com"},
|
||||
Config: &config.Root{
|
||||
SMTP: config.SMTP{
|
||||
DefaultStore: false,
|
||||
StoreDomains: []string{"store.com", "a.store.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
testCases := []struct {
|
||||
@@ -89,9 +95,11 @@ func TestShouldStoreDomain(t *testing.T) {
|
||||
}
|
||||
// Test with storage disabled.
|
||||
ap = &policy.Addressing{
|
||||
Config: config.SMTP{
|
||||
DefaultStore: true,
|
||||
DiscardDomains: []string{"discard.com", "a.discard.com"},
|
||||
Config: &config.Root{
|
||||
SMTP: config.SMTP{
|
||||
DefaultStore: true,
|
||||
DiscardDomains: []string{"discard.com", "a.discard.com"},
|
||||
},
|
||||
},
|
||||
}
|
||||
testCases = []struct {
|
||||
|
||||
Reference in New Issue
Block a user