truemail 1.5.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'truemail/core'
3
+ require_relative 'truemail/core'
4
4
 
5
5
  module Truemail
6
6
  INCOMPLETE_CONFIG = 'verifier_email is required parameter'
7
7
  NOT_CONFIGURED = 'use Truemail.configure before or pass custom configuration'
8
8
 
9
9
  class << self
10
- def configuration
10
+ def configuration(&block)
11
11
  @configuration ||= begin
12
12
  return unless block_given?
13
- configuration = Truemail::Configuration.new
14
- yield(configuration)
13
+ configuration = Truemail::Configuration.new(&block)
15
14
  raise_unless(configuration.complete?, Truemail::INCOMPLETE_CONFIG)
16
15
  configuration
17
16
  end
@@ -3,12 +3,20 @@
3
3
  module Truemail
4
4
  module Audit
5
5
  class Base < Truemail::Worker
6
+ require 'net/http'
7
+ require 'ipaddr'
8
+ require 'resolv'
9
+
6
10
  private
7
11
 
8
12
  def add_warning(message)
9
13
  result.warnings[self.class.name.split('::').last.downcase.to_sym] = message
10
14
  end
11
15
 
16
+ def current_host_ip
17
+ result.current_host_ip
18
+ end
19
+
12
20
  def configuration
13
21
  result.configuration
14
22
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Truemail
4
+ module Audit
5
+ class Dns < Truemail::Audit::Base
6
+ VERIFIER_DOMAIN_NOT_REFER = 'a record of verifier domain not refers to current host ip address'
7
+
8
+ def run
9
+ return if verifier_domain_refer_to_current_host_ip?
10
+ add_warning(Truemail::Audit::Dns::VERIFIER_DOMAIN_NOT_REFER)
11
+ end
12
+
13
+ private
14
+
15
+ def a_record
16
+ Truemail::Wrapper.call(configuration: configuration) do
17
+ Resolv::DNS.new.getaddress(verifier_domain).to_s
18
+ end
19
+ end
20
+
21
+ def verifier_domain_refer_to_current_host_ip?
22
+ a_record.eql?(current_host_ip)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Truemail
4
+ module Audit
5
+ class Ip < Truemail::Audit::Base
6
+ GET_MY_IP_URL = 'https://api.ipify.org'
7
+ IPIFY_ERROR = 'impossible to detect current host address via third party service'
8
+
9
+ def run
10
+ return add_warning(Truemail::Audit::Ip::IPIFY_ERROR) unless detect_current_host_ip
11
+ Truemail::Audit::Dns.check(result)
12
+ Truemail::Audit::Ptr.check(result)
13
+ end
14
+
15
+ private
16
+
17
+ def detect_ip_via_ipify
18
+ Net::HTTP.get(URI(Truemail::Audit::Ip::GET_MY_IP_URL))
19
+ end
20
+
21
+ def detect_current_host_ip
22
+ result.current_host_ip = Truemail::Wrapper.call(configuration: configuration) do
23
+ detect_ip_via_ipify
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -3,37 +3,19 @@
3
3
  module Truemail
4
4
  module Audit
5
5
  class Ptr < Truemail::Audit::Base
6
- require 'ipaddr'
7
- require 'resolv'
8
-
9
- GET_MY_IP_URL = 'https://api.ipify.org'
10
- IPIFY_ERROR = 'impossible to detect current host address via third party service'
11
- PTR_NOT_FOUND = 'ptr record for current host address was not found'
6
+ PTR_NOT_FOUND = 'ptr record for current host ip address was not found'
12
7
  PTR_NOT_REFER = 'ptr record does not reference to current verifier domain'
13
- VERIFIER_DOMAIN_NOT_REFER = 'a record of verifier domain not refers to current host address'
14
8
 
15
9
  def run
16
- return if !current_host_address && add_warning(Truemail::Audit::Ptr::IPIFY_ERROR)
17
- return if ptr_records.empty? && add_warning(Truemail::Audit::Ptr::PTR_NOT_FOUND)
18
- return if ptr_not_refer_to_verifier_domain? && add_warning(Truemail::Audit::Ptr::PTR_NOT_REFER)
19
- return if verifier_domain_refer_to_current_host_address?
20
- add_warning(Truemail::Audit::Ptr::VERIFIER_DOMAIN_NOT_REFER)
10
+ return add_warning(Truemail::Audit::Ptr::PTR_NOT_FOUND) if ptr_records.empty?
11
+ return if ptr_refer_to_verifier_domain?
12
+ add_warning(Truemail::Audit::Ptr::PTR_NOT_REFER)
21
13
  end
22
14
 
23
15
  private
24
16
 
25
- def detect_ip_via_ipify
26
- Net::HTTP.get(URI(Truemail::Audit::Ptr::GET_MY_IP_URL))
27
- end
28
-
29
- def current_host_address
30
- @current_host_address ||= Truemail::Wrapper.call(configuration: configuration) do
31
- IPAddr.new(detect_ip_via_ipify)
32
- end
33
- end
34
-
35
17
  def current_host_reverse_lookup
36
- current_host_address.reverse
18
+ IPAddr.new(current_host_ip).reverse
37
19
  end
38
20
 
39
21
  def ptr_records
@@ -44,18 +26,8 @@ module Truemail
44
26
  end || []
45
27
  end
46
28
 
47
- def ptr_not_refer_to_verifier_domain?
48
- !ptr_records.include?(verifier_domain)
49
- end
50
-
51
- def a_record
52
- Truemail::Wrapper.call(configuration: configuration) do
53
- Resolv::DNS.new.getaddress(verifier_domain).to_s
54
- end
55
- end
56
-
57
- def verifier_domain_refer_to_current_host_address?
58
- a_record.eql?(current_host_address.to_s)
29
+ def ptr_refer_to_verifier_domain?
30
+ ptr_records.include?(verifier_domain)
59
31
  end
60
32
  end
61
33
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Truemail
4
4
  class Auditor
5
- Result = Struct.new(:warnings, :configuration, keyword_init: true) do
5
+ Result = Struct.new(:current_host_ip, :warnings, :configuration, keyword_init: true) do
6
6
  def initialize(warnings: {}, **args)
7
7
  super
8
8
  end
@@ -15,7 +15,7 @@ module Truemail
15
15
  end
16
16
 
17
17
  def run
18
- Truemail::Audit::Ptr.check(result)
18
+ Truemail::Audit::Ip.check(result)
19
19
  self
20
20
  end
21
21
  end
@@ -20,9 +20,7 @@ module Truemail
20
20
  :blacklisted_domains,
21
21
  :logger
22
22
 
23
- attr_accessor :whitelist_validation, :smtp_safe_check
24
-
25
- alias retry_count connection_attempts
23
+ attr_accessor :whitelist_validation, :not_rfc_mx_lookup_flow, :smtp_safe_check
26
24
 
27
25
  def initialize(&block)
28
26
  instance_initializer.each do |instace_variable, value|
@@ -101,6 +99,7 @@ module Truemail
101
99
  whitelisted_domains: [],
102
100
  whitelist_validation: false,
103
101
  blacklisted_domains: [],
102
+ not_rfc_mx_lookup_flow: false,
104
103
  smtp_safe_check: false
105
104
  }
106
105
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- require 'truemail/version'
5
- require 'truemail/configuration'
6
- require 'truemail/worker'
7
- require 'truemail/wrapper'
8
- require 'truemail/auditor'
9
- require 'truemail/validator'
10
- require 'truemail/logger'
4
+ require_relative '../truemail/version'
5
+ require_relative '../truemail/configuration'
6
+ require_relative '../truemail/worker'
7
+ require_relative '../truemail/wrapper'
8
+ require_relative '../truemail/auditor'
9
+ require_relative '../truemail/validator'
10
+ require_relative '../truemail/logger'
11
11
 
12
12
  ConfigurationError = Class.new(StandardError)
13
13
 
14
14
  ArgumentError = Class.new(StandardError) do
15
- def initialize(current_param, class_name)
16
- super("#{current_param} is not a valid #{class_name}")
15
+ def initialize(arg_value, arg_name)
16
+ super("#{arg_value} is not a valid #{arg_name}")
17
17
  end
18
18
  end
19
19
 
@@ -37,24 +37,26 @@ module Truemail
37
37
  end
38
38
 
39
39
  module Audit
40
- require 'truemail/audit/base'
41
- require 'truemail/audit/ptr'
40
+ require_relative '../truemail/audit/base'
41
+ require_relative '../truemail/audit/ip'
42
+ require_relative '../truemail/audit/dns'
43
+ require_relative '../truemail/audit/ptr'
42
44
  end
43
45
 
44
46
  module Validate
45
- require 'truemail/validate/base'
46
- require 'truemail/validate/domain_list_match'
47
- require 'truemail/validate/regex'
48
- require 'truemail/validate/mx'
49
- require 'truemail/validate/smtp'
50
- require 'truemail/validate/smtp/response'
51
- require 'truemail/validate/smtp/request'
47
+ require_relative '../truemail/validate/base'
48
+ require_relative '../truemail/validate/domain_list_match'
49
+ require_relative '../truemail/validate/regex'
50
+ require_relative '../truemail/validate/mx'
51
+ require_relative '../truemail/validate/smtp'
52
+ require_relative '../truemail/validate/smtp/response'
53
+ require_relative '../truemail/validate/smtp/request'
52
54
  end
53
55
 
54
56
  module Log
55
- require 'truemail/log/event'
56
- require 'truemail/log/serializer/base'
57
- require 'truemail/log/serializer/text'
58
- require 'truemail/log/serializer/json'
57
+ require_relative '../truemail/log/event'
58
+ require_relative '../truemail/log/serializer/base'
59
+ require_relative '../truemail/log/serializer/text'
60
+ require_relative '../truemail/log/serializer/json'
59
61
  end
60
62
  end
@@ -67,6 +67,7 @@ module Truemail
67
67
  whitelist_validation: validation_configuration.whitelist_validation,
68
68
  whitelisted_domains: whitelisted_domains,
69
69
  blacklisted_domains: blacklisted_domains,
70
+ not_rfc_mx_lookup_flow: validation_configuration.not_rfc_mx_lookup_flow,
70
71
  smtp_safe_check: validation_configuration.smtp_safe_check,
71
72
  email_pattern: email_pattern,
72
73
  smtp_error_body_pattern: smtp_error_body_pattern
@@ -19,6 +19,7 @@ module Truemail
19
19
  private
20
20
 
21
21
  def host_extractor_methods
22
+ return %i[hosts_from_mx_records?] if configuration.not_rfc_mx_lookup_flow
22
23
  %i[hosts_from_mx_records? hosts_from_cname_records? host_from_a_record?]
23
24
  end
24
25
 
@@ -32,6 +32,10 @@ module Truemail
32
32
  self
33
33
  end
34
34
 
35
+ def as_json
36
+ Truemail::Log::Serializer::Json.call(self)
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def select_validation_type(email, current_validation_type)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '1.5.1'
4
+ VERSION = '1.8.0'
5
5
  end
@@ -27,17 +27,17 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.16'
29
29
  spec.add_development_dependency 'bundler-audit', '~> 0.6.1'
30
- spec.add_development_dependency 'fasterer', '~> 0.8.1'
31
- spec.add_development_dependency 'ffaker', '~> 2.13'
30
+ spec.add_development_dependency 'fasterer', '~> 0.8.3'
31
+ spec.add_development_dependency 'ffaker', '~> 2.14'
32
32
  spec.add_development_dependency 'json_matchers', '~> 0.11.1'
33
- spec.add_development_dependency 'overcommit', '~> 0.52.1'
34
- spec.add_development_dependency 'pry-byebug', '~> 3.7'
33
+ spec.add_development_dependency 'overcommit', '~> 0.53.0'
34
+ spec.add_development_dependency 'pry-byebug', '~> 3.9'
35
35
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
36
- spec.add_development_dependency 'reek', '~> 5.6'
36
+ spec.add_development_dependency 'reek', '~> 6.0'
37
37
  spec.add_development_dependency 'rspec', '~> 3.9'
38
38
  spec.add_development_dependency 'rubocop', '~> 0.79.0'
39
39
  spec.add_development_dependency 'rubocop-performance', '~> 1.5', '>= 1.5.2'
40
- spec.add_development_dependency 'rubocop-rspec', '~> 1.37', '>= 1.37.1'
40
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.39'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
42
- spec.add_development_dependency 'truemail-rspec', '~> 0.1.1'
42
+ spec.add_development_dependency 'truemail-rspec', '~> 0.1.2'
43
43
  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.5.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simpleidn
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.1
61
+ version: 0.8.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.1
68
+ version: 0.8.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ffaker
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.13'
75
+ version: '2.14'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.13'
82
+ version: '2.14'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: json_matchers
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.52.1
103
+ version: 0.53.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.52.1
110
+ version: 0.53.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry-byebug
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.7'
117
+ version: '3.9'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.7'
124
+ version: '3.9'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -148,14 +148,14 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '5.6'
151
+ version: '6.0'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '5.6'
158
+ version: '6.0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: rspec
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -210,20 +210,14 @@ dependencies:
210
210
  requirements:
211
211
  - - "~>"
212
212
  - !ruby/object:Gem::Version
213
- version: '1.37'
214
- - - ">="
215
- - !ruby/object:Gem::Version
216
- version: 1.37.1
213
+ version: '1.39'
217
214
  type: :development
218
215
  prerelease: false
219
216
  version_requirements: !ruby/object:Gem::Requirement
220
217
  requirements:
221
218
  - - "~>"
222
219
  - !ruby/object:Gem::Version
223
- version: '1.37'
224
- - - ">="
225
- - !ruby/object:Gem::Version
226
- version: 1.37.1
220
+ version: '1.39'
227
221
  - !ruby/object:Gem::Dependency
228
222
  name: simplecov
229
223
  requirement: !ruby/object:Gem::Requirement
@@ -244,14 +238,14 @@ dependencies:
244
238
  requirements:
245
239
  - - "~>"
246
240
  - !ruby/object:Gem::Version
247
- version: 0.1.1
241
+ version: 0.1.2
248
242
  type: :development
249
243
  prerelease: false
250
244
  version_requirements: !ruby/object:Gem::Requirement
251
245
  requirements:
252
246
  - - "~>"
253
247
  - !ruby/object:Gem::Version
254
- version: 0.1.1
248
+ version: 0.1.2
255
249
  description: Configurable framework agnostic plain Ruby email validator. Verify email
256
250
  via Regex, DNS and SMTP.
257
251
  email:
@@ -283,6 +277,8 @@ files:
283
277
  - bin/setup
284
278
  - lib/truemail.rb
285
279
  - lib/truemail/audit/base.rb
280
+ - lib/truemail/audit/dns.rb
281
+ - lib/truemail/audit/ip.rb
286
282
  - lib/truemail/audit/ptr.rb
287
283
  - lib/truemail/auditor.rb
288
284
  - lib/truemail/configuration.rb
@@ -308,7 +304,7 @@ homepage: https://github.com/rubygarage/truemail
308
304
  licenses:
309
305
  - MIT
310
306
  metadata: {}
311
- post_install_message:
307
+ post_install_message:
312
308
  rdoc_options: []
313
309
  require_paths:
314
310
  - lib
@@ -323,9 +319,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
319
  - !ruby/object:Gem::Version
324
320
  version: '0'
325
321
  requirements: []
326
- rubyforge_project:
327
- rubygems_version: 2.7.9
328
- signing_key:
322
+ rubyforge_project:
323
+ rubygems_version: 2.7.3
324
+ signing_key:
329
325
  specification_version: 4
330
326
  summary: truemail
331
327
  test_files: []