email_address 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad468bd4a05991b9a99adbeabd6fdb8c40d965fcdeed1559ddeb95ad6d599d13
4
- data.tar.gz: b3b678cf78737eee8ca6a9febb5ff2434edb322b6393383ca7cd50042e66833c
3
+ metadata.gz: dc99a156cbc12320e084571723e8633c5c1f8a3e92a9e47258d9521c0f27fcc6
4
+ data.tar.gz: '05302795638cad6027f50b778253484f390ef2cd697c665150d1e5a2d214172d'
5
5
  SHA512:
6
- metadata.gz: b453716b5ffb47f3cc9a03fd153cb38349d686bfa8830f273c9f9704736ac987c36128c788ab84472c5a3c5d483743f675c1126bf621643fd979f0235bd19f11
7
- data.tar.gz: 0e5bdf1545efd28e45da88e600e7e0bf88ddbed11c1e46c516206f5a301b4e7c0a87301daa90141cf91c8403fc1ea8fcb8cd7a725e64b5d9f810428d14115fe8
6
+ metadata.gz: 58c0ec4c8260854d9f7bacaf6c7891e661c9953f57c678d9bd03ab7e14e69b5a48902ca651ec29105a1fd13b08942187473340dace11cf81533af5ef1093dadc
7
+ data.tar.gz: 4d6ff21b55ed86a0d04ca8011d85a4f0c0f69637c80e9d2b6dc393717051fb15e703630bd531531c5453b3e8c0e301e34917fa48b3be1123f1c6ff3cd105e957
data/README.md CHANGED
@@ -552,7 +552,9 @@ For the mailbox (AKA account, role), without the tag
552
552
  :mx Ensure host is configured with DNS MX records
553
553
  :a Ensure host is known to DNS (A Record)
554
554
  :syntax Validate by syntax only, no Network verification
555
- :connect Attempt host connection (Dangerous: Do not use)
555
+ :connect Attempt host connection (Experimental and Dangerous: Do not use)
556
+ The :host_timeout setting is the maximum number
557
+ of seconds to wait during the :connect validation
556
558
 
557
559
  * host_size: 1..253,
558
560
  A range specifying the size limit of the host part,
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "sqlite3"
30
30
  spec.add_development_dependency "standard", "~> 1.5.0"
31
31
  end
32
- # spec.add_development_dependency "net-smtp"
32
+ spec.add_development_dependency "net-smtp"
33
33
  spec.add_development_dependency "simplecov"
34
34
  spec.add_development_dependency "pry"
35
35
 
@@ -137,6 +137,7 @@ module EmailAddress
137
137
  host_local: false,
138
138
  host_fqdn: true,
139
139
  host_auto_append: true,
140
+ host_timeout: 3,
140
141
 
141
142
  address_validation: :parts, # :parts, :smtp, Proc
142
143
  address_size: 3..254,
@@ -151,7 +152,7 @@ module EmailAddress
151
152
  google: {
152
153
  host_match: %w[gmail.com googlemail.com],
153
154
  exchanger_match: %w[google.com googlemail.com],
154
- local_size: 5..64,
155
+ local_size: 3..64,
155
156
  local_private_size: 1..64, # When hostname not in host_match (private label)
156
157
  mailbox_canonical: ->(m) { m.delete(".") }
157
158
  },
@@ -383,6 +383,9 @@ module EmailAddress
383
383
  host_validation = rules[:host_validation] || @config[:host_validation] || :mx
384
384
  dns_lookup = rules[:dns_lookup] || host_validation
385
385
  self.error_message = nil
386
+ if host_name && !host_name.empty? && !@config[:host_size].include?(host_name.size)
387
+ return set_error(:invalid_host)
388
+ end
386
389
  if ip_address
387
390
  valid_ip?
388
391
  elsif !valid_format?
@@ -462,11 +465,15 @@ module EmailAddress
462
465
  # as an email address check, but is provided to assist in problem resolution.
463
466
  # If you abuse this, you *could* be blocked by the ESP.
464
467
  #
465
- # NOTE: As of Ruby 3.1, Net::SMTP was moved from the standard library to the
466
- # 'net-smtp' gem. In order to avoid adding that dependency for this experimental
467
- # feature, please add the gem to your Gemfile and require it to use this feature.
468
- def connect
468
+ # timeout is the number of seconds to wait before timing out the request and
469
+ # returns false as the connection was unsuccessful.
470
+ #
471
+ # > NOTE: As of Ruby 3.1, Net::SMTP was moved from the standard library to the
472
+ # > 'net-smtp' gem. In order to avoid adding that dependency for this *experimental*
473
+ # > feature, please add the gem to your Gemfile and require it to use this feature.
474
+ def connect(timeout = nil)
469
475
  smtp = Net::SMTP.new(host_name || ip_address)
476
+ smtp.open_timeout = timeout || @config[:host_timeout]
470
477
  smtp.start(@config[:helo_name] || "localhost")
471
478
  smtp.finish
472
479
  true
@@ -474,10 +481,10 @@ module EmailAddress
474
481
  set_error(:server_not_available, e.to_s)
475
482
  rescue SocketError => e
476
483
  set_error(:server_not_available, e.to_s)
484
+ rescue Net::OpenTimeout => e
485
+ set_error(:server_not_available, e.to_s)
477
486
  ensure
478
- if smtp&.started?
479
- smtp.finish
480
- end
487
+ smtp.finish if smtp&.started?
481
488
  end
482
489
 
483
490
  def set_error(err, reason = nil)
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -150,4 +150,8 @@ class TestHost < MiniTest::Test
150
150
  assert_equal EmailAddress::Host.new("[127.0.0.666]", host_allow_ip: true).error, "This is not a valid IPv4 address"
151
151
  assert_equal EmailAddress::Host.new("[IPv6::12t]", host_allow_ip: true).error, "This is not a valid IPv6 address"
152
152
  end
153
+
154
+ def test_host_size
155
+ assert !EmailAddress::Host.new("stackoverflow.com", {host_size: 1..3}).valid?
156
+ end
153
157
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-14 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: net-smtp
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
209
  - !ruby/object:Gem::Version
196
210
  version: '0'
197
211
  requirements: []
198
- rubygems_version: 3.3.3
212
+ rubygems_version: 3.3.7
199
213
  signing_key:
200
214
  specification_version: 4
201
215
  summary: This gem provides a ruby language library for working with and validating