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

Allow case of MX record fallback to A record #101

Merged
merged 1 commit into from
Jan 25, 2018
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
7 changes: 2 additions & 5 deletions lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ def blacklisted?
def valid_mx?
return false unless valid?

mx = []

Resolv::DNS.open do |dns|
mx.concat dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX)
return dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX).size > 0 ||
dns.getresources(address.domain, Resolv::DNS::Resource::IN::A).size > 0
end

mx.any?
end

private
Expand Down
5 changes: 5 additions & 0 deletions spec/valid_email2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class BackwardsCompatibleUser < TestModel
expect(user.valid?).to be_truthy
end

it "should be valid if A records are found" do
user = TestUserMX.new(email: "foo@ghs.google.com")
expect(user.valid?).to be_truthy
end

it "should be invalid if no mx records are found" do
user = TestUserMX.new(email: "foo@subdomain.gmail.com")
expect(user.valid?).to be_falsey
Expand Down