Class: MailAuth::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/mailauth/resolver.rb

Overview

DNS for authentication. Injectable so tests can stand a hash in for a network. NotFound vs Timeout/ServerFailure matters: SPF counts a void lookup against a limit but abandons evaluation when the server didn't answer. Dnsruby rather than Resolv, which discards non-timeout rcodes and collapses SERVFAIL/REFUSED into the same empty answer as NXDOMAIN.

Defined Under Namespace

Classes: Error, NotFound, ServerFailure, Timeout

Constant Summary collapse

QUERY_TIMEOUT =
5

Instance Method Summary collapse

Constructor Details

#initialize(timeout: QUERY_TIMEOUT) ⇒ Resolver

Returns a new instance of Resolver.



18
19
20
# File 'lib/mailauth/resolver.rb', line 18

def initialize(timeout: QUERY_TIMEOUT)
  @timeout = timeout
end

Instance Method Details

#a(name) ⇒ Object



27
28
29
# File 'lib/mailauth/resolver.rb', line 27

def a(name)
  records("A", name).map { |record| record.address.to_s }
end

#aaaa(name) ⇒ Object

Dnsruby prints IPv6 in capitals; RFC 5952 §4.3 asks for lower case.



32
33
34
# File 'lib/mailauth/resolver.rb', line 32

def aaaa(name)
  records("AAAA", name).map { |record| record.address.to_s.downcase }
end

#mx(name) ⇒ Object



36
37
38
# File 'lib/mailauth/resolver.rb', line 36

def mx(name)
  records("MX", name).sort_by(&:preference).map { |record| record.exchange.to_s }
end

#ptr(address) ⇒ Object

Dnsruby puts the question name in name and the host in domainname.



41
42
43
# File 'lib/mailauth/resolver.rb', line 41

def ptr(address)
  records("PTR", IPAddr.new(address).reverse).map { |record| record.domainname.to_s }
end

#txt(name) ⇒ Object

TXT character-strings are joined into one value (RFC 7208 §3.3).



23
24
25
# File 'lib/mailauth/resolver.rb', line 23

def txt(name)
  records("TXT", name).map { |record| record.strings.join }
end