Skip to content

Commit

Permalink
greylist fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbr0wn committed Nov 12, 2024
1 parent d6b1447 commit 5c903e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mailvalidate/email_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ func handleDeliverableResponse(resp *EmailValidation) {

func handleTemporaryFailure(req *EmailValidationRequest, resp *EmailValidation) {
switch {
case isBlacklistError(resp.SmtpResponse.Description):
blacklisted(req, resp)
case isGreylistError(resp.SmtpResponse.Description):
greylisted(req, resp)
case isMailboxFullError(resp.SmtpResponse.Description):
handleMailboxFull(resp)
case isDeliveryFailure(resp.SmtpResponse.Description, resp.SmtpResponse.ErrorCode):
handleDeliveryFailure(resp)
case isGreylistError(resp.SmtpResponse.Description):
greylisted(req, resp)
case isTLSError(resp.SmtpResponse.Description):
handleTLSRequirement(resp)
case isBlacklistError(resp.SmtpResponse.Description):
blacklisted(req, resp)
}
}

Expand Down Expand Up @@ -363,6 +363,7 @@ func isGreylistError(description string) bool {
"postgrey",
"try again in",
"deferred for",
"internal resource temporarily unavailable",
}

for _, keyword := range greylistKeywords {
Expand Down
22 changes: 22 additions & 0 deletions mailvalidate/email_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ func TestMailServerHealthIntegration(t *testing.T) {
RetryAfter: 0, // We'll check this is greater than current time
},
},
{
name: "should handle mimecast greylisting",
req: &EmailValidationRequest{
Email: "test@example.com",
FromEmail: "sender@test.com",
FromDomain: "test.com",
},
resp: &EmailValidation{
IsDeliverable: "unknown",
RetryValidation: true,
SmtpResponse: SmtpResponse{
ResponseCode: "451",
Description: "Internal resource temporarily unavailable - https://community.mimecast.com/docs/DOC-1369#451",
},
},
expected: MailServerHealth{
IsGreylisted: true,
IsBlacklisted: false,
FromEmail: "sender@test.com",
RetryAfter: 0, // We'll check this is greater than current time
},
},
{
name: "should handle temporary blacklisting",
req: &EmailValidationRequest{
Expand Down

0 comments on commit 5c903e1

Please sign in to comment.