truemail 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.reek.yml +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +22 -4
- data/lib/truemail/configuration.rb +23 -4
- data/lib/truemail/core.rb +1 -1
- data/lib/truemail/validate/base.rb +1 -1
- data/lib/truemail/validate/domain_list_match.rb +30 -0
- data/lib/truemail/validator.rb +7 -2
- data/lib/truemail/version.rb +1 -1
- metadata +3 -3
- data/lib/truemail/validate/skip.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21b06ee93aa17673879a07cd4757ea0508d4acf4340c45406ef389c38d3897f
|
4
|
+
data.tar.gz: 5c4322968164282e3128fd1350bc614eb9ddc596a541a5dcab94e9dab81fb358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7782e71da1ff862e233a6acf68ba63f38858f167c291118083a291c2305202f6038ba375ea9d6597600755ffd0cc9264a41e6f3a51fe5c65c2978bc7b1bbf5ea
|
7
|
+
data.tar.gz: ce1f9ae97ebd2cc7d929f4ee99c1af0e95d97116053be9d1dd19849eade75a89094f085c4475b52095459533e2aa9a19a1f19b0f1a3b51e7851e107a74b6364d
|
data/.reek.yml
CHANGED
@@ -31,6 +31,7 @@ detectors:
|
|
31
31
|
- Truemail::Validate::Mx#null_mx?
|
32
32
|
- Truemail::Validate::Mx#a_record
|
33
33
|
- Truemail::Audit::Base#verifier_domain
|
34
|
+
- Truemail::Configuration#domain_matcher
|
34
35
|
|
35
36
|
ControlParameter:
|
36
37
|
exclude:
|
@@ -42,3 +43,7 @@ detectors:
|
|
42
43
|
exclude:
|
43
44
|
- Truemail::Validate::Smtp#not_includes_user_not_found_errors
|
44
45
|
- Truemail::GenerateEmailHelper#prepare_user_name
|
46
|
+
|
47
|
+
NilCheck:
|
48
|
+
exclude:
|
49
|
+
- Truemail::Validator#result_not_changed?
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,7 @@ The Truemail gem helps you validate emails by regex pattern, presence of domain
|
|
8
8
|
|
9
9
|
- Configurable validator, validate only what you need
|
10
10
|
- Zero runtime dependencies
|
11
|
+
- Has whitelist/blacklist
|
11
12
|
- Has simple SMTP debugger
|
12
13
|
- 100% test coverage
|
13
14
|
|
@@ -74,10 +75,18 @@ Truemail.configure do |config|
|
|
74
75
|
config.connection_attempts = 3
|
75
76
|
|
76
77
|
# Optional parameter. You can predefine which type of validation will be used for domains.
|
77
|
-
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp
|
78
|
+
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp
|
78
79
|
# This configuration will be used over current or default validation type parameter
|
79
80
|
# All of validations for 'somedomain.com' will be processed with mx validation only
|
80
|
-
config.validation_type_for = { 'somedomain.com' => :
|
81
|
+
config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx }
|
82
|
+
|
83
|
+
# Optional parameter. Validation of email which contains whitelisted domain always will
|
84
|
+
# return true. Other validations will not processed even if it was defined in validation_type_for
|
85
|
+
config.whitelisted_domains = ['somedomain1.com', 'somedomain2.com']
|
86
|
+
|
87
|
+
# Optional parameter. Validation of email which contains whitelisted domain always will
|
88
|
+
# return false. Other validations will not processed even if it was defined in validation_type_for
|
89
|
+
config.blacklisted_domains = ['somedomain1.com', 'somedomain2.com']
|
81
90
|
|
82
91
|
# Optional parameter. This option will be parse bodies of SMTP errors. It will be helpful
|
83
92
|
# if SMTP server does not return an exact answer that the email does not exist
|
@@ -100,6 +109,8 @@ Truemail.configuration
|
|
100
109
|
@response_timeout=1,
|
101
110
|
@connection_attempts=3,
|
102
111
|
@validation_type_by_domain={},
|
112
|
+
@whitelisted_domains=[],
|
113
|
+
@blacklisted_domains=[],
|
103
114
|
@verifier_domain="somedomain.com",
|
104
115
|
@verifier_email="verifier@example.com"
|
105
116
|
@smtp_safe_check=true>
|
@@ -123,6 +134,8 @@ Truemail.configuration
|
|
123
134
|
@response_timeout=4,
|
124
135
|
@connection_attempts=1,
|
125
136
|
@validation_type_by_domain={},
|
137
|
+
@whitelisted_domains=[],
|
138
|
+
@blacklisted_domains=[],
|
126
139
|
@verifier_domain="somedomain.com",
|
127
140
|
@verifier_email="verifier@example.com",
|
128
141
|
@smtp_safe_check=true>
|
@@ -281,6 +294,8 @@ Truemail.validate('email@example.com')
|
|
281
294
|
@connection_attempts=2,
|
282
295
|
@smtp_safe_check=false,
|
283
296
|
@validation_type_by_domain={},
|
297
|
+
@whitelisted_domains=[],
|
298
|
+
@blacklisted_domains=[],
|
284
299
|
@verifier_domain="example.com",
|
285
300
|
@verifier_email="verifier@example.com">,
|
286
301
|
@email="email@example.com",
|
@@ -335,6 +350,8 @@ Truemail.validate('email@example.com')
|
|
335
350
|
@connection_attempts=2,
|
336
351
|
@smtp_safe_check=true,
|
337
352
|
@validation_type_by_domain={},
|
353
|
+
@whitelisted_domains=[],
|
354
|
+
@blacklisted_domains=[],
|
338
355
|
@verifier_domain="example.com",
|
339
356
|
@verifier_email="verifier@example.com">,
|
340
357
|
@email="email@example.com",
|
@@ -373,6 +390,8 @@ Truemail.validate('email@example.com')
|
|
373
390
|
@connection_attempts=2,
|
374
391
|
@smtp_safe_check=true,
|
375
392
|
@validation_type_by_domain={},
|
393
|
+
@whitelisted_domains=[],
|
394
|
+
@blacklisted_domains=[],
|
376
395
|
@verifier_domain="example.com",
|
377
396
|
@verifier_email="verifier@example.com">,
|
378
397
|
@email="email@example.com",
|
@@ -447,8 +466,7 @@ end
|
|
447
466
|
---
|
448
467
|
## ToDo
|
449
468
|
|
450
|
-
|
451
|
-
2. Fail validations logger
|
469
|
+
Fail validations logger
|
452
470
|
|
453
471
|
## Contributing
|
454
472
|
|
@@ -13,7 +13,9 @@ module Truemail
|
|
13
13
|
:connection_timeout,
|
14
14
|
:response_timeout,
|
15
15
|
:connection_attempts,
|
16
|
-
:validation_type_by_domain
|
16
|
+
:validation_type_by_domain,
|
17
|
+
:whitelisted_domains,
|
18
|
+
:blacklisted_domains
|
17
19
|
|
18
20
|
attr_accessor :smtp_safe_check
|
19
21
|
|
@@ -26,6 +28,8 @@ module Truemail
|
|
26
28
|
@response_timeout = Truemail::Configuration::DEFAULT_RESPONSE_TIMEOUT
|
27
29
|
@connection_attempts = Truemail::Configuration::DEFAULT_CONNECTION_ATTEMPTS
|
28
30
|
@validation_type_by_domain = {}
|
31
|
+
@whitelisted_domains = []
|
32
|
+
@blacklisted_domains = []
|
29
33
|
@smtp_safe_check = false
|
30
34
|
end
|
31
35
|
|
@@ -59,6 +63,13 @@ module Truemail
|
|
59
63
|
validation_type_by_domain.merge!(settings)
|
60
64
|
end
|
61
65
|
|
66
|
+
%i[whitelisted_domains blacklisted_domains].each do |method|
|
67
|
+
define_method("#{method}=") do |argument|
|
68
|
+
raise ArgumentError.new(argument, __method__) unless argument.is_a?(Array) && check_domain_list(argument)
|
69
|
+
instance_variable_set(:"@#{method}", argument)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
62
73
|
def complete?
|
63
74
|
!!verifier_email
|
64
75
|
end
|
@@ -74,17 +85,25 @@ module Truemail
|
|
74
85
|
self.verifier_domain ||= verifier_email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
|
75
86
|
end
|
76
87
|
|
88
|
+
def domain_matcher
|
89
|
+
->(domain) { Truemail::RegexConstant::REGEX_DOMAIN_PATTERN.match?(domain.to_s) }
|
90
|
+
end
|
91
|
+
|
77
92
|
def check_domain(domain)
|
78
|
-
raise Truemail::ArgumentError.new(domain, 'domain') unless
|
79
|
-
|
93
|
+
raise Truemail::ArgumentError.new(domain, 'domain') unless domain_matcher.call(domain)
|
94
|
+
end
|
95
|
+
|
96
|
+
def check_domain_list(domains)
|
97
|
+
domains.all?(&domain_matcher)
|
80
98
|
end
|
81
99
|
|
82
100
|
def check_validation_type(validation_type)
|
83
101
|
raise Truemail::ArgumentError.new(validation_type, 'validation type') unless
|
84
|
-
|
102
|
+
Truemail::Validator::VALIDATION_TYPES.include?(validation_type)
|
85
103
|
end
|
86
104
|
|
87
105
|
def validate_validation_type(settings)
|
106
|
+
raise Truemail::ArgumentError.new(settings, 'hash with settings') unless settings.is_a?(Hash)
|
88
107
|
settings.each do |domain, validation_type|
|
89
108
|
check_domain(domain)
|
90
109
|
check_validation_type(validation_type)
|
data/lib/truemail/core.rb
CHANGED
@@ -30,8 +30,8 @@ module Truemail
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module Validate
|
33
|
-
require 'truemail/validate/skip'
|
34
33
|
require 'truemail/validate/base'
|
34
|
+
require 'truemail/validate/domain_list_match'
|
35
35
|
require 'truemail/validate/regex'
|
36
36
|
require 'truemail/validate/mx'
|
37
37
|
require 'truemail/validate/smtp'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Truemail
|
4
|
+
module Validate
|
5
|
+
class DomainListMatch < Truemail::Validate::Base
|
6
|
+
ERROR = 'blacklisted email'
|
7
|
+
|
8
|
+
def run
|
9
|
+
return success(true) if whitelisted_domain?
|
10
|
+
return unless blacklisted_domain?
|
11
|
+
success(false)
|
12
|
+
add_error(Truemail::Validate::DomainListMatch::ERROR)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def email_domain
|
18
|
+
@email_domain ||= result.email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def whitelisted_domain?
|
22
|
+
configuration.whitelisted_domains.include?(email_domain)
|
23
|
+
end
|
24
|
+
|
25
|
+
def blacklisted_domain?
|
26
|
+
configuration.blacklisted_domains.include?(email_domain)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/truemail/validator.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Truemail
|
4
4
|
class Validator
|
5
5
|
RESULT_ATTRS = %i[success email domain mail_servers errors smtp_debug].freeze
|
6
|
-
VALIDATION_TYPES = %i[regex mx smtp
|
6
|
+
VALIDATION_TYPES = %i[regex mx smtp].freeze
|
7
7
|
|
8
8
|
Result = Struct.new(*RESULT_ATTRS, keyword_init: true) do
|
9
9
|
def initialize(errors: {}, mail_servers: [], **args)
|
@@ -21,12 +21,17 @@ module Truemail
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def run
|
24
|
-
Truemail::Validate.
|
24
|
+
Truemail::Validate::DomainListMatch.check(result)
|
25
|
+
Truemail::Validate.const_get(validation_type.capitalize).check(result) if result_not_changed?
|
25
26
|
self
|
26
27
|
end
|
27
28
|
|
28
29
|
private
|
29
30
|
|
31
|
+
def result_not_changed?
|
32
|
+
result.success.nil?
|
33
|
+
end
|
34
|
+
|
30
35
|
def select_validation_type(email, current_validation_type)
|
31
36
|
domain = email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
|
32
37
|
Truemail.configuration.validation_type_by_domain[domain] || current_validation_type
|
data/lib/truemail/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truemail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Trotsenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -199,9 +199,9 @@ files:
|
|
199
199
|
- lib/truemail/configuration.rb
|
200
200
|
- lib/truemail/core.rb
|
201
201
|
- lib/truemail/validate/base.rb
|
202
|
+
- lib/truemail/validate/domain_list_match.rb
|
202
203
|
- lib/truemail/validate/mx.rb
|
203
204
|
- lib/truemail/validate/regex.rb
|
204
|
-
- lib/truemail/validate/skip.rb
|
205
205
|
- lib/truemail/validate/smtp.rb
|
206
206
|
- lib/truemail/validate/smtp/request.rb
|
207
207
|
- lib/truemail/validate/smtp/response.rb
|