email_address 0.1.12 → 0.1.13

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: 24b689ac0a16f073c42a43b3f6e49c42e472c1fbef31290fa4c41f26389f3f51
4
- data.tar.gz: 7ba8fb68fa0e71a9821d08c8bb5e40ecd5acc625acebc707b4beb4f25240d628
3
+ metadata.gz: 67dd5ab4cf92d131f566e7cf275073dfd80f92f1024adb0a276e08bc81640878
4
+ data.tar.gz: fcccbc2f24aa40ee835c3a4cd5ec1a233823c7ab7d08afdb20f94f029b208493
5
5
  SHA512:
6
- metadata.gz: 4514eb116e370d6e3b4bf9ae006178dae86884228ff66053a0ecd8834943d6ab4a3dc8d6ef658c2c080090a1cb28343e3c3eeb1531bc4a3cedb532ac09dee470
7
- data.tar.gz: 146e6a106d2f3c3f6c73661b28b4371078d2a529b05fc09d2078aea64f3ce25ff036b91364f244c12fe037ac62ad02f1dbbbeed1d378dfd87a74624714d91d5b
6
+ metadata.gz: 7b28dfd2876f0a01cac862905bdd9b1c30d88505d0457a319469ec4ae35cb87d0b592ac6b028a531c2a115249eb3a6abb527896a63a1e2155ed6712618d2cff4
7
+ data.tar.gz: 4734fe3a428b07023963e7a01bf3a2853295a52ea4b308ddda8b82f8a0d09614ffabbc8d63c188b477b4a2f0f464ec76c70f6681b7423f7774b8205cbcefa4ad
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - ruby-head
3
+ - 2.7.0
4
4
  - 2.3.7
5
5
  - jruby-9.2.9.0
6
6
  #- rbx
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "activerecord", "= 4.2.10"
26
26
  spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", '~> 1.3.24'
27
27
  else
28
- spec.add_development_dependency "activerecord", "~> 5.2.0"
28
+ spec.add_development_dependency "activerecord", "~> 5.2.4"
29
29
  spec.add_development_dependency "sqlite3"
30
30
  end
31
31
  #spec.add_development_dependency "codeclimate-test-reporter"
@@ -24,8 +24,8 @@ module EmailAddress
24
24
  # address. The original string is available in the #original method.
25
25
  def initialize(email_address, config={})
26
26
  @config = config # This needs refactoring!
27
- email_address = (email_address || "").strip
28
27
  @original = email_address
28
+ email_address = (email_address || "").strip
29
29
  email_address = parse_rewritten(email_address) unless config[:skip_rewrite]
30
30
  local, host = EmailAddress::Address.split_local_host(email_address)
31
31
 
@@ -246,9 +246,6 @@ module EmailAddress
246
246
  else
247
247
  return false unless self.local.valid?
248
248
  return false unless self.host.valid?
249
- end
250
- if @config[:address_validation] == :smtp
251
-
252
249
  end
253
250
  true
254
251
  end
@@ -9,6 +9,9 @@ module EmailAddress
9
9
  # :a - DNS A Record lookup (as some domains don't specify an MX incorrectly)
10
10
  # :off - Do not perform DNS lookup (Test mode, network unavailable)
11
11
  #
12
+ # * dns_timeout: nil
13
+ # False, or a timeout in seconds. Timeout on the DNS lookup, after which it will fail.
14
+ #
12
15
  # * sha1_secret ""
13
16
  # This application-level secret is appended to the email_address to compute
14
17
  # the SHA1 Digest, making it unique to your application so it can't easily be
@@ -99,6 +102,7 @@ module EmailAddress
99
102
  class Config
100
103
  @config = {
101
104
  dns_lookup: :mx, # :mx, :a, :off
105
+ dns_timeout: nil,
102
106
  sha1_secret: "",
103
107
  munge_string: "*****",
104
108
 
@@ -139,7 +143,7 @@ module EmailAddress
139
143
  },
140
144
  msn: {
141
145
  host_match: %w(msn. hotmail. outlook. live.),
142
- mailbox_validator: ->(m,t) { m =~ /\A[a-z][\-\w]*(?:\.[\-\w]+)*\z/i},
146
+ mailbox_validator: ->(m,t) { m =~ /\A\w[\-\w]*(?:\.[\-\w]+)*\z/i},
143
147
  },
144
148
  yahoo: {
145
149
  host_match: %w(yahoo. ymail. rocketmail.),
@@ -52,7 +52,14 @@ module EmailAddress
52
52
  def mxers
53
53
  return [["example.com", "0.0.0.0", 1]] if @config[:dns_lookup] == :off
54
54
  @mxers ||= Resolv::DNS.open do |dns|
55
- ress = dns.getresources(@host, Resolv::DNS::Resource::IN::MX)
55
+ dns.timeouts = @config[:dns_timeout] if @config[:dns_timeout]
56
+
57
+ ress = begin
58
+ dns.getresources(@host, Resolv::DNS::Resource::IN::MX)
59
+ rescue Resolv::ResolvTimeout
60
+ []
61
+ end
62
+
56
63
  records = ress.map do |r|
57
64
  begin
58
65
  if r.exchange.to_s > " "
@@ -350,8 +350,14 @@ module EmailAddress
350
350
  # Returns a DNS TXT Record
351
351
  def txt(alternate_host=nil)
352
352
  Resolv::DNS.open do |dns|
353
- records = dns.getresources(alternate_host || self.dns_name,
353
+ dns.timeouts = @config[:dns_timeout] if @config[:dns_timeout]
354
+ records = begin
355
+ dns.getresources(alternate_host || self.dns_name,
354
356
  Resolv::DNS::Resource::IN::TXT)
357
+ rescue Resolv::ResolvTimeout
358
+ []
359
+ end
360
+
355
361
  records.empty? ? nil : records.map(&:data).join(" ")
356
362
  end
357
363
  end
@@ -418,7 +424,7 @@ module EmailAddress
418
424
  else
419
425
  true
420
426
  end
421
- elsif valid_dns?
427
+ elsif @config[:dns_timeout].nil? && valid_dns?
422
428
  set_error(:domain_does_not_accept_email)
423
429
  else
424
430
  set_error(:domain_unknown)
@@ -101,6 +101,11 @@ module EmailAddress
101
101
 
102
102
  REDACTED_REGEX = /\A \{ [0-9a-f]{40} \} \z/x # {sha1}
103
103
 
104
+ CONVENTIONAL_TAG_REGEX = # AZaz09_!'+-/=
105
+ %r/^([\w\!\'\+\-\/\=]+)$/i.freeze
106
+ RELAXED_TAG_REGEX = # AZaz09_!#$%&'*+-/=?^`{|}~
107
+ %r/^([\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+)$/i.freeze
108
+
104
109
  def initialize(local, config={}, host=nil)
105
110
  self.config = config.empty? ? EmailAddress::Config.all_settings : config
106
111
  self.local = local
@@ -328,7 +333,12 @@ module EmailAddress
328
333
  # True if the part matches the conventional format
329
334
  def conventional?
330
335
  self.syntax = :invalid
331
- self.local =~ CONVENTIONAL_MAILBOX_REGEX or return false
336
+ if self.tag
337
+ return false unless self.mailbox =~ CONVENTIONAL_MAILBOX_REGEX &&
338
+ self.tag =~ CONVENTIONAL_TAG_REGEX
339
+ else
340
+ return false unless self.local =~ CONVENTIONAL_MAILBOX_REGEX
341
+ end
332
342
  self.valid_size? or return false
333
343
  self.valid_encoding? or return false
334
344
  self.syntax = :conventional
@@ -340,7 +350,10 @@ module EmailAddress
340
350
  self.syntax = :invalid
341
351
  self.valid_size? or return false
342
352
  self.valid_encoding? or return false
343
- if self.local =~ RELAXED_MAILBOX_REGEX
353
+ if self.tag
354
+ return false unless self.mailbox =~ RELAXED_MAILBOX_REGEX &&
355
+ self.tag =~ RELAXED_TAG_REGEX
356
+ elsif self.local =~ RELAXED_MAILBOX_REGEX
344
357
  self.syntax = :relaxed
345
358
  true
346
359
  else
@@ -384,7 +397,7 @@ module EmailAddress
384
397
  end
385
398
 
386
399
  def error
387
- self.valid? ? nil : @error
400
+ self.valid? ? nil : ( @error || :local_invalid)
388
401
  end
389
402
 
390
403
  end
@@ -16,5 +16,6 @@ en:
16
16
  ipv6_address_invalid: "This is not a valid IPv6 address"
17
17
  local_size_long: "Mailbox name too long"
18
18
  local_size_short: "Mailbox name too short"
19
+ local_invalid: "Recipient is not valid"
19
20
  not_allowed: "Address is not allowed"
20
21
  server_not_available: "The remote email server is not available"
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
@@ -116,4 +116,12 @@ class TestAddress < Minitest::Test
116
116
  assert ! EmailAddress.new('a.c.m.e.-industries@foo.com').valid?
117
117
  assert true, EmailAddress.new('a.c.m.e.-industries@foo.com', local_format: :relaxed).valid?
118
118
  end
119
+
120
+ def test_nil_address
121
+ assert_nil EmailAddress.new(nil).normal, "Expected a nil input to make nil output"
122
+ end
123
+
124
+ def test_nonstandard_tag
125
+ assert EmailAddress.valid?("asdfas+-@icloud.com")
126
+ end
119
127
  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.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 5.2.0
61
+ version: 5.2.4
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: 5.2.0
68
+ version: 5.2.4
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubygems_version: 3.0.6
186
+ rubygems_version: 3.1.2
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: This gem provides a ruby language library for working with and validating