Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def domain_is_in?(address_domains, domain_list)
return true if domain_list.include?(address_domain)

tokens = address_domain.split('.')
return false if tokens.length < 3
next false if tokens.length < 3

# check only 6 elements deep
2.upto(6).each do |depth|
Expand Down
23 changes: 23 additions & 0 deletions spec/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@

expect(disposable_email_instance.send(:disposable_mx_server?)).to be_truthy
end

context "when the domain has several MX servers" do
let(:ordinary_mx_record) { double("MX", exchange: "ordinary.example", preference: 10, ttl:) }
let(:disposable_mx_record) { double("MX", exchange: "emailfake.com", preference: 20, ttl:) }

def address_with_mx_records(domain, mx_records)
allow(mock_resolv_dns).to receive(:getresources)
.with(domain, Resolv::DNS::Resource::IN::MX)
.and_return(mx_records)

described_class.new("example@#{domain}", dns_instance)
end

it "is disposable when an ordinary MX host with one dot is listed before a disposable one" do
address = address_with_mx_records("ordinary-first.example", [ordinary_mx_record, disposable_mx_record])
expect(address.disposable?).to be_truthy
end

it "is disposable when a disposable MX host is listed before an ordinary one with one dot" do
address = address_with_mx_records("disposable-first.example", [disposable_mx_record, ordinary_mx_record])
expect(address.disposable?).to be_truthy
end
end
end

describe "#valid_strict_mx?" do
Expand Down