Skip to content

Commit

Permalink
DE-1307 Add validate’s engagement results (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Aug 9, 2024
1 parent b39a353 commit ba82fd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions email_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type EmailVerificationParts struct {

// EmailVerification records basic facts about a validated e-mail address.
// See the ValidateEmail method and example for more details.
//
type EmailVerification struct {
// Indicates whether an email address conforms to IETF RFC standards.
IsValid bool `json:"is_valid"`
Expand All @@ -49,6 +48,18 @@ type EmailVerification struct {
Risk string `json:"risk"`
// Result
Result string `json:"result"`
// Engagement results are a macro-level view that explain an email recipient’s propensity to engage.
// https://documentation.mailgun.com/docs/inboxready/mailgun-validate/validate_engagement/
//
// Only for v4. To use the /v4 version of validations define MG_URL in the environment variable
// as `https://api.mailgun.net/v4` or set `v.SetAPIBase("https://api.mailgun.net/v4")`
Engagement *EngagementData `json:"engagement,omitempty"`
}

type EngagementData struct {
Engaging bool `json:"engaging"`
Behavior string `json:"behavior,omitempty"`
IsBot bool `json:"is_bot"`
}

type v4EmailValidationResp struct {
Expand All @@ -62,6 +73,7 @@ type v4EmailValidationResp struct {
Reason []string `json:"reason"`
Risk string `json:"risk"`
Result string `json:"result"`
Engagement *EngagementData `json:"engagement,omitempty"`
}

type addressParseResult struct {
Expand Down Expand Up @@ -202,7 +214,9 @@ func (m *EmailValidatorImpl) validateV4(ctx context.Context, email string, mailB
IsRoleAddress: res.IsRoleAddress,
Reasons: res.Reason,
Result: res.Result,
Risk: res.Risk}, nil
Risk: res.Risk,
Engagement: res.Engagement,
}, nil
}

// ParseAddresses takes a list of addresses and sorts them into valid and invalid address categories.
Expand Down
3 changes: 3 additions & 0 deletions email_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func TestEmailValidationV4(t *testing.T) {
ensure.DeepEqual(t, ev.Reasons[0], "no-reason")
ensure.DeepEqual(t, ev.Risk, "unknown")
ensure.DeepEqual(t, ev.Result, "deliverable")
ensure.DeepEqual(t, ev.Engagement.Behavior, "disengaged")
ensure.DeepEqual(t, ev.Engagement.Engaging, false)
ensure.False(t, ev.Engagement.IsBot)
}

func TestParseAddresses(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions mock_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (ms *mockServer) validateEmailV4(w http.ResponseWriter, r *http.Request) {
results.Reason = []string{"no-reason"}
results.Risk = "unknown"
results.Result = "deliverable"
results.Engagement = &EngagementData{
Engaging: false,
Behavior: "disengaged",
IsBot: false,
}
toJSON(w, results)
}

Expand Down

0 comments on commit ba82fd9

Please sign in to comment.