valid_email2 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: c31c962fd50265d3f322c486870d78a569838374
4
- data.tar.gz: b35f54c7e817503ef2142b1fda7a22762a4f7b2d
3
+ metadata.gz: 47c9a632e7366f69dce75eb727db1de39a5e3fc3
4
+ data.tar.gz: 46515df8af73b701e3d7aa07f0e0aa0978bbe25b
5
5
  SHA512:
6
- metadata.gz: b7554c788ed305803a85e6a9a7a2cb05f33ae1e161fb2b1a9e75fe114e452d9b7d2e68e8dc9dc59e190996de941cbb280f393ef2197918e1d6093e9dc0c91fe9
7
- data.tar.gz: 0d8cbff9a1ede7b3d8ae87d71d08c682dd996cf6a57fbd5e198b9de628390eda1a209fd766678a2c95eab214f02e9d035fc35a94996c5372adb8a2b459d595e1
6
+ metadata.gz: 7216249244329396469e769a6c369446f107af2d0ac52e21e6639a0e3411e5778d5f694ec2b990d304f361705f5c6a9f53bd16083021e337af8f1a01dbcd1efb
7
+ data.tar.gz: aacbf6ddd454fe15d081714dee7cbcad1aacc779b514c13fc783265877f7196107110e31a5d0220d36ca435738a038d194659ad923bb6f95cbabfc7ee237b964
data/.travis.yml CHANGED
@@ -1,12 +1,13 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 2.1.0
4
5
  - 2.0.0
5
6
  - 1.9.3
6
7
  - 1.9.2
7
8
  - jruby-19mode
8
9
  - jruby-20mode
9
- - rbx-19mode
10
+ - rbx-2.1.1
10
11
 
11
12
  gemfile:
12
13
  - gemfiles/activemodel3.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Version 1.1.0
2
+ Added support to locally blacklist emails
3
+
1
4
  ## Version 1.0.0
2
5
 
3
6
  Moved EmailValidator to seperate file
data/README.md CHANGED
@@ -4,15 +4,16 @@
4
4
  [![Coverage Status](https://coveralls.io/repos/lisinge/valid_email2/badge.png)](https://coveralls.io/r/lisinge/valid_email2)
5
5
  [![Code Climate](https://codeclimate.com/github/lisinge/valid_email2.png)](https://codeclimate.com/github/lisinge/valid_email2)
6
6
  [![Dependency Status](https://gemnasium.com/lisinge/valid_email2.png)](https://gemnasium.com/lisinge/valid_email2)
7
+ [![Stories in Ready](https://badge.waffle.io/lisinge/valid_email2.png)](http://waffle.io/lisinge/valid_email2)
7
8
 
8
- Validate emails with the help of the `mail` gem instead of some cluncy regexp.
9
- Aditionally validate that the domain has a MX record.
9
+ Validate emails with the help of the `mail` gem instead of some clunky regexp.
10
+ Aditionally validate that the domain has a MX record.
10
11
  Optionally validate against a static [list of disposable email services](vendor/disposable_emails.yml).
11
12
 
12
13
 
13
14
  ### Why?
14
15
 
15
- There are lots of other gems and libraries that validates email adresses but most of them use some cluncy regexp.
16
+ There are lots of other gems and libraries that validates email adresses but most of them use some clunky regexp.
16
17
  I also saw a need to be able to validate that the email address is not coming from a "disposable email" provider.
17
18
 
18
19
  ### Is it production ready?
@@ -46,17 +47,22 @@ class User < ActiveRecord::Base
46
47
  end
47
48
  ```
48
49
 
49
- To validate that the domain has a MX record:
50
+ To validate that the domain has a MX record:
50
51
  ```ruby
51
52
  validates :email, email: { mx: true }
52
53
  ```
53
54
 
54
- To validate that the domain is not a disposable email:
55
+ To validate that the domain is not a disposable email:
55
56
  ```ruby
56
57
  validates :email, email: { disposable: true }
57
58
  ```
58
59
 
59
- All together:
60
+ To validate that the domain is not blacklisted (under vendor/blacklist.yml):
61
+ ```ruby
62
+ validates :email, email: { blacklist: true }
63
+ ```
64
+
65
+ All together:
60
66
  ```ruby
61
67
  validates :email, email: { mx: true, disposable: true }
62
68
  ```
@@ -73,14 +79,26 @@ address.disposable? => false
73
79
  address.valid_mx? => true
74
80
  ```
75
81
 
82
+ ### Test environment
83
+
84
+ If you are validating `mx` then your specs will fail without an internet connection.
85
+ It is a good idea to stub out that validation in your test environment.
86
+ Do so by adding this in your `spec_helper`:
87
+ ```ruby
88
+ config.before(:each) do
89
+ allow_any_instance_of(ValidEmail2::Address).to receive(:valid_mx?) { true }
90
+ end
91
+ ```
92
+
76
93
  ## Requirements
77
94
 
78
95
  This gem requires Rails 3.2 or 4.0. It is tested against both versions under:
79
96
  * Ruby-1.9
80
97
  * Ruby-2.0
98
+ * Ruby-2.1
81
99
  * JRuby-1.9
82
100
  * JRuby-2.0
83
- * Rubinius-1.9
101
+ * Rubinius-2.1
84
102
 
85
103
  ## Contributing
86
104
 
data/lib/valid_email2.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require "valid_email2/email_validator"
2
2
 
3
3
  module ValidEmail2
4
- VERSION = "1.0.0"
5
-
6
4
  def self.disposable_emails
7
5
  @@disposable_emails ||= YAML.load_file(File.expand_path("../../vendor/disposable_emails.yml",__FILE__))
8
6
  end
7
+
8
+ def self.blacklist
9
+ blacklist_file = "vendor/blacklist.yml"
10
+ @@blacklist ||= File.exists?(blacklist_file) ? YAML.load_file(File.expand_path(blacklist_file)) : []
11
+ end
9
12
  end
@@ -34,6 +34,10 @@ module ValidEmail2
34
34
  valid? && ValidEmail2.disposable_emails.include?(address.domain)
35
35
  end
36
36
 
37
+ def blacklisted?
38
+ valid? && ValidEmail2.blacklist.include?(address.domain)
39
+ end
40
+
37
41
  def valid_mx?
38
42
  return false unless valid?
39
43
 
@@ -19,6 +19,10 @@ class EmailValidator < ActiveModel::EachValidator
19
19
  error(record, attribute) && return if address.disposable?
20
20
  end
21
21
 
22
+ if options[:blacklist]
23
+ error(record, attribute) && return if address.blacklisted?
24
+ end
25
+
22
26
  if options[:mx]
23
27
  error(record, attribute) && return unless address.valid_mx?
24
28
  end
@@ -0,0 +1,3 @@
1
+ module ValidEmail2
2
+ VERSION = "1.1.0"
3
+ end
@@ -12,6 +12,10 @@ class TestUserDisallowDisposable < TestModel
12
12
  validates :email, email: { disposable: true }
13
13
  end
14
14
 
15
+ class TestUserDisallowBlacklisted < TestModel
16
+ validates :email, email: { blacklist: true }
17
+ end
18
+
15
19
  describe ValidEmail2 do
16
20
  describe "basic validation" do
17
21
  subject(:user) { TestUser.new(email: "") }
@@ -49,6 +53,18 @@ describe ValidEmail2 do
49
53
  end
50
54
  end
51
55
 
56
+ describe "blacklisted emails" do
57
+ it "should be valid when email is not in the blacklist" do
58
+ user = TestUserDisallowBlacklisted.new(email: "foo@gmail.com")
59
+ user.valid?.should be_true
60
+ end
61
+
62
+ it "should be invalid when email is in the blacklist" do
63
+ user = TestUserDisallowBlacklisted.new(email: "foo@#{ValidEmail2.blacklist.first}")
64
+ user.valid?.should be_false
65
+ end
66
+ end
67
+
52
68
  describe "mx lookup" do
53
69
  it "should be valid if mx records are found" do
54
70
  user = TestUserMX.new(email: "foo@gmail.com")
data/valid_email2.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "valid_email2"
4
+ require "valid_email2/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "valid_email2"
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 2.14.1"
24
24
  spec.add_development_dependency "coveralls"
25
- spec.add_runtime_dependency "mail"
25
+ spec.add_runtime_dependency "mail", '~> 2.5.4'
26
26
  spec.add_runtime_dependency "activemodel"
27
27
  end
@@ -0,0 +1 @@
1
+ - blacklisted-test.com
@@ -11,6 +11,7 @@
11
11
  - 20minutemail.com
12
12
  - 2prong.com
13
13
  - 30minutemail.com
14
+ - 33mail.com
14
15
  - 3d-painting.com
15
16
  - 4warding.com
16
17
  - 4warding.net
@@ -37,6 +38,7 @@
37
38
  - antichef.com
38
39
  - antichef.net
39
40
  - antispam.de
41
+ - armyspy.com
40
42
  - baxomale.ht.cx
41
43
  - beefmilk.com
42
44
  - binkmail.com
@@ -61,9 +63,11 @@
61
63
  - cosmorph.com
62
64
  - courriel.fr.nf
63
65
  - courrieltemporaire.com
66
+ - crapmail.org
64
67
  - cubiclink.com
65
68
  - curryworld.de
66
69
  - cust.in
70
+ - cuvox.de
67
71
  - dacoolest.com
68
72
  - dandikmail.com
69
73
  - dayrep.com
@@ -88,11 +92,13 @@
88
92
  - donemail.ru
89
93
  - dontreg.com
90
94
  - dontsendmespam.de
95
+ - drdrb.com
91
96
  - dump-email.info
92
97
  - dumpandjunk.com
93
98
  - dumpmail.de
94
99
  - dumpyemail.com
95
100
  - e4ward.com
101
+ - einrot.com
96
102
  - email60.com
97
103
  - emaildienst.de
98
104
  - emailias.com
@@ -134,6 +140,7 @@
134
140
  - garliclife.com
135
141
  - get1mail.com
136
142
  - get2mail.fr
143
+ - getairmail.com
137
144
  - getonemail.com
138
145
  - getonemail.net
139
146
  - ghosttexter.de
@@ -150,6 +157,7 @@
150
157
  - gowikitv.com
151
158
  - great-host.in
152
159
  - greensloth.com
160
+ - grr.la
153
161
  - gsrv.co.uk
154
162
  - guerillamail.biz
155
163
  - guerillamail.com
@@ -161,6 +169,7 @@
161
169
  - guerrillamail.net
162
170
  - guerrillamail.org
163
171
  - guerrillamailblock.com
172
+ - gustr.com
164
173
  - h.mintemail.com
165
174
  - h8s.org
166
175
  - haltospam.com
@@ -174,6 +183,7 @@
174
183
  - ihateyoualot.info
175
184
  - iheartspam.org
176
185
  - imails.info
186
+ - inboxalias.com
177
187
  - inboxclean.com
178
188
  - inboxclean.org
179
189
  - incognitomail.com
@@ -188,6 +198,7 @@
188
198
  - jetable.net
189
199
  - jetable.org
190
200
  - jnxjn.com
201
+ - jourrapide.com
191
202
  - junk1e.com
192
203
  - kasmail.com
193
204
  - kaspop.com
@@ -198,6 +209,7 @@
198
209
  - klassmaster.com
199
210
  - klassmaster.net
200
211
  - klzlk.com
212
+ - koszmail.pl
201
213
  - kulturbetrieb.info
202
214
  - kurzepost.de
203
215
  - letthemeatspam.com
@@ -221,9 +233,11 @@
221
233
  - mailbidon.com
222
234
  - mailblocks.com
223
235
  - mailcatch.com
236
+ - maildrop.cc
224
237
  - maileater.com
225
238
  - mailexpire.com
226
239
  - mailfreeonline.com
240
+ - mailforspam.com
227
241
  - mailin8r.com
228
242
  - mailinater.com
229
243
  - mailinator.com
@@ -321,6 +335,7 @@
321
335
  - regbypass.com
322
336
  - regbypass.comsafe-mail.net
323
337
  - rejectmail.com
338
+ - rhyta.com
324
339
  - rklips.com
325
340
  - rmqkr.net
326
341
  - rppkn.com
@@ -351,6 +366,7 @@
351
366
  - soodonims.com
352
367
  - spam.la
353
368
  - spam.su
369
+ - spam4.me
354
370
  - spamavert.com
355
371
  - spambob.com
356
372
  - spambob.net
@@ -399,9 +415,11 @@
399
415
  - speed.1s.fr
400
416
  - supergreatmail.com
401
417
  - supermailer.jp
418
+ - superrito.com
402
419
  - suremail.info
403
420
  - teewars.org
404
421
  - teleworm.com
422
+ - teleworm.us
405
423
  - tempalias.com
406
424
  - tempe-mail.com
407
425
  - tempemail.biz
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
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
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.14.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.14.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mail
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.5.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.5.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activemodel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: ActiveModel validation for email. Including MX lookup and disposable
@@ -102,8 +102,8 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - .gitignore
106
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
107
  - CHANGELOG.md
108
108
  - Gemfile
109
109
  - LICENSE.txt
@@ -114,9 +114,11 @@ files:
114
114
  - lib/valid_email2.rb
115
115
  - lib/valid_email2/address.rb
116
116
  - lib/valid_email2/email_validator.rb
117
+ - lib/valid_email2/version.rb
117
118
  - spec/spec_helper.rb
118
119
  - spec/valid_email2_spec.rb
119
120
  - valid_email2.gemspec
121
+ - vendor/blacklist.yml
120
122
  - vendor/disposable_emails.yml
121
123
  homepage: https://github.com/lisinge/valid_email2
122
124
  licenses:
@@ -128,17 +130,17 @@ require_paths:
128
130
  - lib
129
131
  required_ruby_version: !ruby/object:Gem::Requirement
130
132
  requirements:
131
- - - '>='
133
+ - - ">="
132
134
  - !ruby/object:Gem::Version
133
135
  version: '0'
134
136
  required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  requirements:
136
- - - '>='
138
+ - - ">="
137
139
  - !ruby/object:Gem::Version
138
140
  version: '0'
139
141
  requirements: []
140
142
  rubyforge_project:
141
- rubygems_version: 2.0.2
143
+ rubygems_version: 2.2.1
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: ActiveModel validation for email. Including MX lookup and disposable email