Skip to content

Commit

Permalink
Add altEmail to email validation response
Browse files Browse the repository at this point in the history
  • Loading branch information
alexopenline committed Aug 30, 2024
1 parent 31465f6 commit 456a671
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 1 addition & 5 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type VerifyEmailResponse struct {
IsRisky bool
Risk VerifyEmailRisk
Syntax mailvalidate.SyntaxValidation
AlternateEmail AlternateEmail
AlternateEmail mailvalidate.AlternateEmail
RetryValidation bool
Smtp mailvalidate.SmtpResponse
MailServerHealth mailvalidate.MailServerHealth
Expand All @@ -32,10 +32,6 @@ type VerifyEmailRisk struct {
IsPrimaryDomain bool
}

type AlternateEmail struct {
Email string
}

func BuildRequest(email string) mailvalidate.EmailValidationRequest {
firstname, lastname := mailvalidate.GenerateNames()
fromDomain, exists := os.LookupEnv("MAIL_SERVER_DOMAIN")
Expand Down
19 changes: 19 additions & 0 deletions mailvalidate/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ type EmailValidationRequest struct {
FromEmail string
CatchAllTestUser string
Dns *dns.DNS
// applicable only for email validation. Pass results from domain validation
DomainValidationParams *DomainValidationParams
}

type DomainValidationParams struct {
IsPrimaryDomain bool
PrimaryDomain string
}

type SyntaxValidation struct {
Expand All @@ -31,6 +38,10 @@ type SyntaxValidation struct {
CleanEmail string
}

type AlternateEmail struct {
Email string
}

type DomainValidation struct {
Provider string
SecureGatewayProvider string
Expand All @@ -54,6 +65,7 @@ type EmailValidation struct {
RetryValidation bool
SmtpResponse SmtpResponse
MailServerHealth MailServerHealth
AlternateEmail AlternateEmail
Error string
}

Expand Down Expand Up @@ -147,6 +159,7 @@ func ValidateEmail(validationRequest EmailValidationRequest) EmailValidation {
results.Error = fmt.Sprintf("Invalid request: %v", err)
return results
}

emailSyntaxResult := ValidateEmailSyntax(validationRequest.Email)
if !emailSyntaxResult.IsValid {
results.Error = "Invalid email address"
Expand Down Expand Up @@ -198,6 +211,12 @@ func ValidateEmail(validationRequest EmailValidationRequest) EmailValidation {

handleSmtpResponses(&validationRequest, &results)

if validationRequest.DomainValidationParams != nil {
if !validationRequest.DomainValidationParams.IsPrimaryDomain && validationRequest.DomainValidationParams.PrimaryDomain != "" {
results.AlternateEmail.Email = fmt.Sprintf("%s@%s", emailSyntaxResult.User, validationRequest.DomainValidationParams.PrimaryDomain)
}
}

return results
}

Expand Down

0 comments on commit 456a671

Please sign in to comment.