Class: ValidEmail2::Address
- Inherits:
-
Object
- Object
- ValidEmail2::Address
- Defined in:
- lib/valid_email2/address.rb
Constant Summary collapse
- PROHIBITED_DOMAIN_CHARACTERS_REGEX =
/[+!_]/- DEFAULT_RECIPIENT_DELIMITER =
'+'.freeze
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
Instance Method Summary collapse
- #blacklisted? ⇒ Boolean
- #disposable? ⇒ Boolean
-
#initialize(address) ⇒ Address
constructor
A new instance of Address.
- #subaddressed? ⇒ Boolean
- #valid? ⇒ Boolean
- #valid_mx? ⇒ Boolean
- #whitelisted? ⇒ Boolean
Constructor Details
#initialize(address) ⇒ Address
Returns a new instance of Address.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/valid_email2/address.rb', line 12 def initialize(address) @parse_error = false @raw_address = address begin @address = Mail::Address.new(address) rescue Mail::Field::ParseError @parse_error = true end @parse_error ||= address_contain_emoticons? @raw_address end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/valid_email2/address.rb', line 7 def address @address end |
Instance Method Details
#blacklisted? ⇒ Boolean
59 60 61 |
# File 'lib/valid_email2/address.rb', line 59 def blacklisted? valid? && domain_is_in?(ValidEmail2.blacklist) end |
#disposable? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/valid_email2/address.rb', line 47 def disposable? valid? && ( domain_is_in?(ValidEmail2.disposable_emails) || mx_server_is_in?(ValidEmail2.disposable_emails) ) end |
#subaddressed? ⇒ Boolean
43 44 45 |
# File 'lib/valid_email2/address.rb', line 43 def subaddressed? valid? && address.local.include?(DEFAULT_RECIPIENT_DELIMITER) end |
#valid? ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/valid_email2/address.rb', line 25 def valid? return false if @parse_error if address.domain && address.address == @raw_address domain = address.domain domain !~ PROHIBITED_DOMAIN_CHARACTERS_REGEX && # Domain needs to have at least one dot domain =~ /\./ && # Domain may not have two consecutive dots domain !~ /\.{2,}/ && # Domain may not start with a dot domain !~ /^\./ else false end end |
#valid_mx? ⇒ Boolean
63 64 65 66 67 |
# File 'lib/valid_email2/address.rb', line 63 def valid_mx? return false unless valid? mx_servers.any? end |
#whitelisted? ⇒ Boolean
55 56 57 |
# File 'lib/valid_email2/address.rb', line 55 def whitelisted? domain_is_in?(ValidEmail2.whitelist) end |