mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-09 20:55:56 +00:00
add reject from origin domain feature (#375)
Add a new feature to be able to reject email *from* specific domains. Co-authored-by: Cyril DUPONT <cyd@9bis.com>
This commit is contained in:
@@ -71,6 +71,21 @@ func (a *Addressing) NewRecipient(address string) (*Recipient, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ParseOrigin parses an address into a Origin. This is used for parsing MAIL FROM argument,
|
||||
// not To headers.
|
||||
func (a *Addressing) ParseOrigin(address string) (*Origin, error) {
|
||||
local, domain, err := ParseEmailAddress(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Origin{
|
||||
Address: mail.Address{Address: address},
|
||||
addrPolicy: a,
|
||||
LocalPart: local,
|
||||
Domain: domain,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ShouldAcceptDomain indicates if Inbucket accepts mail destined for the specified domain.
|
||||
func (a *Addressing) ShouldAcceptDomain(domain string) bool {
|
||||
domain = strings.ToLower(domain)
|
||||
@@ -99,6 +114,12 @@ func (a *Addressing) ShouldStoreDomain(domain string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ShouldAcceptOriginDomain indicates if Inbucket accept mail from the specified domain.
|
||||
func (a *Addressing) ShouldAcceptOriginDomain(domain string) bool {
|
||||
domain = strings.ToLower(domain)
|
||||
return !stringutil.SliceContains(a.Config.SMTP.RejectOriginDomains, domain)
|
||||
}
|
||||
|
||||
// ParseEmailAddress unescapes an email address, and splits the local part from the domain part.
|
||||
// An error is returned if the local or domain parts fail validation following the guidelines
|
||||
// in RFC3696.
|
||||
|
||||
Reference in New Issue
Block a user