truemail 2.3.2 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/truemail/core.rb CHANGED
@@ -24,8 +24,10 @@ module Truemail
24
24
  REGEX_DOMAIN_PATTERN = /(?=\A.{4,255}\z)(\A#{REGEX_DOMAIN}\z)/.freeze
25
25
  REGEX_DOMAIN_FROM_EMAIL = /\A.+@(.+)\z/.freeze
26
26
  REGEX_SMTP_ERROR_BODY_PATTERN = /(?=.*550)(?=.*(user|account|customer|mailbox)).*/i.freeze
27
- REGEX_PORT_NUMBER = /(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})/.freeze
28
- REGEX_DNS_SERVER_ADDRESS_PATTERN = /\A((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}(:#{REGEX_PORT_NUMBER})?\z/.freeze
27
+ REGEX_IP_ADDRESS = /((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}/.freeze
28
+ REGEX_IP_ADDRESS_PATTERN = /\A#{REGEX_IP_ADDRESS}\z/.freeze
29
+ REGEX_PORT_NUMBER = /6553[0-5]|655[0-2]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}/.freeze
30
+ REGEX_DNS_SERVER_ADDRESS_PATTERN = /\A#{REGEX_IP_ADDRESS}(:#{REGEX_PORT_NUMBER})?\z/.freeze
29
31
  end
30
32
 
31
33
  module Dns
@@ -46,6 +48,7 @@ module Truemail
46
48
  require_relative '../truemail/validate/domain_list_match'
47
49
  require_relative '../truemail/validate/regex'
48
50
  require_relative '../truemail/validate/mx'
51
+ require_relative '../truemail/validate/mx_blacklist'
49
52
  require_relative '../truemail/validate/smtp'
50
53
  require_relative '../truemail/validate/smtp/response'
51
54
  require_relative '../truemail/validate/smtp/request'
@@ -6,6 +6,14 @@ module Truemail
6
6
  class Base
7
7
  require 'json'
8
8
 
9
+ CONFIGURATION_ARRAY_ATTRS = %i[
10
+ validation_type_by_domain
11
+ whitelisted_domains
12
+ blacklisted_domains
13
+ blacklisted_mx_ip_addresses
14
+ dns
15
+ ].freeze
16
+ CONFIGURATION_REGEX_ATTRS = %i[email_pattern smtp_error_body_pattern].freeze
9
17
  DEFAULT_GEM_VALUE = 'default gem value'
10
18
 
11
19
  def self.call(executor_instance)
@@ -30,22 +38,22 @@ module Truemail
30
38
 
31
39
  alias warnings errors
32
40
 
33
- %i[validation_type_by_domain whitelisted_domains blacklisted_domains dns].each do |method|
41
+ Truemail::Log::Serializer::Base::CONFIGURATION_ARRAY_ATTRS.each do |method|
34
42
  define_method(method) do
35
- value = executor_configuration.public_send(method)
36
- return if value.empty?
37
- value
43
+ executor_configuration_attr = executor_configuration.public_send(method)
44
+ return if executor_configuration_attr.empty?
45
+ executor_configuration_attr
38
46
  end
39
47
  end
40
48
 
41
- %i[email_pattern smtp_error_body_pattern].each do |method|
49
+ Truemail::Log::Serializer::Base::CONFIGURATION_REGEX_ATTRS.each do |method|
42
50
  define_method(method) do
43
- value = executor_configuration.public_send(method)
51
+ executor_configuration_attr = executor_configuration.public_send(method)
44
52
  default_pattern = Truemail::RegexConstant.const_get(
45
53
  (method.eql?(:email_pattern) ? :regex_email_pattern : :regex_smtp_error_body_pattern).upcase
46
54
  )
47
- return Truemail::Log::Serializer::Base::DEFAULT_GEM_VALUE if value.eql?(default_pattern)
48
- value
55
+ return Truemail::Log::Serializer::Base::DEFAULT_GEM_VALUE if executor_configuration_attr.eql?(default_pattern)
56
+ executor_configuration_attr
49
57
  end
50
58
  end
51
59
 
@@ -55,6 +63,7 @@ module Truemail
55
63
  whitelist_validation: executor_configuration.whitelist_validation,
56
64
  whitelisted_domains: whitelisted_domains,
57
65
  blacklisted_domains: blacklisted_domains,
66
+ blacklisted_mx_ip_addresses: blacklisted_mx_ip_addresses,
58
67
  dns: dns,
59
68
  not_rfc_mx_lookup_flow: executor_configuration.not_rfc_mx_lookup_flow,
60
69
  smtp_fail_fast: executor_configuration.smtp_fail_fast,
@@ -19,9 +19,9 @@ module Truemail
19
19
  def data_composer(enumerable_object)
20
20
  enumerable_object.inject([]) do |formatted_data, (key, value)|
21
21
  data =
22
- case
23
- when value.is_a?(::Hash) then "\n#{printer(value)}"
24
- when value.is_a?(::Array) then value.join(', ')
22
+ case value
23
+ when ::Hash then "\n#{printer(value)}"
24
+ when ::Array then value.join(', ')
25
25
  else value
26
26
  end
27
27
  formatted_data << "#{key.to_s.tr('_', ' ')}: #{data}".chomp << "\n"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Truemail
4
+ module Validate
5
+ class MxBlacklist < Truemail::Validate::Base
6
+ ERROR = 'blacklisted mx server ip address'
7
+
8
+ def run
9
+ return false unless Truemail::Validate::Mx.check(result)
10
+ return true if success(not_blacklisted_mail_servers?)
11
+ add_error(Truemail::Validate::MxBlacklist::ERROR)
12
+ false
13
+ end
14
+
15
+ private
16
+
17
+ def blacklisted_ip?
18
+ ->(mail_server) { configuration.blacklisted_mx_ip_addresses.include?(mail_server) }
19
+ end
20
+
21
+ def not_blacklisted_mail_servers?
22
+ mail_servers.none?(&blacklisted_ip?)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -13,7 +13,7 @@ module Truemail
13
13
  end
14
14
 
15
15
  def run
16
- return false unless Truemail::Validate::Mx.check(result)
16
+ return false unless Truemail::Validate::MxBlacklist.check(result)
17
17
  establish_smtp_connection
18
18
  return true if success(success_response?)
19
19
  result.smtp_debug = smtp_results
@@ -3,7 +3,7 @@
3
3
  module Truemail
4
4
  class Validator < Truemail::Executor
5
5
  RESULT_ATTRS = %i[success email domain mail_servers errors smtp_debug configuration].freeze
6
- VALIDATION_TYPES = %i[regex mx smtp].freeze
6
+ VALIDATION_TYPES = %i[regex mx mx_blacklist smtp].freeze
7
7
 
8
8
  Result = ::Struct.new(*RESULT_ATTRS, keyword_init: true) do
9
9
  def initialize(mail_servers: [], errors: {}, **args)
@@ -27,7 +27,7 @@ module Truemail
27
27
 
28
28
  def run
29
29
  Truemail::Validate::DomainListMatch.check(result)
30
- result_not_changed? ? Truemail::Validate.const_get(validation_type.capitalize).check(result) : update_validation_type
30
+ result_not_changed? ? Truemail::Validate.const_get(constantize(validation_type)).check(result) : update_validation_type
31
31
  logger&.push(self)
32
32
  self
33
33
  end
@@ -43,6 +43,10 @@ module Truemail
43
43
  result.configuration.validation_type_by_domain[domain] || current_validation_type
44
44
  end
45
45
 
46
+ def constantize(symbol)
47
+ symbol.capitalize.to_s.gsub(/_[a-z]/, &:upcase).tr('_', '').to_sym
48
+ end
49
+
46
50
  def update_validation_type
47
51
  @validation_type = result.success ? :whitelist : :blacklist
48
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '2.3.2'
4
+ VERSION = '2.4.2'
5
5
  end
data/truemail.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['admin@bestweb.com.ua']
12
12
 
13
13
  spec.summary = %(truemail)
14
- spec.description = %(Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS and SMTP.)
14
+ spec.description = %(Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS, SMTP and even more.)
15
15
 
16
16
  spec.homepage = 'https://github.com/truemail-rb/truemail'
17
17
  spec.license = 'MIT'
@@ -33,21 +33,21 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'
35
35
 
36
- spec.add_development_dependency 'bundler', '~> 1.16'
37
- spec.add_development_dependency 'bundler-audit', '~> 0.7.0.1'
38
- spec.add_development_dependency 'dns_mock', '~> 1.2'
39
- spec.add_development_dependency 'faker', '~> 2.16'
36
+ spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.17'
37
+ spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
38
+ spec.add_development_dependency 'dns_mock', '~> 1.2', '>= 1.2.3'
39
+ spec.add_development_dependency 'faker', '~> 2.17'
40
40
  spec.add_development_dependency 'fasterer', '~> 0.9.0'
41
41
  spec.add_development_dependency 'json_matchers', '~> 0.11.1'
42
42
  spec.add_development_dependency 'overcommit', '~> 0.57.0'
43
43
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
44
44
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
45
- spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.3'
45
+ spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
46
46
  spec.add_development_dependency 'rspec', '~> 3.10'
47
- spec.add_development_dependency 'rubocop', '~> 1.11'
48
- spec.add_development_dependency 'rubocop-performance', '~> 1.10', '>= 1.10.1'
49
- spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
47
+ spec.add_development_dependency 'rubocop', '~> 1.14'
48
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
49
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3'
50
50
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
51
- spec.add_development_dependency 'truemail-rspec', '~> 0.4'
52
- spec.add_development_dependency 'webmock', '~> 3.12', '>= 3.12.1'
51
+ spec.add_development_dependency 'truemail-rspec', '~> 0.6'
52
+ spec.add_development_dependency 'webmock', '~> 3.12', '>= 3.12.2'
53
53
  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: 2.3.2
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simpleidn
@@ -30,28 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '2.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.2.17
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '1.16'
43
+ version: '2.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.17
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler-audit
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: 0.7.0.1
53
+ version: 0.8.0
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: 0.7.0.1
60
+ version: 0.8.0
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: dns_mock
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +65,9 @@ dependencies:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
67
  version: '1.2'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.2.3
62
71
  type: :development
63
72
  prerelease: false
64
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -66,20 +75,23 @@ dependencies:
66
75
  - - "~>"
67
76
  - !ruby/object:Gem::Version
68
77
  version: '1.2'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.2.3
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: faker
71
83
  requirement: !ruby/object:Gem::Requirement
72
84
  requirements:
73
85
  - - "~>"
74
86
  - !ruby/object:Gem::Version
75
- version: '2.16'
87
+ version: '2.17'
76
88
  type: :development
77
89
  prerelease: false
78
90
  version_requirements: !ruby/object:Gem::Requirement
79
91
  requirements:
80
92
  - - "~>"
81
93
  - !ruby/object:Gem::Version
82
- version: '2.16'
94
+ version: '2.17'
83
95
  - !ruby/object:Gem::Dependency
84
96
  name: fasterer
85
97
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +177,7 @@ dependencies:
165
177
  version: '6.0'
166
178
  - - ">="
167
179
  - !ruby/object:Gem::Version
168
- version: 6.0.3
180
+ version: 6.0.4
169
181
  type: :development
170
182
  prerelease: false
171
183
  version_requirements: !ruby/object:Gem::Requirement
@@ -175,7 +187,7 @@ dependencies:
175
187
  version: '6.0'
176
188
  - - ">="
177
189
  - !ruby/object:Gem::Version
178
- version: 6.0.3
190
+ version: 6.0.4
179
191
  - !ruby/object:Gem::Dependency
180
192
  name: rspec
181
193
  requirement: !ruby/object:Gem::Requirement
@@ -196,48 +208,48 @@ dependencies:
196
208
  requirements:
197
209
  - - "~>"
198
210
  - !ruby/object:Gem::Version
199
- version: '1.11'
211
+ version: '1.14'
200
212
  type: :development
201
213
  prerelease: false
202
214
  version_requirements: !ruby/object:Gem::Requirement
203
215
  requirements:
204
216
  - - "~>"
205
217
  - !ruby/object:Gem::Version
206
- version: '1.11'
218
+ version: '1.14'
207
219
  - !ruby/object:Gem::Dependency
208
220
  name: rubocop-performance
209
221
  requirement: !ruby/object:Gem::Requirement
210
222
  requirements:
211
223
  - - "~>"
212
224
  - !ruby/object:Gem::Version
213
- version: '1.10'
225
+ version: '1.11'
214
226
  - - ">="
215
227
  - !ruby/object:Gem::Version
216
- version: 1.10.1
228
+ version: 1.11.3
217
229
  type: :development
218
230
  prerelease: false
219
231
  version_requirements: !ruby/object:Gem::Requirement
220
232
  requirements:
221
233
  - - "~>"
222
234
  - !ruby/object:Gem::Version
223
- version: '1.10'
235
+ version: '1.11'
224
236
  - - ">="
225
237
  - !ruby/object:Gem::Version
226
- version: 1.10.1
238
+ version: 1.11.3
227
239
  - !ruby/object:Gem::Dependency
228
240
  name: rubocop-rspec
229
241
  requirement: !ruby/object:Gem::Requirement
230
242
  requirements:
231
243
  - - "~>"
232
244
  - !ruby/object:Gem::Version
233
- version: '2.2'
245
+ version: '2.3'
234
246
  type: :development
235
247
  prerelease: false
236
248
  version_requirements: !ruby/object:Gem::Requirement
237
249
  requirements:
238
250
  - - "~>"
239
251
  - !ruby/object:Gem::Version
240
- version: '2.2'
252
+ version: '2.3'
241
253
  - !ruby/object:Gem::Dependency
242
254
  name: simplecov
243
255
  requirement: !ruby/object:Gem::Requirement
@@ -258,14 +270,14 @@ dependencies:
258
270
  requirements:
259
271
  - - "~>"
260
272
  - !ruby/object:Gem::Version
261
- version: '0.4'
273
+ version: '0.6'
262
274
  type: :development
263
275
  prerelease: false
264
276
  version_requirements: !ruby/object:Gem::Requirement
265
277
  requirements:
266
278
  - - "~>"
267
279
  - !ruby/object:Gem::Version
268
- version: '0.4'
280
+ version: '0.6'
269
281
  - !ruby/object:Gem::Dependency
270
282
  name: webmock
271
283
  requirement: !ruby/object:Gem::Requirement
@@ -275,7 +287,7 @@ dependencies:
275
287
  version: '3.12'
276
288
  - - ">="
277
289
  - !ruby/object:Gem::Version
278
- version: 3.12.1
290
+ version: 3.12.2
279
291
  type: :development
280
292
  prerelease: false
281
293
  version_requirements: !ruby/object:Gem::Requirement
@@ -285,9 +297,9 @@ dependencies:
285
297
  version: '3.12'
286
298
  - - ">="
287
299
  - !ruby/object:Gem::Version
288
- version: 3.12.1
300
+ version: 3.12.2
289
301
  description: Configurable framework agnostic plain Ruby email validator. Verify email
290
- via Regex, DNS and SMTP.
302
+ via Regex, DNS, SMTP and even more.
291
303
  email:
292
304
  - admin@bestweb.com.ua
293
305
  executables: []
@@ -341,6 +353,7 @@ files:
341
353
  - lib/truemail/validate/base.rb
342
354
  - lib/truemail/validate/domain_list_match.rb
343
355
  - lib/truemail/validate/mx.rb
356
+ - lib/truemail/validate/mx_blacklist.rb
344
357
  - lib/truemail/validate/regex.rb
345
358
  - lib/truemail/validate/smtp.rb
346
359
  - lib/truemail/validate/smtp/request.rb