email_address 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/email_address.gemspec +1 -1
- data/lib/email_address/address.rb +1 -4
- data/lib/email_address/config.rb +5 -1
- data/lib/email_address/exchanger.rb +8 -1
- data/lib/email_address/host.rb +8 -2
- data/lib/email_address/local.rb +16 -3
- data/lib/email_address/messages.yaml +1 -0
- data/lib/email_address/version.rb +1 -1
- data/test/email_address/test_address.rb +8 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67dd5ab4cf92d131f566e7cf275073dfd80f92f1024adb0a276e08bc81640878
|
4
|
+
data.tar.gz: fcccbc2f24aa40ee835c3a4cd5ec1a233823c7ab7d08afdb20f94f029b208493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b28dfd2876f0a01cac862905bdd9b1c30d88505d0457a319469ec4ae35cb87d0b592ac6b028a531c2a115249eb3a6abb527896a63a1e2155ed6712618d2cff4
|
7
|
+
data.tar.gz: 4734fe3a428b07023963e7a01bf3a2853295a52ea4b308ddda8b82f8a0d09614ffabbc8d63c188b477b4a2f0f464ec76c70f6681b7423f7774b8205cbcefa4ad
|
data/.travis.yml
CHANGED
data/email_address.gemspec
CHANGED
@@ -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.
|
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
|
data/lib/email_address/config.rb
CHANGED
@@ -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[
|
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
|
-
|
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 > " "
|
data/lib/email_address/host.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/email_address/local.rb
CHANGED
@@ -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.
|
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.
|
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"
|
@@ -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.
|
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:
|
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.
|
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.
|
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.
|
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
|