Skip to content

Commit

Permalink
Merge pull request #137 from dtelyukh/master
Browse files Browse the repository at this point in the history
Handle new fields in email validation response
  • Loading branch information
thrawn01 authored Oct 2, 2018
2 parents bbe57f9 + 3d83379 commit 28c4508
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions email_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type EmailVerificationParts struct {
// See the ValidateEmail method and example for more details.
//
// IsValid indicates whether an email address conforms to IETF RFC standards.
// MailboxVerification indicates whether an email address is deliverable.
// Parts records the different subfields of an email address.
// Address echoes the address provided.
// DidYouMean provides a simple recommendation in case the address is invalid or
Expand All @@ -27,13 +28,16 @@ type EmailVerificationParts struct {
// IsDisposableAddress indicates whether Mailgun thinks the address is from a known
// disposable mailbox provider.
// IsRoleAddress indicates whether Mailgun thinks the address is an email distribution list.
// Reason contains error's description.
type EmailVerification struct {
IsValid bool `json:"is_valid"`
MailboxVerification bool `json:"mailbox_verification,string"`
Parts EmailVerificationParts `json:"parts"`
Address string `json:"address"`
DidYouMean string `json:"did_you_mean"`
IsDisposableAddress bool `json:"is_disposable_address"`
IsRoleAddress bool `json:"is_role_address"`
Reason string `json:"reason"`
}

type addressParseResult struct {
Expand All @@ -48,6 +52,7 @@ func (m *MailgunImpl) ValidateEmail(email string) (EmailVerification, error) {
r := newHTTPRequest(generatePublicApiUrl(m, addressValidateEndpoint))
r.setClient(m.Client())
r.addParameter("address", email)
r.addParameter("mailbox_verification", "true")
r.setBasicAuth(basicAuthUser, m.PublicApiKey())

var response EmailVerification
Expand Down
2 changes: 2 additions & 0 deletions email_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func TestEmailValidation(t *testing.T) {
ensure.Nil(t, err)

ensure.True(t, ev.IsValid)
ensure.True(t, ev.MailboxVerification)
ensure.False(t, ev.IsDisposableAddress)
ensure.False(t, ev.IsRoleAddress)
ensure.True(t, ev.Parts.DisplayName == "")
ensure.DeepEqual(t, ev.Parts.LocalPart, "foo")
ensure.DeepEqual(t, ev.Parts.Domain, "mailgun.com")
ensure.True(t, ev.Reason == "")
}

func TestParseAddresses(t *testing.T) {
Expand Down

0 comments on commit 28c4508

Please sign in to comment.