truemail 2.3.4 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/truemail/core.rb CHANGED
@@ -20,12 +20,14 @@ module Truemail
20
20
 
21
21
  module RegexConstant
22
22
  REGEX_DOMAIN = /[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}/i.freeze
23
- REGEX_EMAIL_PATTERN = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\w|\-.+]*)@(#{REGEX_DOMAIN})\z)/.freeze
23
+ REGEX_EMAIL_PATTERN = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\W\w]*)@(#{REGEX_DOMAIN})\z)/.freeze
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_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
27
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
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
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.4'
4
+ VERSION = '2.4.4'
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'
36
+ spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.21'
37
37
  spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
38
- spec.add_development_dependency 'dns_mock', '~> 1.2', '>= 1.2.1'
39
- spec.add_development_dependency 'faker', '~> 2.17'
38
+ spec.add_development_dependency 'dns_mock', '~> 1.3'
39
+ spec.add_development_dependency 'faker', '~> 2.18'
40
40
  spec.add_development_dependency 'fasterer', '~> 0.9.0'
41
41
  spec.add_development_dependency 'json_matchers', '~> 0.11.1'
42
- spec.add_development_dependency 'overcommit', '~> 0.57.0'
42
+ spec.add_development_dependency 'overcommit', '~> 0.58.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.12', '>= 1.12.1'
48
- spec.add_development_dependency 'rubocop-performance', '~> 1.10', '>= 1.10.2'
49
- spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
47
+ spec.add_development_dependency 'rubocop', '~> 1.18'
48
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
49
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
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.2'
51
+ spec.add_development_dependency 'truemail-rspec', '~> 0.6'
52
+ spec.add_development_dependency 'webmock', '~> 3.13'
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.4
4
+ version: 2.4.4
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-04-16 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simpleidn
@@ -30,14 +30,20 @@ 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.21
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.21
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler-audit
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,34 +64,28 @@ dependencies:
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.2'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.2.1
67
+ version: '1.3'
65
68
  type: :development
66
69
  prerelease: false
67
70
  version_requirements: !ruby/object:Gem::Requirement
68
71
  requirements:
69
72
  - - "~>"
70
73
  - !ruby/object:Gem::Version
71
- version: '1.2'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 1.2.1
74
+ version: '1.3'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: faker
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2.17'
81
+ version: '2.18'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '2.17'
88
+ version: '2.18'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: fasterer
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 0.57.0
123
+ version: 0.58.0
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 0.57.0
130
+ version: 0.58.0
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: pry-byebug
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +171,7 @@ dependencies:
171
171
  version: '6.0'
172
172
  - - ">="
173
173
  - !ruby/object:Gem::Version
174
- version: 6.0.3
174
+ version: 6.0.4
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
@@ -181,7 +181,7 @@ dependencies:
181
181
  version: '6.0'
182
182
  - - ">="
183
183
  - !ruby/object:Gem::Version
184
- version: 6.0.3
184
+ version: 6.0.4
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: rspec
187
187
  requirement: !ruby/object:Gem::Requirement
@@ -202,54 +202,48 @@ dependencies:
202
202
  requirements:
203
203
  - - "~>"
204
204
  - !ruby/object:Gem::Version
205
- version: '1.12'
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: 1.12.1
205
+ version: '1.18'
209
206
  type: :development
210
207
  prerelease: false
211
208
  version_requirements: !ruby/object:Gem::Requirement
212
209
  requirements:
213
210
  - - "~>"
214
211
  - !ruby/object:Gem::Version
215
- version: '1.12'
216
- - - ">="
217
- - !ruby/object:Gem::Version
218
- version: 1.12.1
212
+ version: '1.18'
219
213
  - !ruby/object:Gem::Dependency
220
214
  name: rubocop-performance
221
215
  requirement: !ruby/object:Gem::Requirement
222
216
  requirements:
223
217
  - - "~>"
224
218
  - !ruby/object:Gem::Version
225
- version: '1.10'
219
+ version: '1.11'
226
220
  - - ">="
227
221
  - !ruby/object:Gem::Version
228
- version: 1.10.2
222
+ version: 1.11.3
229
223
  type: :development
230
224
  prerelease: false
231
225
  version_requirements: !ruby/object:Gem::Requirement
232
226
  requirements:
233
227
  - - "~>"
234
228
  - !ruby/object:Gem::Version
235
- version: '1.10'
229
+ version: '1.11'
236
230
  - - ">="
237
231
  - !ruby/object:Gem::Version
238
- version: 1.10.2
232
+ version: 1.11.3
239
233
  - !ruby/object:Gem::Dependency
240
234
  name: rubocop-rspec
241
235
  requirement: !ruby/object:Gem::Requirement
242
236
  requirements:
243
237
  - - "~>"
244
238
  - !ruby/object:Gem::Version
245
- version: '2.2'
239
+ version: '2.4'
246
240
  type: :development
247
241
  prerelease: false
248
242
  version_requirements: !ruby/object:Gem::Requirement
249
243
  requirements:
250
244
  - - "~>"
251
245
  - !ruby/object:Gem::Version
252
- version: '2.2'
246
+ version: '2.4'
253
247
  - !ruby/object:Gem::Dependency
254
248
  name: simplecov
255
249
  requirement: !ruby/object:Gem::Requirement
@@ -270,36 +264,30 @@ dependencies:
270
264
  requirements:
271
265
  - - "~>"
272
266
  - !ruby/object:Gem::Version
273
- version: '0.4'
267
+ version: '0.6'
274
268
  type: :development
275
269
  prerelease: false
276
270
  version_requirements: !ruby/object:Gem::Requirement
277
271
  requirements:
278
272
  - - "~>"
279
273
  - !ruby/object:Gem::Version
280
- version: '0.4'
274
+ version: '0.6'
281
275
  - !ruby/object:Gem::Dependency
282
276
  name: webmock
283
277
  requirement: !ruby/object:Gem::Requirement
284
278
  requirements:
285
279
  - - "~>"
286
280
  - !ruby/object:Gem::Version
287
- version: '3.12'
288
- - - ">="
289
- - !ruby/object:Gem::Version
290
- version: 3.12.2
281
+ version: '3.13'
291
282
  type: :development
292
283
  prerelease: false
293
284
  version_requirements: !ruby/object:Gem::Requirement
294
285
  requirements:
295
286
  - - "~>"
296
287
  - !ruby/object:Gem::Version
297
- version: '3.12'
298
- - - ">="
299
- - !ruby/object:Gem::Version
300
- version: 3.12.2
288
+ version: '3.13'
301
289
  description: Configurable framework agnostic plain Ruby email validator. Verify email
302
- via Regex, DNS and SMTP.
290
+ via Regex, DNS, SMTP and even more.
303
291
  email:
304
292
  - admin@bestweb.com.ua
305
293
  executables: []
@@ -353,6 +341,7 @@ files:
353
341
  - lib/truemail/validate/base.rb
354
342
  - lib/truemail/validate/domain_list_match.rb
355
343
  - lib/truemail/validate/mx.rb
344
+ - lib/truemail/validate/mx_blacklist.rb
356
345
  - lib/truemail/validate/regex.rb
357
346
  - lib/truemail/validate/smtp.rb
358
347
  - lib/truemail/validate/smtp/request.rb
@@ -386,8 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
386
375
  - !ruby/object:Gem::Version
387
376
  version: '0'
388
377
  requirements: []
389
- rubyforge_project:
390
- rubygems_version: 2.7.3
378
+ rubygems_version: 3.2.20
391
379
  signing_key:
392
380
  specification_version: 4
393
381
  summary: truemail