Skip to content

Commit

Permalink
Add support for null MX rfc7505
Browse files Browse the repository at this point in the history
  • Loading branch information
bb committed Sep 4, 2023
1 parent bd01c20 commit 137b197
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## unreleased
* support null MX rfc7505 #206

## Version 4.0.6
* Remove false positives https://github.com/micke/valid_email2/pull/200
* Remove unused default option https://github.com/micke/valid_email2/pull/201
Expand Down
6 changes: 6 additions & 0 deletions lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ def blacklisted?

def valid_mx?
return false unless valid?
return false if null_mx?

mx_or_a_servers.any?
end

def valid_strict_mx?
return false unless valid?
return false if null_mx?

mx_servers.any?
end
Expand Down Expand Up @@ -138,6 +140,10 @@ def mx_servers
end
end

def null_mx?
mx_servers.length == 1 && mx_servers.first.preference == 0 && mx_servers.first.exchange.length == 0
end

def mx_or_a_servers
@mx_or_a_servers ||= Resolv::DNS.open do |dns|
dns.timeouts = @dns_timeout
Expand Down
10 changes: 10 additions & 0 deletions spec/valid_email2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ def set_whitelist
user = TestUserMX.new(email: "[email protected]")
expect(user.valid?).to be_falsey
end

it "is invalid if a null mx is found" do
user = TestUserMX.new(email: "[email protected]")
expect(user.valid?).to be_falsey
end
end

describe "with strict mx validation" do
Expand All @@ -272,6 +277,11 @@ def set_whitelist
user = TestUserStrictMX.new(email: "[email protected]")
expect(user.valid?).to be_falsey
end

it "is invalid if a null mx is found" do
user = TestUserMX.new(email: "[email protected]")
expect(user.valid?).to be_falsey
end
end

describe "with dotted validation" do
Expand Down

0 comments on commit 137b197

Please sign in to comment.