lib/truemail/validate/mx.rb in truemail-2.2.3 vs lib/truemail/validate/mx.rb in truemail-2.3.0
- old
+ new
@@ -1,12 +1,10 @@
# frozen_string_literal: true
module Truemail
module Validate
class Mx < Truemail::Validate::Base
- require 'resolv'
-
ERROR = 'target host(s) not found'
NULL_MX_RECORD = 'null_mx_record'
def run
return false unless Truemail::Validate::Regex.check(result)
@@ -41,15 +39,15 @@
def domain_not_include_null_mx
!mail_servers.include?(Truemail::Validate::Mx::NULL_MX_RECORD)
end
def mx_records(hostname)
- domain_mx_records = Resolv::DNS.new.getresources(hostname, Resolv::DNS::Resource::IN::MX)
+ domain_mx_records = Truemail::Dns::Resolver.mx_records(hostname, configuration: configuration)
return [Truemail::Validate::Mx::NULL_MX_RECORD] if null_mx?(domain_mx_records)
- domain_mx_records.sort_by(&:preference).map do |mx_record|
- Resolv.getaddresses(mx_record.exchange.to_s)
- end.flatten
+ domain_mx_records.sort_by(&:preference).flat_map do |mx_record|
+ Truemail::Dns::Resolver.a_records(mx_record.exchange.to_s, configuration: configuration)
+ end
end
def mail_servers_found?
!mail_servers.empty?
end
@@ -62,18 +60,18 @@
fetch_target_hosts(mx_records(domain))
mail_servers_found?
end
def a_record(hostname)
- Resolv.getaddress(hostname)
+ Truemail::Dns::Resolver.a_record(hostname, configuration: configuration)
end
def hosts_from_cname_records?
- cname_records = Resolv::DNS.new.getresources(domain, Resolv::DNS::Resource::IN::CNAME)
+ cname_records = Truemail::Dns::Resolver.cname_records(domain, configuration: configuration)
return if cname_records.empty?
cname_records.each do |cname_record|
host = a_record(cname_record.name.to_s)
- hostname = Resolv.getname(host)
+ hostname = Truemail::Dns::Resolver.dns_lookup(host, configuration: configuration)
found_hosts = mx_records(hostname)
fetch_target_hosts(found_hosts.empty? ? [host] : found_hosts)
end
mail_servers_found?
end