email_address 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +35 -0
- data/email_address.gemspec +1 -1
- data/lib/email_address/host.rb +11 -6
- data/lib/email_address/local.rb +3 -3
- data/lib/email_address/version.rb +1 -1
- data/test/email_address/test_address.rb +6 -0
- data/test/email_address/test_host.rb +8 -0
- data/test/email_address/test_local.rb +1 -0
- data/test/test_email_address.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86863c7db99499852dc1d4176ecef8a8a372124c
|
4
|
+
data.tar.gz: e646a1808a0ca57048be6bcdb945c3621cfd053c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c31c52963534e41a74cb87ead583be88ddaa08e630fd3ebe8540acbf015d50d63418893ac84f540b39067db00ab37d0a0de17a20604a3ae6dd3dafe93c42cf
|
7
|
+
data.tar.gz: d356139bb7776f3dc82449f6b27240dd99ec7fe4ab704d2be0177bce9dc7b8a71924944b0340742eb050a85c4b1aa2b28786f1a13e882f48e818bfa906680472
|
data/README.md
CHANGED
@@ -26,6 +26,41 @@ want to continue using with your current version.
|
|
26
26
|
|
27
27
|
Requires Ruby 2.0 or later.
|
28
28
|
|
29
|
+
## Quick Start
|
30
|
+
|
31
|
+
To quickly validate email addresses, use the valid? and error helpers.
|
32
|
+
`valid?` returns a boolean, and `error` returns nil if valid, otherwise
|
33
|
+
a basic error message.
|
34
|
+
|
35
|
+
EmailAddress.valid? "allen@google.com" #=> true
|
36
|
+
EmailAddress.error "allen@bad-d0main.com" #=> "Invalid Host/Domain Name"
|
37
|
+
|
38
|
+
`EmailAddress` deeply validates your email addresses. It checks:
|
39
|
+
|
40
|
+
* Host name format and DNS setup
|
41
|
+
* Mailbox format according to "conventional" form. This matches most used user
|
42
|
+
email accounts, but is a subset of the RFC specification.
|
43
|
+
|
44
|
+
It does not check:
|
45
|
+
|
46
|
+
* The mail server is configured to accept connections
|
47
|
+
* The mailbox is valid and accepts email.
|
48
|
+
|
49
|
+
By default, MX records are required in DNS. MX or "mail exchanger" records
|
50
|
+
tell where to deliver email for the domain. Many domains run their
|
51
|
+
website on one provider (ISP, Heroku, etc.), and email on a different
|
52
|
+
provider (such as Google Apps). Note that `example.com`, while
|
53
|
+
a valid domain name, does not have MX records.
|
54
|
+
|
55
|
+
EmailAddress.valid? "allen@example.com" #=> false
|
56
|
+
EmailAddress.valid? "allen@example.com", dns_lookup: :off #=> true
|
57
|
+
|
58
|
+
Most mail servers do not yet support Unicode mailboxes, so the default here is ASCII.
|
59
|
+
|
60
|
+
EmailAddress.error "Pelé@google.com" #=> "Invalid Recipient/Mailbox"
|
61
|
+
EmailAddress.valid? "Pelé@google.com", local_encoding: :unicode #=> true
|
62
|
+
|
63
|
+
|
29
64
|
## Background
|
30
65
|
|
31
66
|
The email address specification is complex and often not what you want
|
data/email_address.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "minitest", "~> 5.8.3"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "activerecord", "~> 5.
|
24
|
+
spec.add_development_dependency "activerecord", "~> 5.1.3" if RUBY_PLATFORM != 'java'
|
25
25
|
spec.add_development_dependency "activerecord", "~> 4.2.5" if RUBY_PLATFORM == 'java'
|
26
26
|
spec.add_development_dependency "sqlite3" if RUBY_PLATFORM != 'java'
|
27
27
|
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter" if RUBY_PLATFORM == 'java'
|
data/lib/email_address/host.rb
CHANGED
@@ -144,7 +144,11 @@ module EmailAddress
|
|
144
144
|
|
145
145
|
def host_name=(name)
|
146
146
|
@host_name = name = name.strip.downcase.gsub(' ', '').gsub(/\(.*\)/, '')
|
147
|
-
|
147
|
+
if host_name =~ /[^[:ascii:]]/
|
148
|
+
@dns_name = ::SimpleIDN.to_ascii(self.host_name)
|
149
|
+
else
|
150
|
+
@dns_name = self.host_name
|
151
|
+
end
|
148
152
|
|
149
153
|
# Subdomain only (root@localhost)
|
150
154
|
if name.index('.').nil?
|
@@ -166,6 +170,9 @@ module EmailAddress
|
|
166
170
|
end
|
167
171
|
self.domain_name = self.registration_name + '.' + self.tld2
|
168
172
|
self.find_provider
|
173
|
+
else # Bad format
|
174
|
+
self.subdomains = self.tld = self.tld2 = ""
|
175
|
+
self.domain_name = self.registration_name = name
|
169
176
|
end
|
170
177
|
end
|
171
178
|
|
@@ -356,9 +363,7 @@ module EmailAddress
|
|
356
363
|
|
357
364
|
# Returns true if the host name is valid according to the current configuration
|
358
365
|
def valid?(rule=@config[:dns_lookup]||:mx)
|
359
|
-
if self.
|
360
|
-
true
|
361
|
-
elsif self.ip_address
|
366
|
+
if self.ip_address
|
362
367
|
@config[:host_allow_ip] && self.valid_ip?
|
363
368
|
elsif rule == :mx
|
364
369
|
self.exchangers.mx_ips.size > 0
|
@@ -378,9 +383,9 @@ module EmailAddress
|
|
378
383
|
if self.ip_address.nil?
|
379
384
|
false
|
380
385
|
elsif self.ip_address.include?(":")
|
381
|
-
self.ip_address =~ Resolv::IPv6::Regex
|
386
|
+
self.ip_address =~ Resolv::IPv6::Regex ? true : false
|
382
387
|
elsif self.ip_address.include?(".")
|
383
|
-
self.ip_address =~ Resolv::IPv4::Regex
|
388
|
+
self.ip_address =~ Resolv::IPv4::Regex ? true : false
|
384
389
|
end
|
385
390
|
end
|
386
391
|
|
data/lib/email_address/local.rb
CHANGED
@@ -122,10 +122,10 @@ module EmailAddress
|
|
122
122
|
if raw =~ /\A\"(.*)\"\z/ # Quoted
|
123
123
|
raw = $1
|
124
124
|
raw.gsub!(/\\(.)/, '\1') # Unescape
|
125
|
-
elsif @config[:local_fix]
|
125
|
+
elsif @config[:local_fix] && @config[:local_format] != :standard
|
126
126
|
raw.gsub!(' ','')
|
127
127
|
raw.gsub!(',','.')
|
128
|
-
raw.gsub!(/([^\p{L}\p{N}]{2,10})/) {|s| s[0] } # Stutter punctuation typo
|
128
|
+
#raw.gsub!(/([^\p{L}\p{N}]{2,10})/) {|s| s[0] } # Stutter punctuation typo
|
129
129
|
end
|
130
130
|
raw, comment = self.parse_comment(raw)
|
131
131
|
mailbox, tag = self.parse_tag(raw)
|
@@ -314,7 +314,7 @@ module EmailAddress
|
|
314
314
|
|
315
315
|
def valid_encoding?(enc=@config[:local_encoding]||:ascii)
|
316
316
|
return false if enc == :ascii && self.unicode?
|
317
|
-
return false if enc == :unicode && self.ascii?
|
317
|
+
#return false if enc == :unicode && self.ascii?
|
318
318
|
true
|
319
319
|
end
|
320
320
|
|
@@ -92,4 +92,10 @@ class TestAddress < Minitest::Test
|
|
92
92
|
assert true, EmailAddress.valid?("first_last@hotmail.com") # #8
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_issue9
|
96
|
+
assert ! EmailAddress.valid?('example.user@foo.')
|
97
|
+
assert ! EmailAddress.valid?('ogog@sss.c')
|
98
|
+
assert ! EmailAddress.valid?('example.user@foo.com/')
|
99
|
+
end
|
100
|
+
|
95
101
|
end
|
@@ -101,4 +101,12 @@ class TestHost < MiniTest::Test
|
|
101
101
|
assert EmailAddress.valid?('test@jiff.com', dns_lookup: :mx)
|
102
102
|
assert ! EmailAddress.valid?('test@gmail.com', dns_lookup: :mx)
|
103
103
|
end
|
104
|
+
|
105
|
+
def test_yahoo_bad_tld
|
106
|
+
assert ! EmailAddress.valid?('test@yahoo.badtld')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_bad_formats
|
110
|
+
#assert EmailAddress::Host.new('example.com:w').registration_name
|
111
|
+
end
|
104
112
|
end
|
@@ -48,6 +48,7 @@ class TestLocal < MiniTest::Test
|
|
48
48
|
def test_unicode
|
49
49
|
assert ! EmailAddress::Local.new("üñîçøðé1", local_encoding: :ascii).standard?, "not üñîçøðé1"
|
50
50
|
assert EmailAddress::Local.new("üñîçøðé2", local_encoding: :unicode).standard?, "üñîçøðé2"
|
51
|
+
assert EmailAddress::Local.new("test", local_encoding: :unicode).valid?, "unicode should include ascii"
|
51
52
|
assert ! EmailAddress::Local.new("üñîçøðé3").valid?, "üñîçøðé3 valid"
|
52
53
|
end
|
53
54
|
|
data/test/test_email_address.rb
CHANGED
@@ -37,7 +37,7 @@ class TestEmailAddress < MiniTest::Test
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_cases
|
40
|
-
%w( miles.o'brien@yahoo.com first
|
40
|
+
%w( miles.o'brien@yahoo.com first.last@gmail.com a-b.c_d+e@f.gx
|
41
41
|
).each do |address|
|
42
42
|
assert EmailAddress.valid?(address, dns_lookup: :off), "valid?(#{address})"
|
43
43
|
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.4
|
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-
|
11
|
+
date: 2017-12-03 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.
|
61
|
+
version: 5.1.3
|
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.
|
68
|
+
version: 5.1.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
178
|
+
rubygems_version: 2.6.11
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: This gem provides a ruby language library for working with and validating
|