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

feat: Add SMTPResponse type for extensions (#539)

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-10-05 18:16:49 -07:00
committed by GitHub
parent 8097b3cc8a
commit 3110183a17
11 changed files with 165 additions and 49 deletions

View File

@@ -446,10 +446,14 @@ func (s *Session) parseMailFromCmd(arg string) {
}
// Process through extensions.
extAction := event.ActionDefer
extResult := s.extHost.Events.BeforeMailAccepted.Emit(
&event.AddressParts{Local: localpart, Domain: domain})
if extResult != nil && !*extResult {
s.send("550 Mail denied by policy")
if extResult != nil {
extAction = extResult.Action
}
if extAction == event.ActionDeny {
s.send(fmt.Sprintf("%03d %s", extResult.ErrorCode, extResult.ErrorMsg))
s.logger.Warn().Msgf("Extension denied mail from <%v>", from)
return
}
@@ -462,7 +466,8 @@ func (s *Session) parseMailFromCmd(arg string) {
return
}
s.from = origin
if !s.from.ShouldAccept() {
// Ignore ShouldAccept if extensions explicitly allowed this From.
if extAction == event.ActionDefer && !s.from.ShouldAccept() {
s.send("501 Unauthorized domain")
s.logger.Warn().Msgf("Bad domain sender %s", domain)
return