Skip to content

Commit

Permalink
DE-1457 populate EmailVerification.IsValid field (#386)
Browse files Browse the repository at this point in the history
IsValid was never populated for v4 validations since
#218

Fixes #385
  • Loading branch information
vtopc authored Feb 6, 2025
1 parent c7963bd commit 5383a71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions email_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type EmailVerificationParts struct {
// See the ValidateEmail method and example for more details.
type EmailVerification struct {
// Indicates whether an email address conforms to IETF RFC standards.
// Deprecated: use Risk instead.
IsValid bool `json:"is_valid"`
// Indicates whether an email address is deliverable.
MailboxVerification string `json:"mailbox_verification"`
Expand All @@ -44,7 +45,7 @@ type EmailVerification struct {
Reason string `json:"reason"`
// A list of potential reasons why a specific validation may be unsuccessful. (Available in the v4 response)
Reasons []string
// Risk assessment for the provided email.
// Risk assessment for the provided email: low/medium/high/unknown.
Risk string `json:"risk"`
// Result
Result string `json:"result"`
Expand All @@ -60,7 +61,6 @@ type EngagementData struct {
}

type v4EmailValidationResp struct {
IsValid bool `json:"is_valid"`
MailboxVerification string `json:"mailbox_verification"`
Parts EmailVerificationParts `json:"parts"`
Address string `json:"address"`
Expand Down Expand Up @@ -195,7 +195,7 @@ func (m *EmailValidatorImpl) validateV4(ctx context.Context, email string, mailB
return EmailVerification{}, err
}
return EmailVerification{
IsValid: res.IsValid,
IsValid: res.Risk == "low",
MailboxVerification: res.MailboxVerification,
Parts: res.Parts,
Address: res.Address,
Expand Down
2 changes: 1 addition & 1 deletion email_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestEmailValidationV4(t *testing.T) {
assert.Equal(t, "", ev.Reason)
assert.True(t, len(ev.Reasons) != 0)
assert.Equal(t, "no-reason", ev.Reasons[0])
assert.Equal(t, "unknown", ev.Risk)
assert.Equal(t, "low", ev.Risk)
assert.Equal(t, "deliverable", ev.Result)
assert.Equal(t, "disengaged", ev.Engagement.Behavior)
assert.False(t, ev.Engagement.Engaging)
Expand Down
4 changes: 2 additions & 2 deletions mock_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func (ms *mockServer) validateEmailV4(w http.ResponseWriter, r *http.Request) {
}

var results v4EmailValidationResp
results.Risk = "unknown"
parts, err := mail.ParseAddress(r.FormValue("address"))
if err == nil {
results.IsValid = true
results.Risk = "low"
results.Parts.Domain = strings.Split(parts.Address, "@")[1]
results.Parts.LocalPart = strings.Split(parts.Address, "@")[0]
results.Parts.DisplayName = parts.Name
}
results.Reason = []string{"no-reason"}
results.Risk = "unknown"
results.Result = "deliverable"
results.Engagement = &EngagementData{
Engaging: false,
Expand Down

0 comments on commit 5383a71

Please sign in to comment.