email_address 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -16
- data/lib/email_address.rb +25 -39
- data/lib/email_address/address.rb +35 -4
- data/lib/email_address/config.rb +11 -4
- data/lib/email_address/host.rb +81 -15
- data/lib/email_address/version.rb +1 -1
- data/test/email_address/test_address.rb +9 -5
- data/test/email_address/test_host.rb +7 -7
- data/test/test_email_address.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7c4c2225713bcb8fa68e8c07aba6de9db62e629
|
4
|
+
data.tar.gz: 8c1f4a244a889254825d1325414536564a12abdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4927cd30d0302715b8f96a9224f13a85742242c27a1f813ffecdf75eb1896e2954fb36590213cad533d325ba121e096c15f74cb9c416fef191fe2181d668e591
|
7
|
+
data.tar.gz: c5c4426b8749dd1cdd4d8617da291c88d6dbca11040a3bcbb1d729e43b14dabf7a4f4c6bea244fec997bb0d0a21aa47462cf66056fdaf536f181e3702216d5dd
|
data/README.md
CHANGED
@@ -20,10 +20,6 @@ and can deal with gmail's "optional dots" in addresses.
|
|
20
20
|
It provides Active Record (Rails) extensions, including an
|
21
21
|
address validator and attributes API custom datatypes.
|
22
22
|
|
23
|
-
*Note:* Version 0.1.0 contains significant API and internal changes over the 0.0.3
|
24
|
-
version. If you have been using the 0.0.x series of the gem, you may
|
25
|
-
want to continue using with your current version.
|
26
|
-
|
27
23
|
Requires Ruby 2.0 or later.
|
28
24
|
|
29
25
|
## Quick Start
|
@@ -53,7 +49,7 @@ provider (such as Google Apps). Note that `example.com`, while
|
|
53
49
|
a valid domain name, does not have MX records.
|
54
50
|
|
55
51
|
EmailAddress.valid? "allen@example.com" #=> false
|
56
|
-
EmailAddress.valid? "allen@example.com",
|
52
|
+
EmailAddress.valid? "allen@example.com", host_validation: :syntax #=> true
|
57
53
|
|
58
54
|
Most mail servers do not yet support Unicode mailboxes, so the default here is ASCII.
|
59
55
|
|
@@ -359,23 +355,23 @@ control how the library treats that address. These can also be
|
|
359
355
|
configured during initialization by provider and default (see below).
|
360
356
|
|
361
357
|
EmailAddress.new("clark.kent@gmail.com",
|
362
|
-
|
358
|
+
host_validation: :syntax, host_encoding: :unicode)
|
363
359
|
|
364
360
|
Globally, you can change and query configuration options:
|
365
361
|
|
366
|
-
EmailAddress::Config.setting(:
|
367
|
-
EmailAddress::Config.setting(:
|
362
|
+
EmailAddress::Config.setting(:host_validation, :mx)
|
363
|
+
EmailAddress::Config.setting(:host_validation) #=> :mx
|
368
364
|
|
369
365
|
Or set multiple settings at once:
|
370
366
|
|
371
|
-
EmailAddress::Config.configure(local_downcase:false,
|
367
|
+
EmailAddress::Config.configure(local_downcase:false, host_validation: :syntax)
|
372
368
|
|
373
369
|
You can add special rules by domain or provider. It takes the options
|
374
370
|
above and adds the :domain_match and :exchanger_match rules.
|
375
371
|
|
376
372
|
EmailAddress.define_provider('google',
|
377
373
|
domain_match: %w(gmail.com googlemail.com),
|
378
|
-
exchanger_match: %w(google.com), # Requires
|
374
|
+
exchanger_match: %w(google.com), # Requires host_validation==:mx
|
379
375
|
local_size: 5..64,
|
380
376
|
mailbox_canonical: ->(m) {m.gsub('.','')})
|
381
377
|
|
@@ -417,11 +413,6 @@ Full translation support would be ideal though.
|
|
417
413
|
|
418
414
|
### Available Configuration Settings
|
419
415
|
|
420
|
-
* dns_lookup: Enables DNS lookup for validation by
|
421
|
-
* :mx - DNS MX Record lookup
|
422
|
-
* :a - DNS A Record lookup (as some domains don't specify an MX incorrectly)
|
423
|
-
* :off - Do not perform DNS lookup (Test mode, network unavailable)
|
424
|
-
|
425
416
|
* sha1_secret -
|
426
417
|
This application-level secret is appended to the email_address to compute
|
427
418
|
the SHA1 Digest, making it unique to your application so it can't easily be
|
@@ -478,7 +469,7 @@ For the mailbox (AKA account, role), without the tag
|
|
478
469
|
:mx Ensure host is configured with DNS MX records
|
479
470
|
:a Ensure host is known to DNS (A Record)
|
480
471
|
:syntax Validate by syntax only, no Network verification
|
481
|
-
:connect Attempt host connection (not
|
472
|
+
:connect Attempt host connection (Dangerous: Do not use)
|
482
473
|
|
483
474
|
* host_size: 1..253,
|
484
475
|
A range specifying the size limit of the host part,
|
data/lib/email_address.rb
CHANGED
@@ -13,59 +13,45 @@ module EmailAddress
|
|
13
13
|
require "email_address/canonical_email_address_type"
|
14
14
|
end
|
15
15
|
|
16
|
+
# @!method self.valid?(options={})
|
17
|
+
# Proxy method to {EmailAddress::Address#valid?}
|
18
|
+
# @!method self.error
|
19
|
+
# Proxy method to {EmailAddress::Address#error}
|
20
|
+
# @!method self.normal
|
21
|
+
# Proxy method to {EmailAddress::Address#normal}
|
22
|
+
# @!method self.redact(digest=:sha1)
|
23
|
+
# Proxy method to {EmailAddress::Address#redact}
|
24
|
+
# @!method self.munge
|
25
|
+
# Proxy method to {EmailAddress::Address#munge}
|
26
|
+
# @!method self.canonical
|
27
|
+
# Proxy method to {EmailAddress::Address#canonical}
|
28
|
+
# @!method self.reference
|
29
|
+
# Proxy method to {EmailAddress::Address#reference}
|
30
|
+
class << self
|
31
|
+
(%i[valid? error normal redact munge canonical reference] &
|
32
|
+
EmailAddress::Address.public_instance_methods
|
33
|
+
).each do |proxy_method|
|
34
|
+
define_method(proxy_method) do |*args, &block|
|
35
|
+
EmailAddress::Address.new(*args).public_send(proxy_method, &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
16
41
|
# Creates an instance of this email address.
|
17
42
|
# This is a short-cut to Email::Address::Address.new
|
18
43
|
def self.new(email_address, config={})
|
19
44
|
EmailAddress::Address.new(email_address, config)
|
20
45
|
end
|
21
46
|
|
22
|
-
# Given an email address, this returns true if the email validates, false otherwise
|
23
|
-
def self.valid?(email_address, config={})
|
24
|
-
self.new(email_address, config).valid?
|
25
|
-
end
|
26
|
-
|
27
|
-
# Given an email address, this returns nil if the email validates,
|
28
|
-
# or a string with a small error message otherwise
|
29
|
-
def self.error(email_address, config={})
|
30
|
-
self.new(email_address, config).error
|
31
|
-
end
|
32
|
-
|
33
|
-
# Shortcut to normalize the given email address in the given format
|
34
|
-
def self.normal(email_address, config={})
|
35
|
-
EmailAddress::Address.new(email_address, config).to_s
|
36
|
-
end
|
37
|
-
|
38
|
-
# Shortcut to normalize the given email address
|
39
|
-
def self.redact(email_address, config={})
|
40
|
-
EmailAddress::Address.new(email_address, config).redact
|
41
|
-
end
|
42
|
-
|
43
|
-
# Shortcut to munge the given email address for web publishing
|
44
|
-
# returns ma_____@do_____.com
|
45
|
-
def self.munge(email_address, config={})
|
46
|
-
EmailAddress::Address.new(email_address, config).munge
|
47
|
-
end
|
48
|
-
|
49
47
|
def self.new_redacted(email_address, config={})
|
50
48
|
EmailAddress::Address.new(EmailAddress::Address.new(email_address, config).redact)
|
51
49
|
end
|
52
50
|
|
53
|
-
# Returns the Canonical form of the email address. This form is what should
|
54
|
-
# be considered unique for an email account, lower case, and no address tags.
|
55
|
-
def self.canonical(email_address, config={})
|
56
|
-
EmailAddress::Address.new(email_address, config).canonical
|
57
|
-
end
|
58
|
-
|
59
51
|
def self.new_canonical(email_address, config={})
|
60
52
|
EmailAddress::Address.new(EmailAddress::Address.new(email_address, config).canonical, config)
|
61
53
|
end
|
62
54
|
|
63
|
-
# Returns the Reference form of the email address, defined as the MD5
|
64
|
-
# digest of the Canonical form.
|
65
|
-
def self.reference(email_address, config={})
|
66
|
-
EmailAddress::Address.new(email_address, config).reference
|
67
|
-
end
|
68
|
-
|
69
55
|
# Does the email address match any of the given rules
|
70
56
|
def self.matches?(email_address, rules, config={})
|
71
57
|
EmailAddress::Address.new(email_address, config).matches?(rules)
|
@@ -6,7 +6,7 @@ module EmailAddress
|
|
6
6
|
# (EmailAddress::Local) and Host (Email::AddressHost) parts.
|
7
7
|
class Address
|
8
8
|
include Comparable
|
9
|
-
attr_accessor :original, :local, :host, :config
|
9
|
+
attr_accessor :original, :local, :host, :config, :reason
|
10
10
|
|
11
11
|
CONVENTIONAL_REGEX = /\A#{::EmailAddress::Local::CONVENTIONAL_MAILBOX_WITHIN}
|
12
12
|
@#{::EmailAddress::Host::DNS_HOST_REGEX}\z/x
|
@@ -230,17 +230,48 @@ module EmailAddress
|
|
230
230
|
return false unless self.local.valid?
|
231
231
|
return false unless self.host.valid?
|
232
232
|
end
|
233
|
-
if
|
234
|
-
|
233
|
+
if @config[:address_validation] == :smtp
|
234
|
+
|
235
235
|
end
|
236
236
|
true
|
237
237
|
end
|
238
238
|
|
239
|
-
|
239
|
+
# Connects to host to test if user can receive email. This should NOT be performed
|
240
|
+
# as an email address check, but is provided to assist in problem resolution.
|
241
|
+
# If you abuse this, you *could* be blocked by the ESP.
|
242
|
+
def connect
|
243
|
+
begin
|
244
|
+
smtp = Net::SMTP.new(self.host_name || self.ip_address)
|
245
|
+
smtp.start(@config[:smtp_helo_name] || 'localhost')
|
246
|
+
smtp.mailfrom @config[:smtp_mail_from] || 'postmaster@localhost'
|
247
|
+
smtp.rcptto self.to_s
|
248
|
+
p [:connect]
|
249
|
+
smtp.finish
|
250
|
+
true
|
251
|
+
rescue Net::SMTPUnknownError => e
|
252
|
+
set_error(:address_unknown, e.to_s)
|
253
|
+
rescue Net::SMTPFatalError => e
|
254
|
+
set_error(:address_unknown, e.to_s)
|
255
|
+
rescue SocketError => e
|
256
|
+
set_error(:address_unknown, e.to_s)
|
257
|
+
ensure
|
258
|
+
if smtp && smtp.started?
|
259
|
+
smtp.finish
|
260
|
+
end
|
261
|
+
!!@error
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def set_error(err, reason=nil)
|
240
266
|
@error = EmailAddress::Config.error_messages.fetch(err) { err }
|
267
|
+
@reason= reason
|
241
268
|
false
|
242
269
|
end
|
243
270
|
|
271
|
+
def error_message
|
272
|
+
@error
|
273
|
+
end
|
274
|
+
|
244
275
|
def error
|
245
276
|
self.valid? ? nil : @error
|
246
277
|
end
|
data/lib/email_address/config.rb
CHANGED
@@ -68,6 +68,9 @@ module EmailAddress
|
|
68
68
|
# * host_allow_ip: false,
|
69
69
|
# Allow IP address format in host: [127.0.0.1], [IPv6:::1]
|
70
70
|
#
|
71
|
+
# * host_local: false,
|
72
|
+
# Allow localhost, no domain, or local subdomains.
|
73
|
+
#
|
71
74
|
# * address_validation: :parts, :smtp, ->(address) { true }
|
72
75
|
# Address validation policy
|
73
76
|
# :parts Validate local and host.
|
@@ -77,8 +80,11 @@ module EmailAddress
|
|
77
80
|
# * address_size: 3..254,
|
78
81
|
# A range specifying the size limit of the complete address
|
79
82
|
#
|
80
|
-
# *
|
81
|
-
#
|
83
|
+
# * address_fqdn_domain: nil || "domain.tld"
|
84
|
+
# Configure to complete the FQDN (Fully Qualified Domain Name)
|
85
|
+
# When host is blank, this value is used
|
86
|
+
# When host is computer name only, a dot and this is appended to get the FQDN
|
87
|
+
# You probably don't want this unless you have host-local email accounts
|
82
88
|
#
|
83
89
|
# For provider rules to match to domain names and Exchanger hosts
|
84
90
|
# The value is an array of match tokens.
|
@@ -104,14 +110,15 @@ module EmailAddress
|
|
104
110
|
mailbox_validator: nil, # nil, Proc
|
105
111
|
|
106
112
|
host_encoding: :punycode || :unicode,
|
107
|
-
host_validation: :mx || :a || :connect,
|
113
|
+
host_validation: :mx || :a || :connect || :syntax,
|
108
114
|
host_size: 1..253,
|
109
115
|
host_allow_ip: false,
|
110
116
|
host_remove_spaces: false,
|
117
|
+
host_local: false,
|
111
118
|
|
112
119
|
address_validation: :parts, # :parts, :smtp, Proc
|
113
120
|
address_size: 3..254,
|
114
|
-
|
121
|
+
address_fqdn_domain: nil, # Fully Qualified Domain Name = [host].[domain.tld]
|
115
122
|
}
|
116
123
|
|
117
124
|
@providers = {
|
data/lib/email_address/host.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'simpleidn'
|
2
2
|
require 'resolv'
|
3
3
|
require 'netaddr'
|
4
|
+
require 'net/smtp'
|
4
5
|
|
5
6
|
module EmailAddress
|
6
7
|
##############################################################################
|
@@ -33,7 +34,7 @@ module EmailAddress
|
|
33
34
|
attr_reader :host_name
|
34
35
|
attr_accessor :dns_name, :domain_name, :registration_name,
|
35
36
|
:tld, :tld2, :subdomains, :ip_address, :config, :provider,
|
36
|
-
:comment, :error_message
|
37
|
+
:comment, :error_message, :reason
|
37
38
|
MAX_HOST_LENGTH = 255
|
38
39
|
|
39
40
|
# Sometimes, you just need a Regexp...
|
@@ -143,7 +144,8 @@ module EmailAddress
|
|
143
144
|
end
|
144
145
|
|
145
146
|
def host_name=(name)
|
146
|
-
|
147
|
+
name = fully_qualified_domain_name(name.downcase)
|
148
|
+
@host_name = name
|
147
149
|
if @config[:host_remove_spaces]
|
148
150
|
@host_name = @host_name.gsub(' ', '')
|
149
151
|
end
|
@@ -179,6 +181,23 @@ module EmailAddress
|
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
184
|
+
def fully_qualified_domain_name(host_part)
|
185
|
+
dn = @config[:address_fqdn_domain]
|
186
|
+
if !dn
|
187
|
+
if (host_part.nil? || host_part <= " ") && @config[:host_local]
|
188
|
+
'localhost'
|
189
|
+
else
|
190
|
+
host_part
|
191
|
+
end
|
192
|
+
elsif host_part.nil? || host_part <= " "
|
193
|
+
dn
|
194
|
+
elsif !host_part.include?(".")
|
195
|
+
host_part + "." + dn
|
196
|
+
else
|
197
|
+
host_part
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
182
201
|
# True if host is hosted at the provider, not a public provider host name
|
183
202
|
def hosted_service?
|
184
203
|
return false unless registration_name
|
@@ -310,7 +329,7 @@ module EmailAddress
|
|
310
329
|
|
311
330
|
# True if the :dns_lookup setting is enabled
|
312
331
|
def dns_enabled?
|
313
|
-
EmailAddress::Config.setting(:
|
332
|
+
[:mx, :a].include?(EmailAddress::Config.setting(:host_validation))
|
314
333
|
end
|
315
334
|
|
316
335
|
# Returns: [official_hostname, alias_hostnames, address_family, *address_list]
|
@@ -360,20 +379,22 @@ module EmailAddress
|
|
360
379
|
############################################################################
|
361
380
|
|
362
381
|
# Returns true if the host name is valid according to the current configuration
|
363
|
-
def valid?(
|
382
|
+
def valid?(rules={})
|
383
|
+
host_validation = rules[:host_validation] || @config[:host_validation] || :mx
|
384
|
+
dns_lookup = rules[:dns_lookup] || host_validation
|
364
385
|
self.error_message = nil
|
365
386
|
if self.ip_address
|
366
387
|
valid_ip?
|
367
388
|
elsif ! valid_format?
|
368
389
|
false
|
369
|
-
elsif
|
390
|
+
elsif dns_lookup == :connect
|
391
|
+
valid_mx? && connect
|
392
|
+
elsif dns_lookup == :mx
|
370
393
|
valid_mx?
|
371
|
-
elsif
|
394
|
+
elsif dns_lookup == :a
|
372
395
|
valid_dns?
|
373
|
-
elsif rule == :off
|
374
|
-
true
|
375
396
|
else
|
376
|
-
|
397
|
+
true
|
377
398
|
end
|
378
399
|
end
|
379
400
|
|
@@ -384,13 +405,21 @@ module EmailAddress
|
|
384
405
|
|
385
406
|
# True if the host name has a DNS A Record
|
386
407
|
def valid_dns?
|
387
|
-
dns_a_record.size > 0 || set_error(:domain_unknown)
|
408
|
+
bool = dns_a_record.size > 0 || set_error(:domain_unknown)
|
409
|
+
if self.localhost? && !@config[:host_local]
|
410
|
+
bool = set_error(:domain_no_localhost)
|
411
|
+
end
|
412
|
+
bool
|
388
413
|
end
|
389
414
|
|
390
415
|
# True if the host name has valid MX servers configured in DNS
|
391
416
|
def valid_mx?
|
392
417
|
if self.exchangers.mx_ips.size > 0
|
393
|
-
|
418
|
+
if self.localhost? && !@config[:host_local]
|
419
|
+
set_error(:domain_no_localhost)
|
420
|
+
else
|
421
|
+
true
|
422
|
+
end
|
394
423
|
elsif valid_dns?
|
395
424
|
set_error(:domain_does_not_accept_email)
|
396
425
|
else
|
@@ -412,16 +441,53 @@ module EmailAddress
|
|
412
441
|
# is reachable.
|
413
442
|
def valid_ip?
|
414
443
|
if ! @config[:host_allow_ip]
|
415
|
-
set_error(:ip_address_forbidden)
|
444
|
+
bool = set_error(:ip_address_forbidden)
|
416
445
|
elsif self.ip_address.include?(":")
|
417
|
-
self.ip_address =~ Resolv::IPv6::Regex ? true : set_error(:ipv6_address_invalid)
|
446
|
+
bool = self.ip_address =~ Resolv::IPv6::Regex ? true : set_error(:ipv6_address_invalid)
|
418
447
|
elsif self.ip_address.include?(".")
|
419
|
-
self.ip_address =~ Resolv::IPv4::Regex ? true : set_error(:ipv4_address_invalid)
|
448
|
+
bool = self.ip_address =~ Resolv::IPv4::Regex ? true : set_error(:ipv4_address_invalid)
|
449
|
+
end
|
450
|
+
if bool && (localhost? && !@config[:host_local])
|
451
|
+
bool = set_error(:ip_address_no_localhost)
|
452
|
+
end
|
453
|
+
bool
|
454
|
+
end
|
455
|
+
|
456
|
+
def localhost?
|
457
|
+
if self.ip_address
|
458
|
+
if self.ip_address.include?(":")
|
459
|
+
return NetAddr::CIDR.create("::1").matches?(self.ip_address)
|
460
|
+
else
|
461
|
+
return NetAddr::CIDR.create("127.0.0.0/8").matches?(self.ip_address)
|
462
|
+
end
|
463
|
+
else
|
464
|
+
self.host_name == 'localhost'
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
# Connects to host to test it can receive email. This should NOT be performed
|
469
|
+
# as an email address check, but is provided to assist in problem resolution.
|
470
|
+
# If you abuse this, you *could* be blocked by the ESP.
|
471
|
+
def connect
|
472
|
+
begin
|
473
|
+
smtp = Net::SMTP.new(self.host_name || self.ip_address)
|
474
|
+
smtp.start(@config[:helo_name] || 'localhost')
|
475
|
+
smtp.finish
|
476
|
+
true
|
477
|
+
rescue Net::SMTPFatalError => e
|
478
|
+
set_error(:server_not_available, e.to_s)
|
479
|
+
rescue SocketError => e
|
480
|
+
set_error(:server_not_available, e.to_s)
|
481
|
+
ensure
|
482
|
+
if smtp && smtp.started?
|
483
|
+
smtp.finish
|
484
|
+
end
|
420
485
|
end
|
421
486
|
end
|
422
487
|
|
423
|
-
def set_error(err)
|
488
|
+
def set_error(err, reason=nil)
|
424
489
|
@error_message = EmailAddress::Config.error_messages.fetch(err) { err }
|
490
|
+
@reason = reason
|
425
491
|
false
|
426
492
|
end
|
427
493
|
|
@@ -66,15 +66,19 @@ class TestAddress < Minitest::Test
|
|
66
66
|
|
67
67
|
# VALIDATION
|
68
68
|
def test_valid
|
69
|
-
assert EmailAddress.valid?("User+tag@example.com",
|
70
|
-
assert ! EmailAddress.valid?("User%tag@example.com",
|
71
|
-
assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode,
|
69
|
+
assert EmailAddress.valid?("User+tag@example.com", host_validation: :a), "valid 1"
|
70
|
+
assert ! EmailAddress.valid?("User%tag@example.com", host_validation: :a), "valid 2"
|
71
|
+
assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode, host_validation: :syntax ), "valid unicode"
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
75
|
-
e = EmailAddress.new("User+tag.gmail.ws")
|
74
|
+
def test_localhost
|
75
|
+
e = EmailAddress.new("User+tag.gmail.ws") # No domain means localhost
|
76
76
|
assert_equal '', e.hostname
|
77
77
|
assert_equal false, e.valid? # localhost not allowed by default
|
78
|
+
assert_equal EmailAddress.error("user1"), :domain_invalid
|
79
|
+
assert_equal EmailAddress.error("user1", host_local:true), :domain_does_not_accept_email
|
80
|
+
assert_equal EmailAddress.error("user1@localhost", host_local:true), :domain_does_not_accept_email
|
81
|
+
assert_equal EmailAddress.error("user2@localhost", host_local:true, dns_lookup: :off, host_validation: :syntax), nil
|
78
82
|
end
|
79
83
|
|
80
84
|
def test_regexen
|
@@ -16,10 +16,10 @@ class TestHost < MiniTest::Test
|
|
16
16
|
def test_dns_enabled
|
17
17
|
a = EmailAddress::Host.new("example.com")
|
18
18
|
assert_instance_of TrueClass, a.dns_enabled?
|
19
|
-
old_setting = EmailAddress::Config.setting(:
|
20
|
-
EmailAddress::Config.configure(
|
19
|
+
old_setting = EmailAddress::Config.setting(:host_validation)
|
20
|
+
EmailAddress::Config.configure(host_validation: :off)
|
21
21
|
assert_instance_of FalseClass, a.dns_enabled?
|
22
|
-
EmailAddress::Config.configure(
|
22
|
+
EmailAddress::Config.configure(host_validation: old_setting)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_foreign_host
|
@@ -59,13 +59,13 @@ class TestHost < MiniTest::Test
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_ipv4
|
62
|
-
h = EmailAddress::Host.new("[127.0.0.1]", host_allow_ip:true)
|
62
|
+
h = EmailAddress::Host.new("[127.0.0.1]", host_allow_ip:true, host_local:true)
|
63
63
|
assert_equal "127.0.0.1", h.ip_address
|
64
64
|
assert_equal true, h.valid?
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_ipv6
|
68
|
-
h = EmailAddress::Host.new("[IPv6:::1]", host_allow_ip:true)
|
68
|
+
h = EmailAddress::Host.new("[IPv6:::1]", host_allow_ip:true, host_local:true)
|
69
69
|
assert_equal "::1", h.ip_address
|
70
70
|
assert_equal true, h.valid?
|
71
71
|
end
|
@@ -116,8 +116,8 @@ class TestHost < MiniTest::Test
|
|
116
116
|
assert_equal EmailAddress::Host.new("yahoo.com").error, nil
|
117
117
|
assert_equal EmailAddress::Host.new("example.com").error, :domain_does_not_accept_email
|
118
118
|
assert_equal EmailAddress::Host.new("yahoo.wtf").error, :domain_unknown
|
119
|
-
assert_equal EmailAddress::Host.new("ajsdfhajshdfklasjhd.wtf",
|
120
|
-
assert_equal EmailAddress::Host.new("ya hoo.com",
|
119
|
+
assert_equal EmailAddress::Host.new("ajsdfhajshdfklasjhd.wtf", host_validation: :syntax).error, nil
|
120
|
+
assert_equal EmailAddress::Host.new("ya hoo.com", host_validation: :syntax).error, :domain_invalid
|
121
121
|
assert_equal EmailAddress::Host.new("[127.0.0.1]").error, :ip_address_forbidden
|
122
122
|
assert_equal EmailAddress::Host.new("[127.0.0.666]", host_allow_ip:true).error, :ipv4_address_invalid
|
123
123
|
assert_equal EmailAddress::Host.new("[IPv6::12t]", host_allow_ip:true).error, :ipv6_address_invalid
|
data/test/test_email_address.rb
CHANGED
@@ -39,7 +39,7 @@ class TestEmailAddress < MiniTest::Test
|
|
39
39
|
def test_cases
|
40
40
|
%w( miles.o'brien@yahoo.com first.last@gmail.com a-b.c_d+e@f.gx
|
41
41
|
).each do |address|
|
42
|
-
assert EmailAddress.valid?(address,
|
42
|
+
assert EmailAddress.valid?(address, host_validation: :syntax), "valid?(#{address})"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
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.7
|
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: 2018-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
177
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.6.
|
178
|
+
rubygems_version: 2.6.13
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: This gem provides a ruby language library for working with and validating
|