email_address 0.2.0 → 0.2.3

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: f9667acc31d6ce84fd3acb2e8e2f3ea04e496df5ff9dc5f89815fa148df1113e
4
- data.tar.gz: e17aa2b229cb28ca80dcbf37226a5411052758db1e15cee0ddc2038d5244de42
3
+ metadata.gz: ad468bd4a05991b9a99adbeabd6fdb8c40d965fcdeed1559ddeb95ad6d599d13
4
+ data.tar.gz: b3b678cf78737eee8ca6a9febb5ff2434edb322b6393383ca7cd50042e66833c
5
5
  SHA512:
6
- metadata.gz: 908fa1ffaa5692b07fa4e586a66a8fdf6395c1a51013ee389e0437df175d6712ecc57831b6616cfabd28463a87c7a60df9b6ba8382cba0c58d8449e4ada51c6d
7
- data.tar.gz: a9f2a9bb8280118af5b21b08e8ca2273b16f3d5f700b91cb7c36b22444a7d5878e54a45292a2080243aff6fa4d31cd2ca3af4bd664f182b49d52ab42b864c711
6
+ metadata.gz: b453716b5ffb47f3cc9a03fd153cb38349d686bfa8830f273c9f9704736ac987c36128c788ab84472c5a3c5d483743f675c1126bf621643fd979f0235bd19f11
7
+ data.tar.gz: 0e5bdf1545efd28e45da88e600e7e0bf88ddbed11c1e46c516206f5a301b4e7c0a87301daa90141cf91c8403fc1ea8fcb8cd7a725e64b5d9f810428d14115fe8
@@ -5,7 +5,7 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- ruby-version: [2.6, 2.7, 3.0, jruby]
8
+ ruby-version: [2.6, 2.7, 3.0, 3.1, jruby]
9
9
  steps:
10
10
  - uses: actions/checkout@v2
11
11
  - uses: ruby/setup-ruby@v1
@@ -27,10 +27,11 @@ Gem::Specification.new do |spec|
27
27
  else
28
28
  spec.add_development_dependency "activerecord", "~> 6.1.4"
29
29
  spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "standard", "~> 1.5.0"
30
31
  end
32
+ # spec.add_development_dependency "net-smtp"
31
33
  spec.add_development_dependency "simplecov"
32
34
  spec.add_development_dependency "pry"
33
- spec.add_development_dependency "standard", "~> 1.1.1"
34
35
 
35
36
  spec.add_dependency "simpleidn"
36
37
  end
@@ -258,6 +258,10 @@ module EmailAddress
258
258
  # Connects to host to test if user can receive email. This should NOT be performed
259
259
  # as an email address check, but is provided to assist in problem resolution.
260
260
  # If you abuse this, you *could* be blocked by the ESP.
261
+ #
262
+ # NOTE: As of Ruby 3.1, Net::SMTP was moved from the standard library to the
263
+ # 'net-smtp' gem. In order to avoid adding that dependency for this experimental
264
+ # feature, please add the gem to your Gemfile and require it to use this feature.
261
265
  def connect
262
266
  smtp = Net::SMTP.new(host_name || ip_address)
263
267
  smtp.start(@config[:smtp_helo_name] || "localhost")
@@ -81,6 +81,12 @@ module EmailAddress
81
81
  # * host_local: false,
82
82
  # Allow localhost, no domain, or local subdomains.
83
83
  #
84
+ # * host_fqdn: true
85
+ # Check if host name is FQDN
86
+ #
87
+ # * host_auto_append: true
88
+ # Append localhost if host is missing
89
+ #
84
90
  # * address_validation: :parts, :smtp, ->(address) { true }
85
91
  # Address validation policy
86
92
  # :parts Validate local and host.
@@ -129,6 +135,8 @@ module EmailAddress
129
135
  host_allow_ip: false,
130
136
  host_remove_spaces: false,
131
137
  host_local: false,
138
+ host_fqdn: true,
139
+ host_auto_append: true,
132
140
 
133
141
  address_validation: :parts, # :parts, :smtp, Proc
134
142
  address_size: 3..254,
@@ -188,7 +196,7 @@ module EmailAddress
188
196
  end
189
197
 
190
198
  def self.error_message(name, locale = "en")
191
- @errors[locale]["email_address"][name.to_s] || name.to_s
199
+ @errors.dig(locale, "email_address", name.to_s) || name.to_s
192
200
  end
193
201
 
194
202
  # Customize your own error message text.
@@ -1,6 +1,5 @@
1
1
  require "simpleidn"
2
2
  require "resolv"
3
- require "net/smtp"
4
3
 
5
4
  module EmailAddress
6
5
  ##############################################################################
@@ -184,7 +183,7 @@ module EmailAddress
184
183
  def fully_qualified_domain_name(host_part)
185
184
  dn = @config[:address_fqdn_domain]
186
185
  if !dn
187
- if (host_part.nil? || host_part <= " ") && @config[:host_local]
186
+ if (host_part.nil? || host_part <= " ") && @config[:host_local] && @config[:host_auto_append]
188
187
  "localhost"
189
188
  else
190
189
  host_part
@@ -402,11 +401,7 @@ module EmailAddress
402
401
  # True if the host name has a DNS A Record
403
402
  def valid_dns?
404
403
  return true unless dns_enabled?
405
- bool = dns_a_record.size > 0 || set_error(:domain_unknown)
406
- if localhost? && !@config[:host_local]
407
- bool = set_error(:domain_no_localhost)
408
- end
409
- bool
404
+ dns_a_record.size > 0 || set_error(:domain_unknown)
410
405
  end
411
406
 
412
407
  # True if the host name has valid MX servers configured in DNS
@@ -430,7 +425,11 @@ module EmailAddress
430
425
  # True if the host_name passes Regular Expression match and size limits.
431
426
  def valid_format?
432
427
  if host_name =~ CANONICAL_HOST_REGEX && to_s.size <= MAX_HOST_LENGTH
433
- return true if localhost?
428
+ if localhost?
429
+ return @config[:host_local] ? true : set_error(:domain_no_localhost)
430
+ end
431
+
432
+ return true if !@config[:host_fqdn]
434
433
  return true if host_name.include?(".") # require FQDN
435
434
  end
436
435
  set_error(:domain_invalid)
@@ -462,6 +461,10 @@ module EmailAddress
462
461
  # Connects to host to test it can receive email. This should NOT be performed
463
462
  # as an email address check, but is provided to assist in problem resolution.
464
463
  # If you abuse this, you *could* be blocked by the ESP.
464
+ #
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.
465
468
  def connect
466
469
  smtp = Net::SMTP.new(host_name || ip_address)
467
470
  smtp.start(@config[:helo_name] || "localhost")
@@ -351,8 +351,10 @@ module EmailAddress
351
351
  valid_size? or return false
352
352
  valid_encoding? or return false
353
353
  if tag
354
- return false unless mailbox =~ RELAXED_MAILBOX_REGEX &&
355
- tag =~ RELAXED_TAG_REGEX
354
+ return false unless RELAXED_MAILBOX_REGEX.match?(mailbox) &&
355
+ RELAXED_TAG_REGEX.match?(tag)
356
+ self.syntax = :relaxed
357
+ true
356
358
  elsif RELAXED_MAILBOX_REGEX.match?(local)
357
359
  self.syntax = :relaxed
358
360
  true
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -103,7 +103,10 @@ class TestAddress < Minitest::Test
103
103
  assert_equal false, e.valid? # localhost not allowed by default
104
104
  assert_equal EmailAddress.error("user1"), "Invalid Domain Name"
105
105
  assert_equal EmailAddress.error("user1", host_local: true), "This domain is not configured to accept email"
106
+ assert_equal EmailAddress.error("user1", host_local: true, host_auto_append: false), "Invalid Domain Name"
106
107
  assert_equal EmailAddress.error("user1@localhost", host_local: true), "This domain is not configured to accept email"
108
+ assert_equal EmailAddress.error("user1@localhost", host_local: false, host_validation: :syntax), "localhost is not allowed for your domain name"
109
+ assert_equal EmailAddress.error("user1@localhost", host_local: false, dns_lookup: :off), "localhost is not allowed for your domain name"
107
110
  assert_nil EmailAddress.error("user2@localhost", host_local: true, dns_lookup: :off, host_validation: :syntax)
108
111
  end
109
112
 
@@ -68,6 +68,21 @@ class TestHost < MiniTest::Test
68
68
  assert_equal true, h.valid?
69
69
  end
70
70
 
71
+ def test_localhost
72
+ h = EmailAddress::Host.new("localhost", host_local: true, host_validation: :syntax)
73
+ assert_equal true, h.valid?
74
+ end
75
+
76
+ def test_host_no_dot
77
+ h = EmailAddress::Host.new("local", host_validation: :syntax)
78
+ assert_equal false, h.valid?
79
+ end
80
+
81
+ def test_host_no_dot_enable_fqdn
82
+ h = EmailAddress::Host.new("local", host_fqdn: false, host_validation: :syntax)
83
+ assert_equal true, h.valid?
84
+ end
85
+
71
86
  def test_comment
72
87
  h = EmailAddress::Host.new("(oops)gmail.com")
73
88
  assert_equal "gmail.com", h.to_s
@@ -110,7 +125,8 @@ class TestHost < MiniTest::Test
110
125
  end
111
126
 
112
127
  def test_hosted_service
113
- assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
128
+ # Is there a gmail-hosted domain that will continue to exist? Removing until then
129
+ # assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
114
130
  assert !EmailAddress.valid?("test@gmail.com", dns_lookup: :mx)
115
131
  end
116
132
 
@@ -105,4 +105,8 @@ class TestLocal < MiniTest::Test
105
105
  def test_tag_punctuation
106
106
  assert EmailAddress.valid?("first.last+foo.bar@gmail.com")
107
107
  end
108
+
109
+ def test_relaxed_tag
110
+ assert EmailAddress.valid? "foo+abc@example.com", host_validation: :syntax, local_format: :relaxed
111
+ end
108
112
  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.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -81,21 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov
84
+ name: standard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.5.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.5.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: standard
112
+ name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 1.1.1
117
+ version: '0'
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: 1.1.1
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simpleidn
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubygems_version: 3.2.15
198
+ rubygems_version: 3.3.3
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: This gem provides a ruby language library for working with and validating