email_address 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/email_address/address.rb +2 -2
- data/lib/email_address/config.rb +1 -1
- data/lib/email_address/host.rb +48 -15
- data/lib/email_address/version.rb +1 -1
- data/test/email_address/test_host.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 865ef9fea556b3de09bffbfc977f751ef806da92
|
4
|
+
data.tar.gz: c647502c488d49962b962090c5b3623bc89c774c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c1508f8e3e73960157d00306db1d0d692e7e9f33db00d8a7ebce75bf1ce56626b670e5fb0f322b54fe78154d79815cefa0350d2f2187c049c13ede4341a828
|
7
|
+
data.tar.gz: 6811f8ec8f1ca8e5253df4cbc58e90d4e6e27ff35014ce56ac59bc70d9a4ed1044d3f09ad0ce3a451238e7328c7eb2721d36840d5f6197616e38bda63c53b2ff
|
@@ -217,7 +217,7 @@ module EmailAddress
|
|
217
217
|
return set_error :invalid_mailbox
|
218
218
|
end
|
219
219
|
unless self.host.valid?
|
220
|
-
return set_error
|
220
|
+
return set_error self.host.error_message
|
221
221
|
end
|
222
222
|
if @config[:address_size] && !@config[:address_size].include?(self.to_s.size)
|
223
223
|
return set_error :exceeds_size
|
@@ -237,7 +237,7 @@ module EmailAddress
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def set_error(err)
|
240
|
-
@error = EmailAddress::Config.error_messages
|
240
|
+
@error = EmailAddress::Config.error_messages.fetch(err) { err }
|
241
241
|
false
|
242
242
|
end
|
243
243
|
|
data/lib/email_address/config.rb
CHANGED
@@ -93,7 +93,7 @@ module EmailAddress
|
|
93
93
|
munge_string: "*****",
|
94
94
|
|
95
95
|
local_downcase: true,
|
96
|
-
local_fix:
|
96
|
+
local_fix: false,
|
97
97
|
local_encoding: :ascii, # :ascii, :unicode,
|
98
98
|
local_parse: nil, # nil, Proc
|
99
99
|
local_format: :conventional, # :conventional, :relaxed, :redacted, :standard, Proc
|
data/lib/email_address/host.rb
CHANGED
@@ -33,7 +33,7 @@ module EmailAddress
|
|
33
33
|
attr_reader :host_name
|
34
34
|
attr_accessor :dns_name, :domain_name, :registration_name,
|
35
35
|
:tld, :tld2, :subdomains, :ip_address, :config, :provider,
|
36
|
-
:comment
|
36
|
+
:comment, :error_message
|
37
37
|
MAX_HOST_LENGTH = 255
|
38
38
|
|
39
39
|
# Sometimes, you just need a Regexp...
|
@@ -313,11 +313,6 @@ module EmailAddress
|
|
313
313
|
EmailAddress::Config.setting(:dns_lookup).equal?(:off) ? false : true
|
314
314
|
end
|
315
315
|
|
316
|
-
# True if the host name has a DNS A Record
|
317
|
-
def has_dns_a_record?
|
318
|
-
dns_a_record.size > 0 ? true : false
|
319
|
-
end
|
320
|
-
|
321
316
|
# Returns: [official_hostname, alias_hostnames, address_family, *address_list]
|
322
317
|
def dns_a_record
|
323
318
|
@_dns_a_record ||= Socket.gethostbyname(self.dns_name)
|
@@ -366,16 +361,49 @@ module EmailAddress
|
|
366
361
|
|
367
362
|
# Returns true if the host name is valid according to the current configuration
|
368
363
|
def valid?(rule=@config[:dns_lookup]||:mx)
|
364
|
+
self.error_message = nil
|
369
365
|
if self.ip_address
|
370
|
-
|
366
|
+
valid_ip?
|
367
|
+
elsif ! valid_format?
|
368
|
+
false
|
371
369
|
elsif rule == :mx
|
372
|
-
|
370
|
+
valid_mx?
|
373
371
|
elsif rule == :a
|
374
|
-
|
372
|
+
valid_dns?
|
375
373
|
elsif rule == :off
|
376
|
-
|
374
|
+
true
|
377
375
|
else
|
378
|
-
|
376
|
+
set_error(:domain_bad_validation_rule)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
# The inverse of valid? -- Returns nil (falsey) if valid, otherwise error message
|
381
|
+
def error
|
382
|
+
valid? ? nil : @error_message
|
383
|
+
end
|
384
|
+
|
385
|
+
# True if the host name has a DNS A Record
|
386
|
+
def valid_dns?
|
387
|
+
dns_a_record.size > 0 || set_error(:domain_unknown)
|
388
|
+
end
|
389
|
+
|
390
|
+
# True if the host name has valid MX servers configured in DNS
|
391
|
+
def valid_mx?
|
392
|
+
if self.exchangers.mx_ips.size > 0
|
393
|
+
true
|
394
|
+
elsif valid_dns?
|
395
|
+
set_error(:domain_does_not_accept_email)
|
396
|
+
else
|
397
|
+
set_error(:domain_unknown)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
# True if the host_name passes Regular Expression match and size limits.
|
402
|
+
def valid_format?
|
403
|
+
if self.host_name =~ CANONICAL_HOST_REGEX && self.to_s.size <= MAX_HOST_LENGTH
|
404
|
+
true
|
405
|
+
else
|
406
|
+
set_error(:domain_invalid)
|
379
407
|
end
|
380
408
|
end
|
381
409
|
|
@@ -383,14 +411,19 @@ module EmailAddress
|
|
383
411
|
# is a potentially valid IP address. It does not check if the address
|
384
412
|
# is reachable.
|
385
413
|
def valid_ip?
|
386
|
-
if
|
387
|
-
|
414
|
+
if ! @config[:host_allow_ip]
|
415
|
+
set_error(:ip_address_forbidden)
|
388
416
|
elsif self.ip_address.include?(":")
|
389
|
-
self.ip_address =~ Resolv::IPv6::Regex ? true :
|
417
|
+
self.ip_address =~ Resolv::IPv6::Regex ? true : set_error(:ipv6_address_invalid)
|
390
418
|
elsif self.ip_address.include?(".")
|
391
|
-
self.ip_address =~ Resolv::IPv4::Regex ? true :
|
419
|
+
self.ip_address =~ Resolv::IPv4::Regex ? true : set_error(:ipv4_address_invalid)
|
392
420
|
end
|
393
421
|
end
|
394
422
|
|
423
|
+
def set_error(err)
|
424
|
+
@error_message = EmailAddress::Config.error_messages.fetch(err) { err }
|
425
|
+
false
|
426
|
+
end
|
427
|
+
|
395
428
|
end
|
396
429
|
end
|
@@ -111,4 +111,15 @@ class TestHost < MiniTest::Test
|
|
111
111
|
assert ! EmailAddress::Host.new('ya hoo.com').valid?
|
112
112
|
assert EmailAddress::Host.new('ya hoo.com', host_remove_spaces:true).valid?
|
113
113
|
end
|
114
|
+
|
115
|
+
def test_errors
|
116
|
+
assert_equal EmailAddress::Host.new("yahoo.com").error, nil
|
117
|
+
assert_equal EmailAddress::Host.new("example.com").error, :domain_does_not_accept_email
|
118
|
+
assert_equal EmailAddress::Host.new("yahoo.wtf").error, :domain_unknown
|
119
|
+
assert_equal EmailAddress::Host.new("ajsdfhajshdfklasjhd.wtf", dns_lookup: :off).error, nil
|
120
|
+
assert_equal EmailAddress::Host.new("ya hoo.com", dns_lookup: :off).error, :domain_invalid
|
121
|
+
assert_equal EmailAddress::Host.new("[127.0.0.1]").error, :ip_address_forbidden
|
122
|
+
assert_equal EmailAddress::Host.new("[127.0.0.666]", host_allow_ip:true).error, :ipv4_address_invalid
|
123
|
+
assert_equal EmailAddress::Host.new("[IPv6::12t]", host_allow_ip:true).error, :ipv6_address_invalid
|
124
|
+
end
|
114
125
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Fair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|