// Location to store the mail messages.
MaildropPath string
- // Blacklisted addresses that should not accept mail.
- BlacklistedAddresses []string
+ // Addresses that should not accept mail. This should include the @domain
+ // component.
+ BlockedAddresses []string
}
func (c Config) GetTLSConfig() (*tls.Config, error) {
}
func (server *smtpServer) VerifyAddress(addr mail.Address) smtp.ReplyLine {
- if server.maildropForAddress(addr) == "" {
+ s := server.configForAddress(addr)
+ if s == nil {
return smtp.ReplyBadMailbox
}
+ for _, blocked := range s.BlockedAddresses {
+ if blocked == addr.Address {
+ return smtp.ReplyMailboxUnallowed
+ }
+ }
return smtp.ReplyOK
}
return nil
}
-func (server *smtpServer) maildropForAddress(addr mail.Address) string {
+func (server *smtpServer) configForAddress(addr mail.Address) *Server {
domain := smtp.DomainForAddress(addr)
for _, s := range server.config.Servers {
if domain == s.Domain {
- return s.MaildropPath
+ return &s
}
}
+ return nil
+}
+func (server *smtpServer) maildropForAddress(addr mail.Address) string {
+ s := server.configForAddress(addr)
+ if s != nil {
+ return s.MaildropPath
+ }
return ""
}
{
Domain: "example.com",
MaildropPath: dir,
+ BlockedAddresses: []string{
+ "blocked@example.com",
+ },
},
},
},
if s.VerifyAddress(mail.Address{Address: "unknown"}) == smtp.ReplyOK {
t.Errorf("Invalid mailbox reports to be valid")
}
+ if s.VerifyAddress(mail.Address{Address: "blocked@example.com"}) == smtp.ReplyOK {
+ t.Errorf("Blocked mailbox reports to be valid")
+ }
}
func TestMessageDelivery(t *testing.T) {