Sha256: b8a1fed52f77028f30add00a52f507f7a709f97fe4d573c6e4eaa7f16701874b
Contents?: true
Size: 1.27 KB
Versions: 5
Compression:
Stored size: 1.27 KB
Contents
require "email_assessor" require "resolv" require "mail" module EmailAssessor class Address attr_accessor :address def initialize(address) @parse_error = false @raw_address = address begin @address = Mail::Address.new(address) rescue Mail::Field::ParseError @parse_error = true end end def valid? return false if @parse_error if address.domain && address.address == @raw_address domain = address.domain domain.match?(%r{\.}) && # Valid address domain must contain a period !domain.match?(%r{\.{2,}}) && # Valid address domain cannot have consecutive periods !domain.match?(%r{^\.}) && # Valid address domain cannot start with a period domain.match?(%r{[a-z]\Z}i) # Valid address domain must end with letters else false end end def disposable? valid? && EmailAssessor.domain_is_disposable?(address.domain) end def blacklisted? valid? && EmailAssessor.domain_is_blacklisted?(address.domain) end def valid_mx? return false unless valid? mx = [] Resolv::DNS.open do |dns| mx.concat dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX) end mx.any? end end end
Version data entries
5 entries across 5 versions & 1 rubygems