Code Monkey home page Code Monkey logo

email_address's People

Contributors

afair avatar alexwayfer avatar bartoszkopinski avatar bicknoyle avatar biow0lf avatar bruno- avatar dennmart avatar eliotsykes avatar fauno avatar h-0-b avatar ivanselivanov avatar lauraeci avatar mantas avatar octave avatar onyxraven avatar petergoldstein avatar pheisiph avatar tessi avatar tk0miya avatar tspacek avatar yoones avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

email_address's Issues

Tests fails on current `master`

Hello.

I wanted to contribute (and resolve some issues), but the problem is that current master (commit 1e5a2ed) has failing tests:

> bundle exec rake
/home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-5.2.5/lib/active_support/core_ext/hash/except.rb:12: warning: method redefined; discarding old except
Run options: --seed 34484

# Running:

...................../home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
......./home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
....../home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
................/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
./home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
....................EF

Fabulous run in 24.147000s, 3.0231 runs/s, 9.4008 assertions/s.

  1) Error:
TestAR#test_validation:
ArgumentError: wrong number of arguments (given 1, expected 0)
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/value.rb:8:in `initialize'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:12:in `new'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:12:in `block in register'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/type/adapter_specific_registry.rb:38:in `call'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:20:in `lookup'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/type.rb:42:in `lookup'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:237:in `block in load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:235:in `each'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:235:in `load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:459:in `block in load_schema'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:456:in `synchronize'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:456:in `load_schema'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:346:in `attribute_types'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attribute_methods.rb:230:in `has_attribute?'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/inheritance.rb:55:in `new'
    /home/alex/Projects/ruby/email_address/test/activerecord/test_ar.rb:8:in `test_validation'

  2) Failure:
TestAR#test_datatype [/home/alex/Projects/ruby/email_address/test/activerecord/test_ar.rb:18]:
Expected: "[email protected]"
  Actual: "[email protected]"

73 runs, 227 assertions, 1 failures, 1 errors, 0 skips

Current Bundle:

> bundle list
Gems included by the bundle:
  * activemodel (5.2.5)
  * activerecord (5.2.5)
  * activesupport (5.2.5)
  * arel (9.0.0)
  * concurrent-ruby (1.1.8)
  * docile (1.3.5)
  * email_address (0.1.20)
  * i18n (1.8.10)
  * minitest (5.14.4)
  * netaddr (2.0.4)
  * rake (13.0.3)
  * simplecov (0.21.2)
  * simplecov-html (0.12.3)
  * simplecov_json_formatter (0.1.2)
  * simpleidn (0.2.1)
  * sqlite3 (1.4.2)
  * thread_safe (0.3.6)
  * tzinfo (1.2.9)
  * unf (0.1.4)
  * unf_ext (0.0.7.7)
Use `bundle info` to print more detailed information about a gem

Sometimes there is no fail, only the error:

> bundle exec rake
/home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-5.2.5/lib/active_support/core_ext/hash/except.rb:12: warning: method redefined; discarding old except
Run options: --seed 6383

# Running:

....../home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
........./home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
...........E........................../home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
/home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
./home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
.../home/alex/Projects/ruby/email_address/lib/email_address/host.rb:336: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
................

Fabulous run in 23.506989s, 3.1055 runs/s, 9.7418 assertions/s.

  1) Error:
TestAR#test_datatype:
ArgumentError: wrong number of arguments (given 1, expected 0)
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/value.rb:8:in `initialize'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:12:in `new'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:12:in `block in register'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/type/adapter_specific_registry.rb:38:in `call'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activemodel-5.2.5/lib/active_model/type/registry.rb:20:in `lookup'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/type.rb:42:in `lookup'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:237:in `block in load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:235:in `each'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attributes.rb:235:in `load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:459:in `block in load_schema'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:456:in `synchronize'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:456:in `load_schema'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/model_schema.rb:346:in `attribute_types'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/attribute_methods.rb:230:in `has_attribute?'
    /home/alex/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.5/lib/active_record/inheritance.rb:55:in `new'
    /home/alex/Projects/ruby/email_address/test/activerecord/test_ar.rb:17:in `test_datatype'

73 runs, 229 assertions, 0 failures, 1 errors, 0 skips

I guess it's because some global state between tests, which is definitely bad.

If I'll have time โ€” I can try to investigate, but it'd be easier for you, maintainer.

NoMethodError: undefined method `blank?'

Seems like a critical break in the main use-case of this gem, no?

irb(main):013:0> require 'email_address'
=> false
irb(main):014:0> EmailAddress::VERSION
=> "0.1.10"
irb(main):015:0> EmailAddress.valid? "[email protected]"
NoMethodError: undefined method `blank?' for #<EmailAddress::Exchanger:0x00007f9118b3c350>
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/email_address-0.1.10/lib/email_address/host.rb:415:in `valid_mx?'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/email_address-0.1.10/lib/email_address/host.rb:396:in `valid?'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/email_address-0.1.10/lib/email_address/address.rb:236:in `valid?'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/email_address-0.1.10/lib/email_address.rb:46:in `public_send'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/email_address-0.1.10/lib/email_address.rb:46:in `block (2 levels) in singleton class'
	from (irb):15
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/console.rb:18:in `run'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:393:in `console'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:30:in `block in <top (required)>'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
	from /Users/btalbot/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:22:in `<top (required)>'
	from /Users/btalbot/.rbenv/versions/2.4.3/bin/bundle:23:in `load'
	from /Users/btalbot/.rbenv/versions/2.4.3/bin/bundle:23:in `<main>'

Incompatible with netaddr 2.0

The netaddr gem has been refactored and v2.0 was released today (January 19th). It's not backward-compatible. Either the email_address gem needs to require < 2.0.0 or be updated to use the new version of the gem.

Gmail white labeled emails inherit google config for local_size

My company uses gmail for company emails and some of our emails return false when we check if they are valid. The issue seems to be that our emails are identified as 'google' emails and the default config for google is to use local_size: 5..64. We use a while labeled email domain and don't have such limitations so it seems like the gem is mis-identifying our addresses as google addresses.

Example:
EmailAddress.new('[email protected]', dns_lookup: :mx).valid?
=> false

Getting "Mailbox name too short" on a 4-digit mailbox name

I've read through the source code and it looks to me like a 4-digit mailbox name should be considered valid. By default it looks like it's set to 1..64, however, I still get this error:

irb(main):098:0> EmailAddress.error '[email protected]'
=> "Mailbox name too short"

I'm using Rails 4.2.8 and email_address (0.1.10).

`host_validation: :syntax` making network calls

The docs indicate that running the following will validate the email locally without any network calls:

EmailAddress.valid?('[email protected]', host_validation: :syntax)

When I run this on a list of 2000 email addresses it runs very slowly, and I get network errors that indicate that its still checking something remotely.

Am I mistaken that host_validation: :syntax should make the validation completely offline?

Trailing underscore in mailbox returns empty error

I had a user reporting that they could not reset their password in Devise. Their email has a mailbox with a trailing underscore ([email protected]), but the email_address gem is returning .valid? as false, and .error as empty string. This is different from #35 as the issue is not that we are incorrectly marking the email as invalid, but rather that we are simply returning a nil/empty error message which makes it difficult to give feedback to the user.

Hotmail email mailbox_validator is incorrect

We found some hotmail emails in our DB that are invalid according to this gem but should be valid. Hotmail seems to support underscores but the mailbox_validator for msn does not.

https://social.technet.microsoft.com/Forums/exchange/en-US/69f393aa-d555-4f8f-bb16-c636a129fc25/what-are-valid-and-invalid-email-address-characters?forum=exchangesvradminlegacy

"e.g., Windows Live Hotmail, for example, only allows creation of email addresses using alphanumerics, dot (.), underscore (_) and hyphen (-)"

Fix MSN provider

I'm using this great gem! Thx for it!

Today, we received a message that one email address: [email protected] is not valid, but it's. Outlook changed rules for email addresses, I think.

We fixed it with like this:

EmailAddress::Config.provider(
  :msn,
  domain_match: %w[msn. hotmail. outlook. live.],
  mailbox_validator: ->(m, _t) { m =~ EmailAddress::Local::STANDARD_LOCAL_REGEX }
)

It's not the best fix, but it works for us.
Is it a good idea to do PR with changes providers config?

Custom errors

I was trying customize the error messages as per the readme but was unable to get it going. I inspected EmailAddress::Config.error_messages and noticed its a nested hash. So the merge that happens in config.rb appends the keys. I think the merge needs to happen on the inner hash or a deep merge needs to happen. See below:

Default errors

{
  "en"=>{
    "email_address"=> {
        "address_unknown"=>"Unknown Email Address", 
        "domain_does_not_accept_email"=>"This domain is not configured to accept email", "domain_invalid"=>"Invalid Domain Name", 
        "domain_no_localhost"=>"localhost is not allowed for your domain name", "domain_unknown"=>"Domain name not registered", 
        "exceeds_size"=>"Address too long", 
        "incomplete_domain"=>"Domain name is incomplete", 
        "invalid_address"=>"Invalid Email Address", 
        "invalid_host"=>"Invalid Host/Domain Name", 
        "invalid_mailbox"=>"Invalid Mailbox", 
        "ip_address_forbidden"=>"IP Addresses are not allowed", "ip_address_no_localhost"=>"Localhost IP addresses are not allowed", "ipv4_address_invalid"=>"This is not a valid IPv4 address", 
        "ipv6_address_invalid"=>"This is not a valid IPv6 address", 
        "local_size_long"=>"Mailbox name too long", 
        "local_size_short"=>"Mailbox name too short", 
        "local_invalid"=>"Recipient is not valid", 
        "not_allowed"=>"Address is not allowed", 
        "server_not_available"=>"The remote email server is not available"
    }
  }
}

Overridden errors as a symbol

EmailAddress::Config.error_messages(
    invalid_address: "Please specify a valid email address"
)

Output

{
  "en"=>{
    "email_address"=> {
        "address_unknown"=>"Unknown Email Address", 
        "domain_does_not_accept_email"=>"This domain is not configured to accept email", "domain_invalid"=>"Invalid Domain Name", 
        "domain_no_localhost"=>"localhost is not allowed for your domain name", "domain_unknown"=>"Domain name not registered", 
        "exceeds_size"=>"Address too long", 
        "incomplete_domain"=>"Domain name is incomplete", 
        "invalid_address"=>"Invalid Email Address", 
        "invalid_host"=>"Invalid Host/Domain Name", 
        "invalid_mailbox"=>"Invalid Mailbox", 
        "ip_address_forbidden"=>"IP Addresses are not allowed", "ip_address_no_localhost"=>"Localhost IP addresses are not allowed", "ipv4_address_invalid"=>"This is not a valid IPv4 address", 
        "ipv6_address_invalid"=>"This is not a valid IPv6 address", 
        "local_size_long"=>"Mailbox name too long", 
        "local_size_short"=>"Mailbox name too short", 
        "local_invalid"=>"Recipient is not valid", 
        "not_allowed"=>"Address is not allowed", 
        "server_not_available"=>"The remote email server is not available"
    }
  },
  :invalid_address=>"Please specify a valid email address"
}

Overridden errors as a string

EmailAddress::Config.error_messages(
    'invalid_address' => "Please specify a valid email address"
)

Output

{
  "en"=>{
    "email_address"=> {
        "address_unknown"=>"Unknown Email Address", 
        "domain_does_not_accept_email"=>"This domain is not configured to accept email", "domain_invalid"=>"Invalid Domain Name", 
        "domain_no_localhost"=>"localhost is not allowed for your domain name", "domain_unknown"=>"Domain name not registered", 
        "exceeds_size"=>"Address too long", 
        "incomplete_domain"=>"Domain name is incomplete", 
        "invalid_address"=>"Invalid Email Address", 
        "invalid_host"=>"Invalid Host/Domain Name", 
        "invalid_mailbox"=>"Invalid Mailbox", 
        "ip_address_forbidden"=>"IP Addresses are not allowed", "ip_address_no_localhost"=>"Localhost IP addresses are not allowed", "ipv4_address_invalid"=>"This is not a valid IPv4 address", 
        "ipv6_address_invalid"=>"This is not a valid IPv6 address", 
        "local_size_long"=>"Mailbox name too long", 
        "local_size_short"=>"Mailbox name too short", 
        "local_invalid"=>"Recipient is not valid", 
        "not_allowed"=>"Address is not allowed", 
        "server_not_available"=>"The remote email server is not available"
    }
  },
  'invalid_address'=>"Please specify a valid email address"
}

Overridden again

EmailAddress::Config.error_messages(
"en" => {
    'email_address' => {
        'invalid_address' => "Please specify a valid email address"
    }
})

Output

{
  "en"=>{
    "email_address"=> {
        'invalid_address'=>"Please specify a valid email address"
    }
  }
}

Relaxed is not accepting + character

Docs mention "Relaxed - A less strict form of Conventional, same character set", so I was assuming it would be a superset of conventional, but

irb(main):086:0> EmailAddress.valid? '[email protected]', host_validation: :syntax, local_format: :conventional
=> true
irb(main):087:0> EmailAddress.valid? '[email protected]', host_validation: :syntax, local_format: :relaxed
=> false

Is this expected?

Uninitialized constant

In a user activerecord model (done this way so I can have additional checks):

def check_email
      email_address = ::EmailAddress.new(email)
      if false == email_address.valid?(email)
        errors.add(:email, 'invalid email address provided')
      end
end

Error: Uninitialized constant EmailAddress

If I require 'email_address' at the top of the file my server crashes on start up with no error message (obviously the gem is in my Gemfile). Any idea what could be going on?

lloyd@xps13:~/Sites/api$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
lloyd@xps13:~/Sites/api$ rails -v
Rails 4.2.10

Also runs file in development. I can start server with RAILS_ENV set to production or staging just fine. Only on staging server is this causing an issue.

Server setup:

$:~$ ./bin/rails --version
Rails 4.2.10
$:~/$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

Undefined method when host_validation mode is "syntax"

I recently added this to my code:

EmailAddress::Config.configure(
  host_validation: :syntax
)

When I try to use EmailAddress to validate an address, an error occurs:

 3) Msb::CartsController checkout action failure email address is invalid returns 422
     Failure/Error: return if EmailAddress.valid?(email_address)
     
     NoMethodError:
       undefined method `mx_ips' for nil:NilClass
     # /Users/strike/.rvm/gems/ruby-2.4.2@memberhub-commerce-api/gems/email_address-0.1.9/lib/email_address/host.rb:417:in `valid_mx?'
     # /Users/strike/.rvm/gems/ruby-2.4.2@memberhub-commerce-api/gems/email_address-0.1.9/lib/email_address/host.rb:393:in `valid?'
     # /Users/strike/.rvm/gems/ruby-2.4.2@memberhub-commerce-api/gems/email_address-0.1.9/lib/email_address/address.rb:233:in `valid?'
     # /Users/strike/.rvm/gems/ruby-2.4.2@memberhub-commerce-api/gems/email_address-0.1.9/lib/email_address.rb:43:in `public_send'
     # /Users/strike/.rvm/gems/ruby-2.4.2@memberhub-commerce-api/gems/email_address-0.1.9/lib/email_address.rb:43:in `block (2 levels) in singleton class'

This is the line that blows up:

if self.exchangers.mx_ips.size > 0

Because this...

def exchangers
  return nil if @config[:host_type] != :email || !self.dns_enabled?
  @_exchangers ||= EmailAddress::Exchanger.cached(self.dns_name)
end

... returns nil.

v0.1.14 breaks compatibility with Ruby versions before 2.4.0

Regexp#match? was introduced in Ruby 2.4.0 and code using older versions of Ruby can expect errors related to match? not being defined.

it's used for example here

Either docs could be updated or code can check which RUBY_VERSION and based on version using match?, WDYT?

EmailAddress.matches?(address, 'google') #=> 'google' (true) Error in Version 0.1.20

In one of my projects, we use this method to detect that users had google related emails or not. but it seems to be not working on the new version.

If I use email like [email protected] it will say its a google email but when I use [email protected] will not return google and it returns false

This works in the older version 0.1.12 (Which I was using) but not in the newer version can someone let me know what is happening there?

Thanks

Emails with trailing underscores are falsely identified as invalid

I just ran email_address against a big email list I have, and it works fine except for that several emails with trailing underscores in the local part are identified as invalid emails.
I'm not that familiar with the deep details of email validation, but maybe just allow trailing underscores? Even though it might not be 100% according to some spec

Normalizing shouldn't trigger DNS lookups

When normalizing an email address not hosted with a known provider, the gem will trigger a DNS lookup. While I love the ability to check MX records during validation, it's a huge performance impact when normalizing several email addresses. This happens often when using the email address type in ActiveRecord for example.

To reproduce this issue, follow these steps in irb or so:

# Trigger an exception when an attempt to lookup DNS is made
class Resolv::DNS; def self.open(*args); raise "Please don't do that"; end; end

# Look up a random email address 
EmailAddress.normal("[email protected]")

The problem seems to be related to finding the correct provider for the email address. Here's a backtrace for the example above:

email_address-0.1.8/lib/email_address/exchanger.rb:48:in `mxers'
email_address-0.1.8/lib/email_address/exchanger.rb:29:in `each'
email_address-0.1.8/lib/email_address/exchanger.rb:87:in `block in matches?'
email_address-0.1.8/lib/email_address/exchanger.rb:83:in `each'
email_address-0.1.8/lib/email_address/exchanger.rb:83:in `matches?'
email_address-0.1.8/lib/email_address/exchanger.rb:38:in `block in provider'
email_address-0.1.8/lib/email_address/exchanger.rb:37:in `each'
email_address-0.1.8/lib/email_address/exchanger.rb:37:in `provider'
email_address-0.1.8/lib/email_address/host.rb:220:in `find_provider'
email_address-0.1.8/lib/email_address/host.rb:177:in `host_name='
email_address-0.1.8/lib/email_address/host.rb:132:in `parse'
email_address-0.1.8/lib/email_address/host.rb:91:in `initialize'
email_address-0.1.8/lib/email_address/address.rb:30:in `new'
email_address-0.1.8/lib/email_address/address.rb:30:in `initialize'
email_address-0.1.8/lib/email_address.rb:43:in `new'
email_address-0.1.8/lib/email_address.rb:43:in `block (2 levels) in singleton class'

Have Instance level config

I would love the config to not be global. It would be super useful to sometimes validate only the syntax of the email address, like maybe when importing a list of people, but other times do a more strict check like when a user is changing their own email address, or trying to send an email to a specific address.

Dots in a GSuite domain are not the same as in gmail

As you can see in the gmail help doc about dots (https://support.google.com/mail/answer/7436150?vid=0-862679329880-1516155855805&hl=en) the canonical address should disregard dots only if the domain is the gmail domain, and not if it's a g suite domain.
Specifically see the following excerpt from this help doc:
image

To prove this, let's take boomer.com as an example. It's a domain that has the MX records of g suite (see https://mxtoolbox.com/SuperTool.aspx?action=mx%3aboomer.com&run=toolpage).
When calling EmailAddress.canonical('[email protected]'), we get [email protected] but that is NOT true.

If you run the same thing on a different domain (non-g suite domain) you'll get the canonical address WITH the dots: EmailAddress.canonical('[email protected]') outputs [email protected]

Consider a slightly less generic name

I think it's not too uncommon for a rails app to have a model called "EmailAddress" if you choose to allow a person to have many email addresses for example, and don't store an email address directly on a person record.

In this case, this gem's name conflicts with the model name.

Local part containing `-_` converted to `-` with "normal"

Normal - The edited form of any input email address. Typically, it is lower-cased and minor "fixes" can be performed, depending on the configurations and email address provider.

I guess the issue here is that it doesn't specify what kind of fixes it performs. Looks like it's trying to do too much. I would expect these addresses to be normalised without any breaking changes.

Here are some examples:

irb(main):006:0> EmailAddress.new("[email protected]").normal
=> "[email protected]"
irb(main):012:0> EmailAddress.new("[email protected]").normal
=> "[email protected]"
irb(main):024:0> EmailAddress.new("[email protected]").normal
=> "[email protected]"

Valid email marked as invalid

Hi,

We recently had a user's email get marked as invalid by this Gem, but we are pretty sure it is actually valid as they have emailed us from it.

I don't want to give the users email out, but it was an <account>@live.co.uk email address. And the account was a 2 digit number, followed by 3 letters.

Weirdly there were no errors, it was just being marked invalid.

irb(main):047:0> EmailAddress.valid?(email)
=> false
irb(main):048:0> EmailAddress.error(email)
=> ""

We're using version 0.1.12 of the gem

Still making DNS requests when `dns_lookup` is `off`

We have the following in our Rails configuration for validating email addresses:

EmailAddress::Config.setting(:host_validation, :syntax)
EmailAddress::Config.setting(:dns_lookup, :off) if Rails.env.test?

This is to ensure that we aren't making network requests during testing, which slows our tests considerably and would introduce undesirable external effects. As of 0.1.14, this seems to have no effect, and DNS lookups are performed throughout our test suite. Previously, we were using version 0.1.13 and it appeared to be working fine.

Typo on README.md

In the main README the following line is wrong

EmailAddress::Config.setting( local_format: :relaxed )

it should be

EmailAddress::Config.setting( :local_format, :relaxed )

Go to another CI

Travis CI is pretty deprecated and buggy, as I know.

There are builds, yes, but where is their status for my PR?

image

Also you can see tycooon/memery#28 and excpt/moments#3

I'm satisfied with Cirrus CI, but GitHub Actions and Circle CI are good too.

Can judge whether target email is temporary?

Hi, I am now facing with a troublesome problem. Some people maliciously use temporary email accounts to register, logged into the site, and made bad behavior. So I want to disable the registration function of temporary email. But I how to judge target email is temporary? Can you help me? Thank!
ps: Ten Minutes Mail is one of the most famous.

Address validation `address_local` not implemented

Hello ๐Ÿ‘‹

I am about to use this gem for email validation (thanks for all your work here! you really did a lot of good things here, especially saving me from manually doing the punycode conversion).

While going through the configuration docs in your README, I noticed that you advertise the following setting:

address_local: false, Allow localhost, no domain, or local subdomains.

However, after testing it, I found it to not function. After reading through the source code of this gem, I couldn't find any place where you implement this setting.

This is how I use it:

EmailAddress.new(
  email_string,
  host_validation: :syntax,
  host_encoding: :punycode,
  local_format: :standard,
  local_encoding: :unicode,
  address_local: false
)

Maybe I am using the gem wrong, but to me it looks like this feature is not implemented.

We could either:

  1. remove it's description from the README
  2. implement the feature

cheers,
tessi

EmailAddress.normal can be extremely slow for certain mail addresses

I played around with our Rails app, which uses EmailAddress.normal('some_mail_address', host_encoding: :unicode) to show previously normalized mail addresses in a format which is more readable to our Users, to test something unrelated to this issue.

After creating a fake User with the mail address [email protected], I noticed that the view which uses EmailAddress.normal('[email protected]', host_encoding: :unicode) took a few seconds to render.

After some debugging, I found that I could reproduce this issue (IRB output):

require 'benchmark'
=> true
require 'email_address'
=> true
puts Benchmark.measure { EmailAddress.normal("[email protected]", host_encoding: :unicode) }
  0.002057   0.001057   0.003114 (  4.149702)
=> nil

So calling EmailAddress.normal in this case takes more than 4 seconds (!) on my 2018 MacBook Pro with Ruby 2.6.5 and version 0.1.12 of this gem installed.

Error

I kept getting this error undefined method my_email_attribute' for #User:0x00007fd032841908` could anyone help

user@localhost not considered valid

A dot seems expected in the hostname for it to be considered valid. Am I mistaking or is it a bug?

  • ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
  • Rails 5.1.4
irb(main):003:0> EmailAddress::VERSION
=> "0.1.6"
irb(main):005:0> EmailAddress.valid?("user@localhost", dns_lookup: :off, host_validation: :syntax)
=> false

Validating common email typos without MX/network lookup, using public suffix gem

I'm researching preventing common TLD and public suffix typos like "[email protected]", whilst avoiding an MX lookup for performance reasons.

One proposed solution is to check the address domain against the public suffix database using strict validation:

PublicSuffix.valid?("gmail.cpm", default_rule: nil)
# => false

PublicSuffix.valid?("gmail.com", default_rule: nil)
# => true

Do you think this is something that would be a worthwhile addition to the email_address gem, perhaps as a host_validation: :public_suffix option?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.