Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DE-1457 populate EmailVerification.IsValid field #386

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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