truemail 1.0.0 → 1.0.1

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: a21b06ee93aa17673879a07cd4757ea0508d4acf4340c45406ef389c38d3897f
4
- data.tar.gz: 5c4322968164282e3128fd1350bc614eb9ddc596a541a5dcab94e9dab81fb358
3
+ metadata.gz: d6ae9e8559f02e6dc3c192d25b68299d710b0f725d6415dcce94291b67cfedec
4
+ data.tar.gz: ca8150d40f29c19424c75203ebc8725a158f9ab211e31fed6139258f850f061e
5
5
  SHA512:
6
- metadata.gz: 7782e71da1ff862e233a6acf68ba63f38858f167c291118083a291c2305202f6038ba375ea9d6597600755ffd0cc9264a41e6f3a51fe5c65c2978bc7b1bbf5ea
7
- data.tar.gz: ce1f9ae97ebd2cc7d929f4ee99c1af0e95d97116053be9d1dd19849eade75a89094f085c4475b52095459533e2aa9a19a1f19b0f1a3b51e7851e107a74b6364d
6
+ metadata.gz: 756ac97059a71e39fff2161c9d484ac5c916061403d7165fb1afd45c1d363928c10330fc0175ed33fe0915eedc503b237e8c796fe1cdfd4c80a7dc7c2fc4d6f5
7
+ data.tar.gz: 565ab89967301f5f8b9cd5cd6c230ee6c1a6e908776532f1346131850afccfe72063bb2acc05b573b806c8cd8be13b0f085eaadf136de9165ace3a6ee232651e
data/.reek.yml CHANGED
@@ -38,6 +38,7 @@ detectors:
38
38
  - Truemail::GenerateEmailHelper#calculate_email_size
39
39
  - Truemail::Worker#success
40
40
  - Truemail#raise_unless
41
+ - Truemail::Configuration#raise_unless
41
42
 
42
43
  FeatureEnvy:
43
44
  exclude:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- truemail (1.0.0)
4
+ truemail (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -77,7 +77,8 @@ Truemail.configure do |config|
77
77
  # Optional parameter. You can predefine which type of validation will be used for domains.
78
78
  # Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp
79
79
  # This configuration will be used over current or default validation type parameter
80
- # All of validations for 'somedomain.com' will be processed with mx validation only
80
+ # All of validations for 'somedomain.com' will be processed with regex validation only.
81
+ # And all of validations for 'otherdomain.com' will be processed with mx validation only.
81
82
  config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx }
82
83
 
83
84
  # Optional parameter. Validation of email which contains whitelisted domain always will
@@ -154,9 +155,92 @@ Truemail.configuration
154
155
 
155
156
  ### Validation features
156
157
 
158
+ #### Whitelist/Blacklist check
159
+
160
+ Whitelist/Blacklist check is zero validation level. You can define white and black list domains. It means that validation of email which contains whitelisted domain always will return ```true```, and for blacklisted domain will return ```false```.
161
+
162
+ Please note, other validations will not processed even if it was defined in ```validation_type_for```.
163
+
164
+ **Sequence of domain list check:**
165
+ 1. Whitelist check
166
+ 2. Blacklist check
167
+
168
+ Example of usage:
169
+
170
+ ```ruby
171
+ require 'truemail'
172
+
173
+ Truemail.configure do |config|
174
+ config.verifier_email = 'verifier@example.com'
175
+ config.whitelisted_domains = ['white-domain.com', 'somedomain.com']
176
+ config.blacklisted_domains = ['black-domain.com', 'somedomain.com']
177
+ config.validation_type_for = { 'somedomain.com' => :mx }
178
+ end
179
+ ```
180
+
181
+ ##### Whitelist case
182
+
183
+ When email in whitelist, validation type will be redefined. Validation result returns ```true```
184
+
185
+ ```ruby
186
+ Truemail.validate('email@white-domain.com')
187
+
188
+ #<Truemail::Validator:0x000055b8429f3490
189
+ @result=#<struct Truemail::Validator::Result
190
+ success=true,
191
+ email="email@white-domain.com",
192
+ domain=nil,
193
+ mail_servers=[],
194
+ errors={},
195
+ smtp_debug=nil>,
196
+ @validation_type=:whitelist>
197
+ ```
198
+
199
+ ##### Blacklist case
200
+
201
+ When email in blacklist, validation type will be redefined too. Validation result returns ```false```
202
+
203
+ ```ruby
204
+ Truemail.validate('email@black-domain.com')
205
+
206
+ #<Truemail::Validator:0x000023y8429f3493
207
+ @result=#<struct Truemail::Validator::Result
208
+ success=false,
209
+ email="email@black-domain.com",
210
+ domain=nil,
211
+ mail_servers=[],
212
+ errors={},
213
+ smtp_debug=nil>,
214
+ @validation_type=:blacklist>
215
+ ```
216
+
217
+ ##### Duplication case
218
+
219
+ Validation result for this email returns ```true```, because it was found in whitelisted domains list first. Also ```validation_type``` for this case will be redefined.
220
+
221
+ ```ruby
222
+ Truemail.validate('email@somedomain.com')
223
+
224
+ #<Truemail::Validator:0x000055b8429f3490
225
+ @result=#<struct Truemail::Validator::Result
226
+ success=true,
227
+ email="email@somedomain.com",
228
+ domain=nil,
229
+ mail_servers=[],
230
+ errors={},
231
+ smtp_debug=nil>,
232
+ @validation_type=:whitelist>
233
+ ```
234
+
157
235
  #### Regex validation
158
236
 
159
- Validation with regex pattern is the first validation level. By default this validation not performs strictly following RFC 5322 standard, so you can override Truemail default regex pattern if you want.
237
+ Validation with regex pattern is the first validation level. It uses whitelist/blacklist check before running itself.
238
+
239
+ ```code
240
+ [Whitelist/Blacklist] -> [Regex validation]
241
+ ```
242
+
243
+ By default this validation not performs strictly following [RFC 5322](https://www.ietf.org/rfc/rfc5322.txt) standard, so you can override Truemail default regex pattern if you want.
160
244
 
161
245
  Example of usage:
162
246
 
@@ -211,7 +295,7 @@ Truemail.validate('email@example.com', with: :regex)
211
295
  Validation by MX records is the second validation level. It uses Regex validation before running itself. When regex validation has completed successfully then runs itself.
212
296
 
213
297
  ```code
214
- [Regex validation] -> [MX validation]
298
+ [Whitelist/Blacklist] -> [Regex validation] -> [MX validation]
215
299
  ```
216
300
 
217
301
  Please note, Truemail MX validator not performs strict compliance of the [RFC 5321](https://tools.ietf.org/html/rfc5321#section-5) standard for best validation outcome.
@@ -244,7 +328,7 @@ Truemail.validate('email@example.com', with: :mx)
244
328
  SMTP validation is a final, third validation level. This type of validation tries to check real existence of email account on a current email server. This validation runs a chain of previous validations and if they're complete successfully then runs itself.
245
329
 
246
330
  ```code
247
- [Regex validation] -> [MX validation] -> [SMTP validation]
331
+ [Whitelist/Blacklist] -> [Regex validation] -> [MX validation] -> [SMTP validation]
248
332
  ```
249
333
 
250
334
  If total count of MX servers is equal to one, ```Truemail::Smtp``` validator will use value from ```Truemail.configuration.connection_attempts``` as connection attempts. By default it's equal 2.
@@ -35,7 +35,7 @@ module Truemail
35
35
 
36
36
  %i[email_pattern smtp_error_body_pattern].each do |method|
37
37
  define_method("#{method}=") do |argument|
38
- raise Truemail::ArgumentError.new(argument, __method__) unless argument.is_a?(Regexp)
38
+ raise_unless(argument, __method__, argument.is_a?(Regexp))
39
39
  instance_variable_set(:"@#{method}", argument)
40
40
  end
41
41
  end
@@ -53,7 +53,7 @@ module Truemail
53
53
 
54
54
  %i[connection_timeout response_timeout connection_attempts].each do |method|
55
55
  define_method("#{method}=") do |argument|
56
- raise ArgumentError.new(argument, __method__) unless argument.is_a?(Integer) && argument.positive?
56
+ raise_unless(argument, __method__, argument.is_a?(Integer) && argument.positive?)
57
57
  instance_variable_set(:"@#{method}", argument)
58
58
  end
59
59
  end
@@ -65,7 +65,7 @@ module Truemail
65
65
 
66
66
  %i[whitelisted_domains blacklisted_domains].each do |method|
67
67
  define_method("#{method}=") do |argument|
68
- raise ArgumentError.new(argument, __method__) unless argument.is_a?(Array) && check_domain_list(argument)
68
+ raise_unless(argument, __method__, argument.is_a?(Array) && check_domain_list(argument))
69
69
  instance_variable_set(:"@#{method}", argument)
70
70
  end
71
71
  end
@@ -76,9 +76,13 @@ module Truemail
76
76
 
77
77
  private
78
78
 
79
+ def raise_unless(argument_context, argument_name, condition)
80
+ raise Truemail::ArgumentError.new(argument_context, argument_name) unless condition
81
+ end
82
+
79
83
  def validate_arguments(argument, method)
80
84
  constant = Truemail::RegexConstant.const_get("regex_#{method[/\A.+_(.+)\=\z/, 1]}_pattern".upcase)
81
- raise Truemail::ArgumentError.new(argument, method) unless constant.match?(argument.to_s)
85
+ raise_unless(argument, method, constant.match?(argument.to_s))
82
86
  end
83
87
 
84
88
  def default_verifier_domain
@@ -90,7 +94,7 @@ module Truemail
90
94
  end
91
95
 
92
96
  def check_domain(domain)
93
- raise Truemail::ArgumentError.new(domain, 'domain') unless domain_matcher.call(domain)
97
+ raise_unless(domain, 'domain', domain_matcher.call(domain))
94
98
  end
95
99
 
96
100
  def check_domain_list(domains)
@@ -98,12 +102,11 @@ module Truemail
98
102
  end
99
103
 
100
104
  def check_validation_type(validation_type)
101
- raise Truemail::ArgumentError.new(validation_type, 'validation type') unless
102
- Truemail::Validator::VALIDATION_TYPES.include?(validation_type)
105
+ raise_unless(validation_type, 'validation type', Truemail::Validator::VALIDATION_TYPES.include?(validation_type))
103
106
  end
104
107
 
105
108
  def validate_validation_type(settings)
106
- raise Truemail::ArgumentError.new(settings, 'hash with settings') unless settings.is_a?(Hash)
109
+ raise_unless(settings, 'hash with settings', settings.is_a?(Hash))
107
110
  settings.each do |domain, validation_type|
108
111
  check_domain(domain)
109
112
  check_validation_type(validation_type)
@@ -22,7 +22,7 @@ module Truemail
22
22
 
23
23
  def run
24
24
  Truemail::Validate::DomainListMatch.check(result)
25
- Truemail::Validate.const_get(validation_type.capitalize).check(result) if result_not_changed?
25
+ result_not_changed? ? Truemail::Validate.const_get(validation_type.capitalize).check(result) : update_validation_type
26
26
  self
27
27
  end
28
28
 
@@ -32,6 +32,10 @@ module Truemail
32
32
  result.success.nil?
33
33
  end
34
34
 
35
+ def update_validation_type
36
+ @validation_type = result.success ? :whitelist : :blacklist
37
+ end
38
+
35
39
  def select_validation_type(email, current_validation_type)
36
40
  domain = email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
37
41
  Truemail.configuration.validation_type_by_domain[domain] || current_validation_type
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
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: 1.0.0
4
+ version: 1.0.1
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-06-04 00:00:00.000000000 Z
11
+ date: 2019-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler