valid_email2 5.2.6 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +1 -1
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +15 -6
- data/config/deny_listed_email_domains.yml +1 -0
- data/lib/helpers/deprecation_helper.rb +14 -0
- data/lib/valid_email2/address.rb +9 -4
- data/lib/valid_email2/email_validator.rb +18 -3
- data/lib/valid_email2/version.rb +1 -1
- data/lib/valid_email2.rb +27 -5
- data/release-please-config.json +0 -1
- data/spec/valid_email2_spec.rb +32 -32
- data/valid_email2.gemspec +2 -2
- metadata +6 -5
- data/config/blacklisted_email_domains.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e044955522eceb44fb1def3eb4da317dc58625072d0c41f509ce50cc5634d4b
|
4
|
+
data.tar.gz: bc1af776d07f7a8480441d4bbf3f711d48cc7292947b8e004e1831be71e603bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1974e08b667ae079117faf1415047fccebcb4a870bd1006a240ee15990bcee39ef75999a55ecc33e812c053a0c218afb0a80df7cf8b8379f3e9343583f7de51f
|
7
|
+
data.tar.gz: '085e865491902d39d25a49cf0834743cfc0280dee0a1b6f9358e265e8a473a0381b9da929edf8848b782e4e95715f8d58af66836f65e600bb511d06b651b2675'
|
data/.github/workflows/ci.yaml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{".":"5.
|
1
|
+
{".":"5.3.0"}
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [5.3.0](https://github.com/micke/valid_email2/compare/v5.2.6...v5.3.0) (2024-08-31)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* Deprecate blacklist and whitelist naming ([9df0bf8](https://github.com/micke/valid_email2/commit/9df0bf8c9912721b007e5a6acc67f533ca560c9f))
|
9
|
+
* Warn when loading deprecated files ([46634df](https://github.com/micke/valid_email2/commit/46634dff409f9a47f10684d629dc022b22daf362))
|
10
|
+
|
3
11
|
## [5.2.6](https://github.com/micke/valid_email2/compare/v5.2.5...v5.2.6) (2024-08-10)
|
4
12
|
|
5
13
|
|
data/README.md
CHANGED
@@ -73,20 +73,20 @@ To validate that the domain is not a disposable email (checks domain only, does
|
|
73
73
|
validates :email, 'valid_email_2/email': { disposable_domain: true }
|
74
74
|
```
|
75
75
|
|
76
|
-
To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but
|
76
|
+
To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but allow-listed (under config/allow_listed_email_domains.yml):
|
77
77
|
```ruby
|
78
|
-
validates :email, 'valid_email_2/email': {
|
78
|
+
validates :email, 'valid_email_2/email': { disposable_with_allow_list: true }
|
79
79
|
```
|
80
80
|
|
81
|
-
To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but
|
81
|
+
To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but allow-listed (under config/allow_listed_email_domains.yml):
|
82
82
|
|
83
83
|
```ruby
|
84
|
-
validates :email, 'valid_email_2/email': {
|
84
|
+
validates :email, 'valid_email_2/email': { disposable_domain_with_allow_list: true }
|
85
85
|
```
|
86
86
|
|
87
|
-
To validate that the domain is not
|
87
|
+
To validate that the domain is not on the deny list (under config/deny_list_email_domains.yml):
|
88
88
|
```ruby
|
89
|
-
validates :email, 'valid_email_2/email': {
|
89
|
+
validates :email, 'valid_email_2/email': { deny_list: true }
|
90
90
|
```
|
91
91
|
|
92
92
|
To validate that email is not subaddressed:
|
@@ -147,6 +147,15 @@ end
|
|
147
147
|
|
148
148
|
This gem is tested against currently supported Ruby and Rails versions. For an up to date list, check the build matrix in the [workflow](.github/workflows/ci.yaml).
|
149
149
|
|
150
|
+
## Upgrading to v5.3.0
|
151
|
+
|
152
|
+
In version v5.3.0 the config directory files were renamed as follows:
|
153
|
+
|
154
|
+
`config/blacklisted_email_domains.yml` -> `config/deny_listed_email_domains.yml`
|
155
|
+
`config/whitelisted_email_domains.yml` -> `config/allow_listed_email_domains.yml`
|
156
|
+
|
157
|
+
You won't need to make any changes yourself if you're installing this version for the first time. For individuals updating from earlier versions, make sure to update the file namings as per the above. In future versions this will be a breaking change.
|
158
|
+
|
150
159
|
## Upgrading to v3.0.0
|
151
160
|
|
152
161
|
In version v3.0.0 I decided to move __and__ rename the config files from the
|
@@ -0,0 +1 @@
|
|
1
|
+
- deny-listed-test.com
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DeprecationHelper
|
2
|
+
def deprecate_method(old_method, new_method)
|
3
|
+
define_method(old_method) do |*args, &block|
|
4
|
+
klass = is_a? Module
|
5
|
+
target = klass ? "#{self}." : "#{self.class}#"
|
6
|
+
warn "Warning: `#{target}#{old_method}` is deprecated and will be removed in version 6 of valid_email2; use `#{new_method}` instead."
|
7
|
+
send(new_method, *args, &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def deprecation_message(old_name, new_name)
|
12
|
+
warn "Warning: `#{old_name}` is deprecated and will be removed in version 6 of valid_email2; use `#{new_name}` instead."
|
13
|
+
end
|
14
|
+
end
|
data/lib/valid_email2/address.rb
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
require "valid_email2"
|
4
4
|
require "resolv"
|
5
5
|
require "mail"
|
6
|
+
require_relative "../helpers/deprecation_helper"
|
6
7
|
|
7
8
|
module ValidEmail2
|
8
9
|
class Address
|
10
|
+
extend DeprecationHelper
|
11
|
+
|
9
12
|
attr_accessor :address
|
10
13
|
|
11
14
|
PROHIBITED_DOMAIN_CHARACTERS_REGEX = /[+!_\/\s'`]/
|
@@ -84,13 +87,15 @@ module ValidEmail2
|
|
84
87
|
valid? && mx_server_is_in?(ValidEmail2.disposable_emails)
|
85
88
|
end
|
86
89
|
|
87
|
-
def
|
88
|
-
domain_is_in?(ValidEmail2.
|
90
|
+
def allow_listed?
|
91
|
+
domain_is_in?(ValidEmail2.allow_list)
|
89
92
|
end
|
93
|
+
deprecate_method :whitelisted?, :allow_listed?
|
90
94
|
|
91
|
-
def
|
92
|
-
valid? && domain_is_in?(ValidEmail2.
|
95
|
+
def deny_listed?
|
96
|
+
valid? && domain_is_in?(ValidEmail2.deny_list)
|
93
97
|
end
|
98
|
+
deprecate_method :blacklisted?, :deny_listed?
|
94
99
|
|
95
100
|
def valid_mx?
|
96
101
|
return false unless valid?
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require "valid_email2/address"
|
2
2
|
require "active_model"
|
3
3
|
require "active_model/validations"
|
4
|
+
require_relative "../helpers/deprecation_helper"
|
4
5
|
|
5
6
|
module ValidEmail2
|
6
7
|
class EmailValidator < ActiveModel::EachValidator
|
8
|
+
include DeprecationHelper
|
9
|
+
|
7
10
|
def default_options
|
8
11
|
{ disposable: false, mx: false, strict_mx: false, disallow_subaddressing: false, multiple: false, dns_timeout: 5, dns_nameserver: nil }
|
9
12
|
end
|
@@ -33,15 +36,27 @@ module ValidEmail2
|
|
33
36
|
end
|
34
37
|
|
35
38
|
if options[:disposable_with_whitelist]
|
36
|
-
|
39
|
+
deprecation_message(:disposable_with_whitelist, :disposable_with_allow_list)
|
40
|
+
end
|
41
|
+
|
42
|
+
if options[:disposable_with_allow_list] || options[:disposable_with_whitelist]
|
43
|
+
error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.allow_listed? }
|
37
44
|
end
|
38
45
|
|
39
46
|
if options[:disposable_domain_with_whitelist]
|
40
|
-
|
47
|
+
deprecation_message(:disposable_domain_with_whitelist, :disposable_domain_with_allow_list)
|
48
|
+
end
|
49
|
+
|
50
|
+
if options[:disposable_domain_with_allow_list] || options[:disposable_domain_with_whitelist]
|
51
|
+
error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.allow_listed? }
|
41
52
|
end
|
42
53
|
|
43
54
|
if options[:blacklist]
|
44
|
-
|
55
|
+
deprecation_message(:blacklist, :deny_list)
|
56
|
+
end
|
57
|
+
|
58
|
+
if options[:deny_list] || options[:blacklist]
|
59
|
+
error(record, attribute) && return if addresses.any?(&:deny_listed?)
|
45
60
|
end
|
46
61
|
|
47
62
|
if options[:mx]
|
data/lib/valid_email2/version.rb
CHANGED
data/lib/valid_email2.rb
CHANGED
@@ -1,29 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "valid_email2/email_validator"
|
4
|
+
require_relative "./helpers/deprecation_helper"
|
4
5
|
|
5
6
|
module ValidEmail2
|
7
|
+
|
6
8
|
BLACKLIST_FILE = "config/blacklisted_email_domains.yml"
|
9
|
+
DENY_LIST_FILE = "config/deny_listed_email_domains.yml"
|
7
10
|
WHITELIST_FILE = "config/whitelisted_email_domains.yml"
|
11
|
+
ALLOW_LIST_FILE = "config/allow_listed_email_domains.yml"
|
8
12
|
DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)
|
9
13
|
|
10
14
|
class << self
|
15
|
+
extend DeprecationHelper
|
16
|
+
|
11
17
|
def disposable_emails
|
12
18
|
@disposable_emails ||= load_file(DISPOSABLE_FILE)
|
13
19
|
end
|
14
20
|
|
15
|
-
def
|
16
|
-
@
|
21
|
+
def deny_list
|
22
|
+
@deny_list ||= load_if_exists(DENY_LIST_FILE) ||
|
23
|
+
load_deprecated_if_exists(BLACKLIST_FILE) ||
|
24
|
+
Set.new
|
17
25
|
end
|
26
|
+
deprecate_method :blacklist, :deny_list
|
18
27
|
|
19
|
-
def
|
20
|
-
@
|
28
|
+
def allow_list
|
29
|
+
@allow_list ||= load_if_exists(ALLOW_LIST_FILE) ||
|
30
|
+
load_deprecated_if_exists(WHITELIST_FILE) ||
|
31
|
+
Set.new
|
21
32
|
end
|
33
|
+
deprecate_method :whitelist, :allow_list
|
22
34
|
|
23
35
|
private
|
24
36
|
|
25
37
|
def load_if_exists(path)
|
26
|
-
|
38
|
+
load_file(path) if File.exist?(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_deprecated_if_exists(path)
|
42
|
+
if File.exist?(path)
|
43
|
+
warn <<~WARN
|
44
|
+
Warning: The file `#{path}` used by valid_email2 is deprecated and won't be read in version 6 of valid_email2;
|
45
|
+
Rename the file to `#{path.gsub("blacklisted", "deny_listed").gsub("whitelisted", "allow_listed")}` instead."
|
46
|
+
WARN
|
47
|
+
load_file(path)
|
48
|
+
end
|
27
49
|
end
|
28
50
|
|
29
51
|
def load_file(path)
|
data/release-please-config.json
CHANGED
data/spec/valid_email2_spec.rb
CHANGED
@@ -47,16 +47,16 @@ class TestUserDisallowDisposableDomain < TestModel
|
|
47
47
|
validates :email, 'valid_email_2/email': { disposable_domain: true }
|
48
48
|
end
|
49
49
|
|
50
|
-
class
|
51
|
-
validates :email, 'valid_email_2/email': {
|
50
|
+
class TestUserDisallowDisposableWithAllowList < TestModel
|
51
|
+
validates :email, 'valid_email_2/email': { disposable_with_allow_list: true }
|
52
52
|
end
|
53
53
|
|
54
|
-
class
|
55
|
-
validates :email, 'valid_email_2/email': {
|
54
|
+
class TestUserDisallowDisposableDomainWithAllowList < TestModel
|
55
|
+
validates :email, 'valid_email_2/email': { disposable_domain_with_allow_list: true }
|
56
56
|
end
|
57
57
|
|
58
|
-
class
|
59
|
-
validates :email, 'valid_email_2/email': {
|
58
|
+
class TestUserDisallowDenyListed < TestModel
|
59
|
+
validates :email, 'valid_email_2/email': { deny_list: true }
|
60
60
|
end
|
61
61
|
|
62
62
|
class TestUserMessage < TestModel
|
@@ -208,58 +208,58 @@ describe ValidEmail2 do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
describe "with
|
212
|
-
let(:
|
213
|
-
let(:
|
211
|
+
describe "with allow-listed emails" do
|
212
|
+
let(:allow_list_domain) { disposable_domain }
|
213
|
+
let(:allow_list_file_path) { "config/allow_listed_email_domains.yml" }
|
214
214
|
|
215
|
-
# Some of the specs below need to explictly set the
|
215
|
+
# Some of the specs below need to explictly set the allow list var or it
|
216
216
|
# may be cached to an empty set
|
217
|
-
def
|
217
|
+
def set_allow_list
|
218
218
|
ValidEmail2.instance_variable_set(
|
219
|
-
:@
|
220
|
-
ValidEmail2.send(:load_if_exists, ValidEmail2::
|
219
|
+
:@allow_list,
|
220
|
+
ValidEmail2.send(:load_if_exists, ValidEmail2::ALLOW_LIST_FILE)
|
221
221
|
)
|
222
222
|
end
|
223
223
|
|
224
224
|
after do
|
225
|
-
FileUtils.rm(
|
226
|
-
|
225
|
+
FileUtils.rm(allow_list_file_path, force: true)
|
226
|
+
set_allow_list
|
227
227
|
end
|
228
228
|
|
229
|
-
it "is invalid if the domain is disposable and not in the
|
230
|
-
user =
|
229
|
+
it "is invalid if the domain is disposable and not in the allow list" do
|
230
|
+
user = TestUserDisallowDisposableWithAllowList.new(email: "foo@#{allow_list_domain}")
|
231
231
|
expect(user.valid?).to be_falsey
|
232
232
|
end
|
233
233
|
|
234
|
-
it "is valid if the domain is disposable but in the
|
235
|
-
File.open(
|
236
|
-
|
237
|
-
user =
|
234
|
+
it "is valid if the domain is disposable but in the allow list" do
|
235
|
+
File.open(allow_list_file_path, "w") { |f| f.write [allow_list_domain].to_yaml }
|
236
|
+
set_allow_list
|
237
|
+
user = TestUserDisallowDisposableWithAllowList.new(email: "foo@#{allow_list_domain}")
|
238
238
|
expect(user.valid?).to be_truthy
|
239
239
|
end
|
240
240
|
|
241
|
-
it "is invalid if the domain is a disposable_domain and not in the
|
242
|
-
user =
|
241
|
+
it "is invalid if the domain is a disposable_domain and not in the allow list" do
|
242
|
+
user = TestUserDisallowDisposableDomainWithAllowList.new(email: "foo@#{allow_list_domain}")
|
243
243
|
expect(user.valid?).to be_falsey
|
244
244
|
end
|
245
245
|
|
246
|
-
it "is valid if the domain is a disposable_domain but in the
|
247
|
-
File.open(
|
248
|
-
|
249
|
-
user =
|
246
|
+
it "is valid if the domain is a disposable_domain but in the allow list" do
|
247
|
+
File.open(allow_list_file_path, "w") { |f| f.write [allow_list_domain].to_yaml }
|
248
|
+
set_allow_list
|
249
|
+
user = TestUserDisallowDisposableDomainWithAllowList.new(email: "foo@#{allow_list_domain}")
|
250
250
|
expect(user.valid?).to be_truthy
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
-
describe "with
|
256
|
-
it "is valid if the domain is not
|
257
|
-
user =
|
255
|
+
describe "with deny list validation" do
|
256
|
+
it "is valid if the domain is not deny-listed" do
|
257
|
+
user = TestUserDisallowDenyListed.new(email: "foo@gmail.com")
|
258
258
|
expect(user.valid?).to be_truthy
|
259
259
|
end
|
260
260
|
|
261
|
-
it "is invalid if the domain is
|
262
|
-
user =
|
261
|
+
it "is invalid if the domain is deny-listed" do
|
262
|
+
user = TestUserDisallowDenyListed.new(email: "foo@deny-listed-test.com")
|
263
263
|
expect(user.valid?).to be_falsey
|
264
264
|
end
|
265
265
|
end
|
data/valid_email2.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ValidEmail2::VERSION
|
9
9
|
spec.authors = ["Micke Lisinge"]
|
10
10
|
spec.email = ["hi@micke.me"]
|
11
|
-
spec.description = %q{ActiveModel validation for email. Including MX lookup and disposable email
|
12
|
-
spec.summary = %q{ActiveModel validation for email. Including MX lookup and disposable email
|
11
|
+
spec.description = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
|
12
|
+
spec.summary = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
|
13
13
|
spec.homepage = "https://github.com/micke/valid_email2"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.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: 2024-08-
|
11
|
+
date: 2024-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.2'
|
125
125
|
description: ActiveModel validation for email. Including MX lookup and disposable
|
126
|
-
email
|
126
|
+
email deny list
|
127
127
|
email:
|
128
128
|
- hi@micke.me
|
129
129
|
executables: []
|
@@ -140,10 +140,11 @@ files:
|
|
140
140
|
- LICENSE.txt
|
141
141
|
- README.md
|
142
142
|
- Rakefile
|
143
|
-
- config/
|
143
|
+
- config/deny_listed_email_domains.yml
|
144
144
|
- config/disposable_email_domains.txt
|
145
145
|
- gemfiles/activemodel6.gemfile
|
146
146
|
- gemfiles/activemodel7.gemfile
|
147
|
+
- lib/helpers/deprecation_helper.rb
|
147
148
|
- lib/valid_email2.rb
|
148
149
|
- lib/valid_email2/address.rb
|
149
150
|
- lib/valid_email2/email_validator.rb
|
@@ -178,7 +179,7 @@ rubygems_version: 3.5.3
|
|
178
179
|
signing_key:
|
179
180
|
specification_version: 4
|
180
181
|
summary: ActiveModel validation for email. Including MX lookup and disposable email
|
181
|
-
|
182
|
+
deny list
|
182
183
|
test_files:
|
183
184
|
- spec/address_spec.rb
|
184
185
|
- spec/benchmark_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
- blacklisted-test.com
|