1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

policy: Implement recipient domain policy for #51

- INBUCKET_SMTP_DEFAULTACCEPT
- INBUCKET_SMTP_ACCEPTDOMAINS
- INBUCKET_SMTP_REJECTDOMAINS
This commit is contained in:
James Hillyerd
2018-04-01 18:05:21 -07:00
parent 0b3c18eba9
commit a7d2b00a9c
8 changed files with 143 additions and 9 deletions

View File

@@ -329,6 +329,11 @@ func (s *Session) mailHandler(cmd string, arg string) {
s.logger.Warn().Msgf("Bad address as RCPT arg: %q, %s", addr, err)
return
}
if !recip.ShouldAccept() {
s.logger.Warn().Str("addr", addr).Msg("Rejecting recipient")
s.send("550 Relay not permitted")
return
}
if len(s.recipients) >= s.config.MaxRecipients {
s.logger.Warn().Msgf("Maximum limit of %v recipients reached",
s.config.MaxRecipients)

View File

@@ -169,6 +169,7 @@ func TestMailState(t *testing.T) {
{"RCPT TO:<u1@gmail.com>", 250},
{"RCPT TO: <u2@gmail.com>", 250},
{"RCPT TO:u3@gmail.com", 250},
{"RCPT TO:u3@deny.com", 550},
{"RCPT TO: u4@gmail.com", 250},
{"RSET", 250},
{"MAIL FROM:<john@gmail.com>", 250},
@@ -366,9 +367,11 @@ func setupSMTPServer(ds storage.Store) (s *Server, buf *bytes.Buffer, teardown f
Domain: "inbucket.local",
DomainNoStore: "bitbucket.local",
MaxRecipients: 5,
Timeout: 5,
MaxMessageBytes: 5000,
StoreMessages: true,
DefaultAccept: true,
RejectDomains: []string{"deny.com"},
Timeout: 5,
}
// Capture log output