Class: ValidateEmail
- Inherits:
-
Object
- Object
- ValidateEmail
- Defined in:
- lib/valid_email/validate_email.rb
Class Method Summary collapse
- .ban_disposable_email?(value) ⇒ Boolean
- .mx_valid?(value, fallback = false) ⇒ Boolean
- .mx_valid_with_fallback?(value) ⇒ Boolean
- .valid?(value, user_options = {}) ⇒ Boolean
Class Method Details
.ban_disposable_email?(value) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/valid_email/validate_email.rb', line 52 def ban_disposable_email?(value) r = false begin m = Mail::Address.new(value) r = !BanDisposableEmailValidator.config.include?(m.domain) if m.domain rescue Exception => e r = false end r end |
.mx_valid?(value, fallback = false) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/valid_email/validate_email.rb', line 30 def mx_valid?(value, fallback=false) r = false begin m = Mail::Address.new(value) if m.domain mx = [] Resolv::DNS.open do |dns| mx.concat dns.getresources(m.domain, Resolv::DNS::Resource::IN::MX) mx.concat dns.getresources(m.domain, Resolv::DNS::Resource::IN::A) if fallback end r = mx.size > 0 end rescue Exception =>e r = false end r end |
.mx_valid_with_fallback?(value) ⇒ Boolean
48 49 50 |
# File 'lib/valid_email/validate_email.rb', line 48 def mx_valid_with_fallback?(value) mx_valid?(value, true) end |
.valid?(value, user_options = {}) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/valid_email/validate_email.rb', line 5 def valid?(value, ={}) = { :mx => false, :message => nil }.merge!() r = false begin m = Mail::Address.new(value) # We must check that value contains a domain and that value is an email address r = m.domain && m.address == value # Check that domain consists of dot-atom-text elements > 1 # In mail 2.6.1, domains are invalid per rfc2822 are parsed when they shouldn't # This is to make sure we cover those cases domain_dot_elements = m.domain.split(/\./) r &&= domain_dot_elements.none?(&:blank?) && domain_dot_elements.size > 1 # Check if domain has DNS MX record if r && [:mx] require 'valid_email/mx_validator' r &&= mx_valid?(email) end rescue Exception => e r = false end r end |