valid_email 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 066fc2f842dfd3d3afc0df730f7e44951a6692aa035b378036e2587731073dd1
4
- data.tar.gz: a21522fd9b8453ff36fc960fdbcd916843fe3232a4a87f2528611f1d8f9f693c
3
+ metadata.gz: 912afd4576d829541b67adb5b5830c4c31d8bf7f7005092957a655f9dbcf07ba
4
+ data.tar.gz: a0647b0db0f921c5159c585fb2298211f1be85cafe138fd426ebf1ec5d32049d
5
5
  SHA512:
6
- metadata.gz: f6dbf19e9942dacf1d749d3027d1d20e130a64c1418c7cae5e43165d0ddf304d46f02a530658760626af4cbe6cb686fcb30964bfd8512967e74c7599712c06cf
7
- data.tar.gz: cd549c34b78c76ef33ed9e60b3d683706a6fde6bcf2e5dcf7223dbf26f46a7556bbcb3325e8a862f1708b80072fce0f5c4b2e8bef479178d9633ffabd8224ddd
6
+ metadata.gz: bc35a4b3adb7b092b9158dff8d2d2c16bd1e5cc5f59b91f521ea0cbfd30d0bd5c4c523f2990752486036fed8db8908566228eee18b7f3c282f7b9824cca0b1f2
7
+ data.tar.gz: 44233a8c92c72e597c3b10bdc052e17c1e8ead83c87dfab94103f7341d9b2b32348f555fbe4fdee2af0e474c7af92f253b3421fb4ed37aed779eabc30c1a9cbd
data/.travis.yml CHANGED
@@ -1,15 +1,18 @@
1
- sudo: false
2
- language: ruby
1
+ before_install:
2
+ - gem install bundler:1.17.3
3
3
  cache: bundler
4
+ dist: xenial
5
+ language: ruby
4
6
  rvm:
5
7
  - 1.9.3
6
- - 2.0.0
8
+ - 2.0
7
9
  - 2.1
8
- - 2.2.1
9
- - 2.2.2
10
- - 2.3.3
11
- - 2.4.0
12
- - jruby-19mode
13
- - jruby-20mode
14
- before_install:
15
- - gem install bundler:1.17.3
10
+ - 2.2
11
+ - 2.2
12
+ - 2.3
13
+ - 2.4
14
+ - 2.5
15
+ - 2.6
16
+ - 2.7
17
+ - 3.0
18
+ - jruby-head
data/README.md CHANGED
@@ -1,98 +1,130 @@
1
- # Purpose
1
+ # Valid Email
2
2
 
3
- It validates email for application use (registering a new account for example)
3
+ ## Purpose
4
4
 
5
- # Usage
5
+ It validates email for application use (registering a new account for example).
6
6
 
7
- In your Gemfile :
8
-
9
- gem 'valid_email'
7
+ ## Usage
10
8
 
9
+ In your `Gemfile`:
10
+ ```ruby
11
+ gem 'valid_email'
12
+ ```
11
13
 
12
- In your code :
14
+ In your code:
15
+ ```ruby
16
+ require 'valid_email'
13
17
 
14
- require 'valid_email'
15
- class Person
16
- include ActiveModel::Validations
17
- attr_accessor :name, :email
18
+ class Person
19
+ include ActiveModel::Validations
20
+ attr_accessor :name, :email
18
21
 
19
- validates :name, :presence => true, :length => { :maximum => 100 }
20
- validates :email, :presence => true, :email => true
21
- end
22
+ validates :name, presence: true, length: { maximum: 100 }
23
+ validates :email, presence: true, email: true
24
+ end
22
25
 
23
26
 
24
- p = Person.new
25
- p.name = "hallelujah"
26
- p.email = "john@doe.com"
27
- p.valid? # => true
27
+ person = Person.new
28
+ person.name = 'hallelujah'
29
+ person.email = 'john@doe.com'
30
+ person.valid? # => true
28
31
 
29
- p.email = "john@doe"
30
- p.valid? # => false
32
+ person.email = 'john@doe'
33
+ person.valid? # => false
31
34
 
32
- p.email = "John Does <john@doe.com>"
33
- p.valid? # => false
35
+ person.email = 'John Does <john@doe.com>'
36
+ person.valid? # => false
37
+ ```
34
38
 
35
39
  You can check if email domain has MX record:
36
-
37
- validates :email, :email => {:mx => true, :message => I18n.t('validations.errors.models.user.invalid_email')}
40
+ ```ruby
41
+ validates :email,
42
+ email: {
43
+ mx: true,
44
+ message: I18n.t('validations.errors.models.user.invalid_email')
45
+ }
46
+ ```
38
47
 
39
48
  Or
40
49
 
41
- validates :email, :email => {:message => I18n.t('validations.errors.models.user.invalid_email')}, :mx => {:message => I18n.t('validations.errors.models.user.invalid_mx')}
50
+ ```ruby
51
+ validates :email,
52
+ email: {
53
+ message: I18n.t('validations.errors.models.user.invalid_email')
54
+ },
55
+ mx: {
56
+ message: I18n.t('validations.errors.models.user.invalid_mx')
57
+ }
58
+ ```
42
59
 
43
60
  By default, the email domain is validated using a regular expression, which does not require an external service and improves performance.
44
61
  Alternatively, you can check if an email domain has a MX or A record by using `:mx_with_fallback` instead of `:mx`.
45
62
 
46
- validates :email, :email => {:mx_with_fallback => true}
63
+ ```ruby
64
+ validates :email, email: { mx_with_fallback: true }
65
+ ```
47
66
 
48
67
  You can detect disposable accounts
49
68
 
50
- validates :email, :email => {:ban_disposable_email => true, :message => I18n.t('validations.errors.models.user.invalid_email')}
69
+ ```ruby
70
+ validates :email,
71
+ email: {
72
+ ban_disposable_email: true,
73
+ message: I18n.t('validations.errors.models.user.invalid_email')
74
+ }
75
+ ```
51
76
 
52
77
  If you don't want the MX validator stuff, just require the right file
53
78
 
54
- require 'valid_email/email_validator'
55
-
56
- Or in your Gemfile
79
+ ```ruby
80
+ require 'valid_email/email_validator'
81
+ ```
57
82
 
58
- gem 'valid_email', :require => 'valid_email/email_validator'
83
+ Or in your `Gemfile`
59
84
 
85
+ ```ruby
86
+ gem 'valid_email', require: 'valid_email/email_validator'
87
+ ```
60
88
 
61
89
  ### Usage outside of model validation
62
- There is a chance that you want to use e-mail validator outside of model validation.
90
+
91
+ There is a chance that you want to use e-mail validator outside of model validation.
63
92
  If that's the case, you can use the following methods:
64
93
 
65
94
  ```ruby
66
- ValidateEmail.valid?('email@randommail.com') # You can optionally pass a hash of options, same as validator
95
+ options = {} # You can optionally pass a hash of options, same as validator
96
+ ValidateEmail.valid?('email@randommail.com', options)
67
97
  ValidateEmail.mx_valid?('email@randommail.com')
68
98
  ValidateEmail.mx_valid_with_fallback?('email@randommail.com')
69
99
  ValidateEmail.valid?('email@randommail.com')
70
100
  ```
71
101
 
72
- Load it (and not the rails extensions) with
73
-
74
- gem 'valid_email', require: 'valid_email/validate_email'
102
+ Load it (and not the Rails extensions) with
75
103
 
104
+ ```ruby
105
+ gem 'valid_email', require: 'valid_email/validate_email'
106
+ ```
76
107
 
77
108
  ### String and Nil object extensions
78
109
 
79
- There is also a String and Nil class extension, if you require the gem in this way in Gemfile:
110
+ There is also a String and Nil class extension, if you require the gem in this way in `Gemfile`:
80
111
 
81
112
  ```ruby
82
- gem 'valid_email', require: ['valid_email/all_with_extensions']
113
+ gem 'valid_email', require: 'valid_email/all_with_extensions'
83
114
  ```
84
115
 
85
116
  You will be able to use the following methods:
86
117
  ```ruby
87
118
  nil.email? # => false
88
- "john@gmail.com".email? # => May return true if it exists. It accepts a hash of options like ValidateEmail.valid?
119
+ 'john@gmail.com'.email? # => May return true if it exists.
120
+ # It accepts a hash of options like ValidateEmail.valid?
89
121
  ```
90
122
 
91
123
  ## Code Status
92
124
 
93
- * [![Build Status](https://travis-ci.org/hallelujah/valid_email.svg?branch=master)](https://travis-ci.org/hallelujah/valid_email)
125
+ [![Build Status](https://travis-ci.org/hallelujah/valid_email.svg?branch=master)](https://travis-ci.org/hallelujah/valid_email)
94
126
 
95
- # Credits
127
+ ## Credits
96
128
 
97
129
  * Ramihajamalala Hery hery[at]rails-royce.org
98
130
  * Fire-Dragon-DoL francesco.belladonna[at]gmail.com
@@ -109,18 +141,14 @@ nil.email? # => false
109
141
  * Jean Boussier jean.boussier[at]gmail.com
110
142
  * Masaki Hara - @qnighy
111
143
 
112
- # Note on Patches/Pull Requests
113
-
114
- * Fork the project.
115
-
116
- * Make your feature addition or bug fix.
117
-
118
- * Add tests for it. This is important so I don’t break it in a future version unintentionally.
119
-
120
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
144
+ ## Pull Requests
121
145
 
122
- * Send me a pull request. Bonus points for topic branches.
146
+ 1. Fork the project.
147
+ 2. Make your feature addition or bug fix.
148
+ 3. Add tests for it. This is important so I don’t break it in a future version unintentionally.
149
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
150
+ 5. Send me a pull request. Bonus points for topic branches.
123
151
 
124
- # Copyright
152
+ ## Copyright
125
153
 
126
154
  Copyright &copy; 2011 Ramihajamalala Hery. See LICENSE for details
@@ -0,0 +1,5 @@
1
+ cs:
2
+ valid_email:
3
+ validations:
4
+ email:
5
+ invalid: je neplatný
@@ -0,0 +1,5 @@
1
+ es:
2
+ valid_email:
3
+ validations:
4
+ email:
5
+ invalid: "no es válido"
@@ -347,7 +347,6 @@ disposable_email_services:
347
347
  - prtnx.com
348
348
  - punkass.com
349
349
  - putthisinyourspamdatabase.com
350
- - qq.com
351
350
  - quickinbox.com
352
351
  - rcpt.at
353
352
  - recode.me
@@ -22,7 +22,7 @@ class EmailValidator < ActiveModel::EachValidator
22
22
  end
23
23
  unless r
24
24
  msg = (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email"))
25
- record.errors.add attribute, (msg % {value: value})
25
+ record.errors.add attribute, message: (msg % {value: value})
26
26
  end
27
27
  end
28
28
  end
@@ -1,4 +1,5 @@
1
1
  require 'mail'
2
+ require 'simpleidn'
2
3
 
3
4
  class ValidateEmail
4
5
  class << self
@@ -27,7 +28,7 @@ class ValidateEmail
27
28
  return false unless m.domain.match(/^\S+$/)
28
29
 
29
30
  domain_dot_elements = m.domain.split(/\./)
30
- return false unless domain_dot_elements.size > 1 && !domain_dot_elements.any?(&:empty?)
31
+ return false unless domain_dot_elements.size > 1 && domain_dot_elements.none?(&:empty?)
31
32
 
32
33
  # Ensure that the local segment adheres to adheres to RFC-5322
33
34
  return false unless valid_local?(m.local)
@@ -90,11 +91,17 @@ class ValidateEmail
90
91
  m = Mail::Address.new(value)
91
92
  return false unless m.domain
92
93
 
94
+ if m.domain.ascii_only?
95
+ ascii_domain = m.domain
96
+ else
97
+ ascii_domain = SimpleIDN.to_ascii(m.domain)
98
+ end
99
+
93
100
  Resolv::DNS.open do |dns|
94
101
  dns.timeouts = MxValidator.config[:timeouts] unless MxValidator.config[:timeouts].empty?
95
102
 
96
- return dns.getresources(m.domain, Resolv::DNS::Resource::IN::MX).size > 0 || (
97
- fallback && dns.getresources(m.domain, Resolv::DNS::Resource::IN::A).size > 0
103
+ return dns.getresources(ascii_domain, Resolv::DNS::Resource::IN::MX).size > 0 || (
104
+ fallback && dns.getresources(ascii_domain, Resolv::DNS::Resource::IN::A).size > 0
98
105
  )
99
106
  end
100
107
  rescue Mail::Field::ParseError
@@ -1 +1 @@
1
- ValidEmailVersion = "0.1.3"
1
+ ValidEmailVersion = "0.1.4"
@@ -1,63 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EmailValidator do
4
- person_class = Class.new do
4
+ email_class = Class.new do
5
5
  include ActiveModel::Validations
6
+
6
7
  attr_accessor :email
8
+
9
+ def self.model_name
10
+ ActiveModel::Name.new(self, nil, "TestModel")
11
+ end
12
+ end
13
+
14
+ person_class = Class.new(email_class) do
7
15
  validates :email, :email => true
8
16
  end
9
17
 
10
- person_class_mx = Class.new do
11
- include ActiveModel::Validations
12
- attr_accessor :email
18
+ person_class_mx = Class.new(email_class) do
13
19
  validates :email, :email => {:mx => true}
14
20
  end
15
21
 
16
- person_class_mx_with_fallback = Class.new do
17
- include ActiveModel::Validations
18
- attr_accessor :email
22
+ person_class_mx_with_fallback = Class.new(email_class) do
19
23
  validates :email, :email => {:mx_with_fallback => true}
20
24
  end
21
25
 
22
- person_class_disposable_email = Class.new do
23
- include ActiveModel::Validations
24
- attr_accessor :email
26
+ person_class_disposable_email = Class.new(email_class) do
25
27
  validates :email, :email => {:ban_disposable_email => true}
26
28
  end
27
29
 
28
- person_class_nil_allowed = Class.new do
29
- include ActiveModel::Validations
30
- attr_accessor :email
30
+ person_class_nil_allowed = Class.new(email_class) do
31
31
  validates :email, :email => {:allow_nil => true}
32
32
  end
33
33
 
34
- person_class_blank_allowed = Class.new do
35
- include ActiveModel::Validations
36
- attr_accessor :email
34
+ person_class_blank_allowed = Class.new(email_class) do
37
35
  validates :email, :email => {:allow_blank => true}
38
36
  end
39
37
 
40
- person_class_mx_separated = Class.new do
41
- include ActiveModel::Validations
42
- attr_accessor :email
38
+ person_class_mx_separated = Class.new(email_class) do
43
39
  validates :email, :mx => true
44
40
  end
45
41
 
46
- person_class_mx_with_fallback_separated = Class.new do
47
- include ActiveModel::Validations
48
- attr_accessor :email
42
+ person_class_mx_with_fallback_separated = Class.new(email_class) do
49
43
  validates :email, :mx_with_fallback => true
50
44
  end
51
45
 
52
- person_class_domain = Class.new do
53
- include ActiveModel::Validations
54
- attr_accessor :email
46
+ person_class_domain = Class.new(email_class) do
55
47
  validates :email, :domain => true
56
48
  end
57
49
 
58
- person_message_specified = Class.new do
59
- include ActiveModel::Validations
60
- attr_accessor :email
50
+ person_message_specified = Class.new(email_class) do
61
51
  validates :email, :email => { :message => 'custom message', :ban_disposable_email => true }
62
52
  end
63
53
 
@@ -290,4 +280,19 @@ describe EmailValidator do
290
280
  let!(:errors) { [ "est invalide" ] }
291
281
  it_behaves_like "Validating emails"
292
282
  end
283
+
284
+ describe 'Translating in czech' do
285
+ let!(:locale){ :cs }
286
+ let!(:errors) do
287
+ [
288
+ I18n.t(
289
+ :invalid,
290
+ locale: locale,
291
+ scope: [:valid_email, :validations, :email]
292
+ )
293
+ ]
294
+ end
295
+
296
+ it_behaves_like 'Validating emails'
297
+ end
293
298
  end
data/spec/spec_helper.rb CHANGED
@@ -2,5 +2,8 @@ $:.unshift File.expand_path('../../lib',__FILE__)
2
2
  require 'valid_email'
3
3
 
4
4
  RSpec.configure do |config|
5
+ config.order = :random
6
+ config.profile_examples = 10
5
7
  config.raise_errors_for_deprecations!
8
+ Kernel.srand config.seed
6
9
  end
@@ -15,13 +15,27 @@ describe ValidateEmail do
15
15
  end
16
16
 
17
17
  context 'when mx: true option passed' do
18
+ let(:dns) { Resolv::DNS.new }
19
+
20
+ def mock_dns_mx
21
+ allow(dns).to receive(:getresources).and_return([])
22
+ allow(Resolv::DNS).to receive(:new).and_return(dns)
23
+ end
24
+
18
25
  it 'returns true when mx record exist' do
19
26
  expect(ValidateEmail.valid?('user@gmail.com', mx: true)).to be_truthy
20
27
  end
21
28
 
22
29
  it "returns false when mx record doesn't exist" do
30
+ mock_dns_mx
23
31
  expect(ValidateEmail.valid?('user@example.com', mx: true)).to be_falsey
24
32
  end
33
+
34
+ it "IDN-encodes the domain name if it contains multibyte characters" do
35
+ mock_dns_mx
36
+ ValidateEmail.valid?("user@\u{1F600}.com", mx: true)
37
+ expect(dns).to have_received(:getresources).with('xn--e28h.com', anything)
38
+ end
25
39
  end
26
40
 
27
41
  context 'when domain: true option passed' do
data/valid_email.gemspec CHANGED
@@ -12,17 +12,16 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{ActiveModel Validation for email}
13
13
  s.license = 'MIT'
14
14
 
15
- s.rubyforge_project = "valid_email"
16
-
17
15
  s.files = `git ls-files`.split("\n")
18
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
18
  s.require_paths = ["lib"]
21
19
 
22
20
  # specify any dependencies here; for example:
23
- s.add_development_dependency "rspec", "~> 2.99"
21
+ s.add_development_dependency "rspec", "~> 3.10"
24
22
  s.add_development_dependency "rake", '< 11.0'
25
23
  s.add_runtime_dependency "mail", ">= 2.6.1"
24
+ s.add_runtime_dependency "simpleidn"
26
25
  if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0')
27
26
  s.add_runtime_dependency 'mime-types', '<= 2.6.2'
28
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramihajamalala Hery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.99'
19
+ version: '3.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.99'
26
+ version: '3.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.6.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: simpleidn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: activemodel
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +94,10 @@ files:
80
94
  - LICENSE
81
95
  - README.md
82
96
  - Rakefile
97
+ - config/locales/cs.yml
83
98
  - config/locales/de.yml
84
99
  - config/locales/en.yml
100
+ - config/locales/es.yml
85
101
  - config/locales/fi.yml
86
102
  - config/locales/fr.yml
87
103
  - config/locales/hu.yml
@@ -128,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
144
  - !ruby/object:Gem::Version
129
145
  version: '0'
130
146
  requirements: []
131
- rubyforge_project: valid_email
132
- rubygems_version: 2.7.6
147
+ rubygems_version: 3.1.4
133
148
  signing_key:
134
149
  specification_version: 4
135
150
  summary: ActiveModel Validation for email