email_address 0.1.14 → 0.1.19
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/.travis.yml +1 -2
- data/README.md +38 -4
- data/email_address.gemspec +1 -0
- data/lib/email_address.rb +17 -18
- data/lib/email_address/active_record_validator.rb +5 -4
- data/lib/email_address/address.rb +16 -17
- data/lib/email_address/canonical_email_address_type.rb +14 -12
- data/lib/email_address/config.rb +22 -2
- data/lib/email_address/email_address_type.rb +15 -13
- data/lib/email_address/exchanger.rb +3 -3
- data/lib/email_address/host.rb +16 -18
- data/lib/email_address/local.rb +7 -7
- data/lib/email_address/version.rb +1 -1
- data/test/email_address/test_address.rb +5 -0
- data/test/test_aliasing.rb +54 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adfafdd9c68cbc88c13f77175ab945fce253b0c67d93cbf92f27d95358d9286d
|
4
|
+
data.tar.gz: 07ea20d4fddbc9a2626a870b40162fe5ecaedfd7f588ba56f8d9efffce9a4eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45005aaae90329115140e038aa9f17325d66a939de376a2efc0fdda6542a1b47850ae40b80503fd69e1308f3cfe2fb5392904d2ca5ba0f997b00b6712e01ccb9
|
7
|
+
data.tar.gz: e69900c156e676aac54f5f2d3ca395f08f08d07f768913df990d8b3c012e12e5cda678145f1dcdb0d141691ebf93d2beb85ba3b8dd654522fbb121962529585c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -50,7 +50,7 @@ It does not check:
|
|
50
50
|
By default, MX records are required in DNS. MX or "mail exchanger" records
|
51
51
|
tell where to deliver email for the domain. Many domains run their
|
52
52
|
website on one provider (ISP, Heroku, etc.), and email on a different
|
53
|
-
provider (such as
|
53
|
+
provider (such as G Suite). Note that `example.com`, while
|
54
54
|
a valid domain name, does not have MX records.
|
55
55
|
|
56
56
|
```ruby
|
@@ -248,6 +248,16 @@ EmailAddress.normal("HIRO@こんにちは世界.com")
|
|
248
248
|
EmailAddress.normal("hiro@xn--28j2a3ar1pp75ovm7c.com", host_encoding: :unicode)
|
249
249
|
#=> "hiro@こんにちは世界.com"
|
250
250
|
```
|
251
|
+
As of release 0.1.17, exchanger_match is no longer used for host provider
|
252
|
+
determination, which designated the set of rules for that domain.
|
253
|
+
Sometimes, as in Google-hosted domains, the address
|
254
|
+
rules are different, notably the optional dots in mailboxes for gmail.com
|
255
|
+
accounts do not apply to other private domains hosted at google.
|
256
|
+
|
257
|
+
To access the provider service, you can now call:
|
258
|
+
|
259
|
+
EmailAddress.new("user@hosteddomain.com").host.hosted_provider
|
260
|
+
|
251
261
|
|
252
262
|
#### Rails Validator
|
253
263
|
|
@@ -534,14 +544,38 @@ For the mailbox (AKA account, role), without the tag
|
|
534
544
|
* address_size: 3..254,
|
535
545
|
A range specifying the size limit of the complete address
|
536
546
|
|
537
|
-
* address_local: false,
|
538
|
-
Allow localhost, no domain, or local subdomains.
|
539
|
-
|
540
547
|
For provider rules to match to domain names and Exchanger hosts
|
541
548
|
The value is an array of match tokens.
|
542
549
|
* host_match: %w(.org example.com hotmail. user*@ sub.*.com)
|
543
550
|
* exchanger_match: %w(google.com 127.0.0.1 10.9.8.0/24 ::1/64)
|
544
551
|
|
552
|
+
### Namespace conflict resolution
|
553
|
+
|
554
|
+
If your application already uses the `EmailAddress` class name,
|
555
|
+
it's possible to create an alias prior to loading your code:
|
556
|
+
|
557
|
+
For a Rails application, you can do this in `config/application.rb`
|
558
|
+
after the `Bundler.require` line, usually:
|
559
|
+
|
560
|
+
```ruby
|
561
|
+
Bundler.require(*Rails.groups)
|
562
|
+
```
|
563
|
+
|
564
|
+
Add these lines immediately after that point:
|
565
|
+
|
566
|
+
```ruby
|
567
|
+
EmailAddressValidator = EmailAddress
|
568
|
+
Object.send(:remove_const, :EmailAddress)
|
569
|
+
```
|
570
|
+
|
571
|
+
Then your application loads with your EmailAddress class. You may
|
572
|
+
then use this gem with `EmailAddressValidator` or whatever name you
|
573
|
+
gave it above:
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
EmailAddressValidator.valid?("clark.kent@gmail.com") # => true
|
577
|
+
```
|
578
|
+
|
545
579
|
## Notes
|
546
580
|
|
547
581
|
#### Internationalization
|
data/email_address.gemspec
CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/afair/email_address"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
+
#spec.required_ruby_version = ">= 2.3.0"
|
16
17
|
spec.files = `git ls-files`.split($/)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/lib/email_address.rb
CHANGED
@@ -40,31 +40,30 @@ module EmailAddress
|
|
40
40
|
# secret to use in options[:secret]
|
41
41
|
class << self
|
42
42
|
(%i[valid? error normal redact munge canonical reference base srs] &
|
43
|
-
|
43
|
+
Address.public_instance_methods
|
44
44
|
).each do |proxy_method|
|
45
45
|
define_method(proxy_method) do |*args, &block|
|
46
|
-
|
46
|
+
Address.new(*args).public_send(proxy_method, &block)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
end
|
50
|
-
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
# Creates an instance of this email address.
|
51
|
+
# This is a short-cut to EmailAddress::Address.new
|
52
|
+
def new(email_address, config={})
|
53
|
+
Address.new(email_address, config)
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
def new_redacted(email_address, config={})
|
57
|
+
Address.new(Address.new(email_address, config).redact)
|
58
|
+
end
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
def new_canonical(email_address, config={})
|
61
|
+
Address.new(Address.new(email_address, config).canonical, config)
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
# Does the email address match any of the given rules
|
65
|
+
def matches?(email_address, rules, config={})
|
66
|
+
Address.new(email_address, config).matches?(rules)
|
67
|
+
end
|
69
68
|
end
|
70
69
|
end
|
@@ -35,11 +35,12 @@ module EmailAddress
|
|
35
35
|
|
36
36
|
def validate_email(r,f)
|
37
37
|
return if r[f].nil?
|
38
|
-
e =
|
38
|
+
e = Address.new(r[f])
|
39
39
|
unless e.valid?
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
error_message = @opt[:message] ||
|
41
|
+
Config.error_messages[:invalid_address] ||
|
42
|
+
"Invalid Email Address"
|
43
|
+
r.errors.add(f, error_message)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -5,33 +5,32 @@ require "digest/md5"
|
|
5
5
|
|
6
6
|
module EmailAddress
|
7
7
|
# Implements the Email Address container, which hold the Local
|
8
|
-
# (EmailAddress::Local) and Host (
|
8
|
+
# (EmailAddress::Local) and Host (EmailAddress::Host) parts.
|
9
9
|
class Address
|
10
10
|
include Comparable
|
11
|
-
include
|
11
|
+
include Rewriter
|
12
12
|
|
13
13
|
attr_accessor :original, :local, :host, :config, :reason
|
14
14
|
|
15
|
-
CONVENTIONAL_REGEX = /\A#{
|
16
|
-
@#{
|
17
|
-
STANDARD_REGEX = /\A#{
|
18
|
-
@#{
|
19
|
-
RELAXED_REGEX = /\A#{
|
20
|
-
@#{
|
15
|
+
CONVENTIONAL_REGEX = /\A#{Local::CONVENTIONAL_MAILBOX_WITHIN}
|
16
|
+
@#{Host::DNS_HOST_REGEX}\z/x
|
17
|
+
STANDARD_REGEX = /\A#{Local::STANDARD_LOCAL_WITHIN}
|
18
|
+
@#{Host::DNS_HOST_REGEX}\z/x
|
19
|
+
RELAXED_REGEX = /\A#{Local::RELAXED_MAILBOX_WITHIN}
|
20
|
+
@#{Host::DNS_HOST_REGEX}\z/x
|
21
21
|
|
22
22
|
# Given an email address of the form "local@hostname", this sets up the
|
23
23
|
# instance, and initializes the address to the "normalized" format of the
|
24
24
|
# address. The original string is available in the #original method.
|
25
25
|
def initialize(email_address, config = {})
|
26
|
-
@config = config
|
26
|
+
@config = Config.new(config)
|
27
27
|
@original = email_address
|
28
28
|
email_address = (email_address || "").strip
|
29
29
|
email_address = parse_rewritten(email_address) unless config[:skip_rewrite]
|
30
|
-
local, host =
|
30
|
+
local, host = Address.split_local_host(email_address)
|
31
31
|
|
32
|
-
@host =
|
33
|
-
@
|
34
|
-
@local = EmailAddress::Local.new(local, @config, @host)
|
32
|
+
@host = Host.new(host, @config)
|
33
|
+
@local = Local.new(local, @config, @host)
|
35
34
|
@error = @error_message = nil
|
36
35
|
end
|
37
36
|
|
@@ -115,7 +114,7 @@ module EmailAddress
|
|
115
114
|
alias to_s normal
|
116
115
|
|
117
116
|
def inspect
|
118
|
-
"
|
117
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} address=\"#{self}\">"
|
119
118
|
end
|
120
119
|
|
121
120
|
# Returns the canonical email address according to the provider
|
@@ -191,7 +190,7 @@ module EmailAddress
|
|
191
190
|
# of this addres with another, using the canonical or redacted forms.
|
192
191
|
def same_as?(other_email)
|
193
192
|
if other_email.is_a?(String)
|
194
|
-
other_email =
|
193
|
+
other_email = Address.new(other_email)
|
195
194
|
end
|
196
195
|
|
197
196
|
canonical == other_email.canonical ||
|
@@ -215,7 +214,7 @@ module EmailAddress
|
|
215
214
|
|
216
215
|
# Does "root@*.com" match "root@example.com" domain name
|
217
216
|
rules.each do |r|
|
218
|
-
if
|
217
|
+
if r.match(/.+@.+/)
|
219
218
|
return r if File.fnmatch?(r, to_s)
|
220
219
|
end
|
221
220
|
end
|
@@ -277,7 +276,7 @@ module EmailAddress
|
|
277
276
|
def set_error(err, reason = nil)
|
278
277
|
@error = err
|
279
278
|
@reason = reason
|
280
|
-
@error_message =
|
279
|
+
@error_message = Config.error_message(err)
|
281
280
|
false
|
282
281
|
end
|
283
282
|
|
@@ -29,20 +29,22 @@
|
|
29
29
|
# user.canonical_email #=> "patsmith@gmail.com"
|
30
30
|
################################################################################
|
31
31
|
|
32
|
-
|
32
|
+
module EmailAddress
|
33
|
+
class CanonicalEmailAddressType < ActiveRecord::Type::Value
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# From user input, setter
|
36
|
+
def cast(value)
|
37
|
+
super(Address.new(value).canonical)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
# From a database value
|
41
|
+
def deserialize(value)
|
42
|
+
value && Address.new(value).normal
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
# To a database value (string)
|
46
|
+
def serialize(value)
|
47
|
+
value && Address.new(value).normal
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
data/lib/email_address/config.rb
CHANGED
@@ -143,6 +143,7 @@ module EmailAddress
|
|
143
143
|
},
|
144
144
|
msn: {
|
145
145
|
host_match: %w[msn. hotmail. outlook. live.],
|
146
|
+
exchanger_match: %w[outlook.com],
|
146
147
|
mailbox_validator: ->(m, t) { m =~ /\A\w[\-\w]*(?:\.[\-\w]+)*\z/i }
|
147
148
|
},
|
148
149
|
yahoo: {
|
@@ -175,8 +176,7 @@ module EmailAddress
|
|
175
176
|
def self.provider(name, config = {})
|
176
177
|
name = name.to_sym
|
177
178
|
if config.size > 0
|
178
|
-
@providers[name]
|
179
|
-
@providers[name].merge!(config)
|
179
|
+
@providers[name.to_sym] = config
|
180
180
|
end
|
181
181
|
@providers[name]
|
182
182
|
end
|
@@ -199,5 +199,25 @@ module EmailAddress
|
|
199
199
|
configs.each { |c| config.merge!(c) }
|
200
200
|
config
|
201
201
|
end
|
202
|
+
|
203
|
+
def initialize(overrides = {})
|
204
|
+
@config = Config.all_settings(overrides)
|
205
|
+
end
|
206
|
+
|
207
|
+
def []=(setting, value)
|
208
|
+
@config[setting.to_sym] = value
|
209
|
+
end
|
210
|
+
|
211
|
+
def [](setting)
|
212
|
+
@config[setting.to_sym]
|
213
|
+
end
|
214
|
+
|
215
|
+
def configure(settings)
|
216
|
+
@config = @config.merge(settings)
|
217
|
+
end
|
218
|
+
|
219
|
+
def to_h
|
220
|
+
@config
|
221
|
+
end
|
202
222
|
end
|
203
223
|
end
|
@@ -29,20 +29,22 @@
|
|
29
29
|
# user.canonical_email #=> "patsmith@gmail.com"
|
30
30
|
################################################################################
|
31
31
|
|
32
|
-
|
32
|
+
module EmailAddress
|
33
|
+
class EmailAddressType < ActiveRecord::Type::Value
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# From user input, setter
|
36
|
+
def cast(value)
|
37
|
+
super(Address.new(value).normal)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# From a database value
|
41
|
+
def deserialize(value)
|
42
|
+
value && Address.new(value).normal
|
43
|
+
end
|
44
|
+
|
45
|
+
# To a database value (string)
|
46
|
+
def serialize(value)
|
47
|
+
value && Address.new(value).normal
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
@@ -24,7 +24,7 @@ module EmailAddress
|
|
24
24
|
|
25
25
|
def initialize(host, config = {})
|
26
26
|
@host = host
|
27
|
-
@config = config
|
27
|
+
@config = config.is_a?(Hash) ? Config.new(config) : config
|
28
28
|
@dns_disabled = @config[:host_validation] == :syntax || @config[:dns_lookup] == :off
|
29
29
|
end
|
30
30
|
|
@@ -38,7 +38,7 @@ module EmailAddress
|
|
38
38
|
# Returns the provider name based on the MX-er host names, or nil if not matched
|
39
39
|
def provider
|
40
40
|
return @provider if defined? @provider
|
41
|
-
|
41
|
+
Config.providers.each do |provider, config|
|
42
42
|
if config[:exchanger_match] && matches?(config[:exchanger_match])
|
43
43
|
return @provider = provider
|
44
44
|
end
|
@@ -76,7 +76,7 @@ module EmailAddress
|
|
76
76
|
|
77
77
|
# Returns Array of domain names for the MX'ers, used to determine the Provider
|
78
78
|
def domains
|
79
|
-
@_domains ||= mxers.map { |m|
|
79
|
+
@_domains ||= mxers.map { |m| Host.new(m.first).domain_name }.sort.uniq
|
80
80
|
end
|
81
81
|
|
82
82
|
# Returns an array of MX IP address (String) for the given email domain
|
data/lib/email_address/host.rb
CHANGED
@@ -87,7 +87,7 @@ module EmailAddress
|
|
87
87
|
def initialize(host_name, config = {})
|
88
88
|
@original = host_name ||= ""
|
89
89
|
config[:host_type] ||= :email
|
90
|
-
@config = config
|
90
|
+
@config = config.is_a?(Hash) ? Config.new(config) : config
|
91
91
|
@error = @error_message = nil
|
92
92
|
parse(host_name)
|
93
93
|
end
|
@@ -149,7 +149,7 @@ module EmailAddress
|
|
149
149
|
if @config[:host_remove_spaces]
|
150
150
|
@host_name = @host_name.delete(" ")
|
151
151
|
end
|
152
|
-
@dns_name = if /[^[:ascii:]]/.match
|
152
|
+
@dns_name = if /[^[:ascii:]]/.match(host_name)
|
153
153
|
::SimpleIDN.to_ascii(host_name)
|
154
154
|
else
|
155
155
|
host_name
|
@@ -209,7 +209,7 @@ module EmailAddress
|
|
209
209
|
def find_provider # :nodoc:
|
210
210
|
return provider if provider
|
211
211
|
|
212
|
-
|
212
|
+
Config.providers.each do |provider, config|
|
213
213
|
if config[:host_match] && matches?(config[:host_match])
|
214
214
|
return set_provider(provider, config)
|
215
215
|
end
|
@@ -217,25 +217,23 @@ module EmailAddress
|
|
217
217
|
|
218
218
|
return set_provider(:default) unless dns_enabled?
|
219
219
|
|
220
|
-
provider = exchangers.provider
|
221
|
-
if provider != :default
|
222
|
-
set_provider(provider,
|
223
|
-
EmailAddress::Config.provider(provider))
|
224
|
-
end
|
225
|
-
|
226
220
|
self.provider ||= set_provider(:default)
|
227
221
|
end
|
228
222
|
|
229
223
|
def set_provider(name, provider_config = {}) # :nodoc:
|
230
|
-
|
231
|
-
|
224
|
+
config.configure(provider_config)
|
225
|
+
@provider = name
|
232
226
|
end
|
233
227
|
|
234
228
|
# Returns a hash of the parts of the host name after parsing.
|
235
229
|
def parts
|
236
230
|
{host_name: host_name, dns_name: dns_name, subdomain: subdomains,
|
237
231
|
registration_name: registration_name, domain_name: domain_name,
|
238
|
-
tld2: tld2, tld: tld, ip_address: ip_address}
|
232
|
+
tld2: tld2, tld: tld, ip_address: ip_address,}
|
233
|
+
end
|
234
|
+
|
235
|
+
def hosted_provider
|
236
|
+
Exchanger.cached(dns_name).provider
|
239
237
|
end
|
240
238
|
|
241
239
|
############################################################################
|
@@ -286,7 +284,7 @@ module EmailAddress
|
|
286
284
|
|
287
285
|
# Does "example." match any tld?
|
288
286
|
def registration_name_matches?(rule)
|
289
|
-
"#{registration_name}."
|
287
|
+
rule == "#{registration_name}."
|
290
288
|
end
|
291
289
|
|
292
290
|
# Does "sub.example.com" match ".com" and ".example.com" top level names?
|
@@ -340,11 +338,11 @@ module EmailAddress
|
|
340
338
|
@_dns_a_record ||= []
|
341
339
|
end
|
342
340
|
|
343
|
-
# Returns an array of
|
341
|
+
# Returns an array of Exchanger hosts configured in DNS.
|
344
342
|
# The array will be empty if none are configured.
|
345
343
|
def exchangers
|
346
344
|
# return nil if @config[:host_type] != :email || !self.dns_enabled?
|
347
|
-
@_exchangers ||=
|
345
|
+
@_exchangers ||= Exchanger.cached(dns_name, @config)
|
348
346
|
end
|
349
347
|
|
350
348
|
# Returns a DNS TXT Record
|
@@ -450,9 +448,9 @@ module EmailAddress
|
|
450
448
|
if !@config[:host_allow_ip]
|
451
449
|
bool = set_error(:ip_address_forbidden)
|
452
450
|
elsif ip_address.include?(":")
|
453
|
-
bool = Resolv::IPv6::Regex
|
451
|
+
bool = ip_address.match(Resolv::IPv6::Regex) ? true : set_error(:ipv6_address_invalid)
|
454
452
|
elsif ip_address.include?(".")
|
455
|
-
bool = Resolv::IPv4::Regex
|
453
|
+
bool = ip_address.match(Resolv::IPv4::Regex) ? true : set_error(:ipv4_address_invalid)
|
456
454
|
end
|
457
455
|
if bool && (localhost? && !@config[:host_local])
|
458
456
|
bool = set_error(:ip_address_no_localhost)
|
@@ -499,7 +497,7 @@ module EmailAddress
|
|
499
497
|
def set_error(err, reason = nil)
|
500
498
|
@error = err
|
501
499
|
@reason = reason
|
502
|
-
@error_message =
|
500
|
+
@error_message = Config.error_message(err)
|
503
501
|
false
|
504
502
|
end
|
505
503
|
|
data/lib/email_address/local.rb
CHANGED
@@ -107,7 +107,7 @@ module EmailAddress
|
|
107
107
|
%r/^([\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+)$/i.freeze
|
108
108
|
|
109
109
|
def initialize(local, config={}, host=nil)
|
110
|
-
|
110
|
+
@config = config.is_a?(Hash) ? Config.new(config) : config
|
111
111
|
self.local = local
|
112
112
|
@host = host
|
113
113
|
@error = @error_message = nil
|
@@ -130,10 +130,10 @@ module EmailAddress
|
|
130
130
|
def parse(raw)
|
131
131
|
if raw =~ /\A\"(.*)\"\z/ # Quoted
|
132
132
|
raw = $1
|
133
|
-
raw.gsub
|
133
|
+
raw = raw.gsub(/\\(.)/, '\1') # Unescape
|
134
134
|
elsif @config[:local_fix] && @config[:local_format] != :standard
|
135
|
-
raw.gsub
|
136
|
-
raw.gsub
|
135
|
+
raw = raw.gsub(' ','')
|
136
|
+
raw = raw.gsub(',','.')
|
137
137
|
#raw.gsub!(/([^\p{L}\p{N}]{2,10})/) {|s| s[0] } # Stutter punctuation typo
|
138
138
|
end
|
139
139
|
raw, comment = self.parse_comment(raw)
|
@@ -226,7 +226,7 @@ module EmailAddress
|
|
226
226
|
def relax
|
227
227
|
form = self.mailbox
|
228
228
|
form += @config[:tag_separator] + self.tag if self.tag
|
229
|
-
form.gsub
|
229
|
+
form = form.gsub(/[ \"\(\),:<>@\[\]\\]/,'')
|
230
230
|
form
|
231
231
|
end
|
232
232
|
|
@@ -235,7 +235,7 @@ module EmailAddress
|
|
235
235
|
form = self.mailbox
|
236
236
|
form += @config[:tag_separator] + self.tag if self.tag
|
237
237
|
form += "(" + self.comment + ")" if self.comment
|
238
|
-
form.gsub
|
238
|
+
form = form.gsub(/([\\\"])/, '\\\1') # Escape \ and "
|
239
239
|
if form =~ /[ \"\(\),:<>@\[\\\]]/ # Space and "(),:;<>@[\]
|
240
240
|
form = %Q("#{form}")
|
241
241
|
end
|
@@ -388,7 +388,7 @@ module EmailAddress
|
|
388
388
|
def set_error(err, reason=nil)
|
389
389
|
@error = err
|
390
390
|
@reason= reason
|
391
|
-
@error_message =
|
391
|
+
@error_message = Config.error_message(err)
|
392
392
|
false
|
393
393
|
end
|
394
394
|
|
@@ -37,6 +37,11 @@ class TestAddress < Minitest::Test
|
|
37
37
|
assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_google_hosted
|
41
|
+
a = EmailAddress.new("Ex.am.ple+tag@boomer.com")
|
42
|
+
assert_equal a.canonical, "ex.am.ple@boomer.com"
|
43
|
+
end
|
44
|
+
|
40
45
|
# COMPARISON & MATCHING
|
41
46
|
def test_compare
|
42
47
|
a = ("User+tag@example.com")
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'test_helper'
|
3
|
+
|
4
|
+
class TestAliasing < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
Object.send(:const_set, :EmailAddressValidator, EmailAddress)
|
7
|
+
Object.send(:remove_const, :EmailAddress)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_email_address_not_defined
|
11
|
+
assert_nil defined?(EmailAddress)
|
12
|
+
assert_nil defined?(EmailAddress::Address)
|
13
|
+
assert_nil defined?(EmailAddress::Config)
|
14
|
+
assert_nil defined?(EmailAddress::Exchanger)
|
15
|
+
assert_nil defined?(EmailAddress::Host)
|
16
|
+
assert_nil defined?(EmailAddress::Local)
|
17
|
+
assert_nil defined?(EmailAddress::Rewriter)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_alias_defined
|
21
|
+
assert_equal defined?(EmailAddressValidator), "constant"
|
22
|
+
assert_equal defined?(EmailAddressValidator::Address), "constant"
|
23
|
+
assert_equal defined?(EmailAddressValidator::Config), "constant"
|
24
|
+
assert_equal defined?(EmailAddressValidator::Exchanger), "constant"
|
25
|
+
assert_equal defined?(EmailAddressValidator::Host), "constant"
|
26
|
+
assert_equal defined?(EmailAddressValidator::Local), "constant"
|
27
|
+
assert_equal defined?(EmailAddressValidator::Rewriter), "constant"
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_alias_class_methods
|
31
|
+
assert_equal true, EmailAddressValidator.valid?("user@yahoo.com")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_alias_host_methods
|
35
|
+
assert_equal true, EmailAddressValidator::Host.new("yahoo.com").valid?
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_alias_address_methods
|
39
|
+
assert_equal true, EmailAddressValidator::Address.new("user@yahoo.com").valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_alias_config_methods
|
43
|
+
assert Hash, EmailAddressValidator::Config.new.to_h
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_alias_local_methods
|
47
|
+
assert_equal true, EmailAddressValidator::Local.new("user").valid?
|
48
|
+
end
|
49
|
+
|
50
|
+
def teardown
|
51
|
+
Object.send(:const_set, :EmailAddress, EmailAddressValidator)
|
52
|
+
Object.send(:remove_const, :EmailAddressValidator)
|
53
|
+
end
|
54
|
+
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Fair
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -162,13 +162,14 @@ files:
|
|
162
162
|
- test/email_address/test_host.rb
|
163
163
|
- test/email_address/test_local.rb
|
164
164
|
- test/email_address/test_rewriter.rb
|
165
|
+
- test/test_aliasing.rb
|
165
166
|
- test/test_email_address.rb
|
166
167
|
- test/test_helper.rb
|
167
168
|
homepage: https://github.com/afair/email_address
|
168
169
|
licenses:
|
169
170
|
- MIT
|
170
171
|
metadata: {}
|
171
|
-
post_install_message:
|
172
|
+
post_install_message:
|
172
173
|
rdoc_options: []
|
173
174
|
require_paths:
|
174
175
|
- lib
|
@@ -183,8 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
184
|
- !ruby/object:Gem::Version
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
|
-
rubygems_version: 3.
|
187
|
-
signing_key:
|
187
|
+
rubygems_version: 3.1.4
|
188
|
+
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: This gem provides a ruby language library for working with and validating
|
190
191
|
email addresses. By default, it validates against conventional usage, the format
|
@@ -199,5 +200,6 @@ test_files:
|
|
199
200
|
- test/email_address/test_host.rb
|
200
201
|
- test/email_address/test_local.rb
|
201
202
|
- test/email_address/test_rewriter.rb
|
203
|
+
- test/test_aliasing.rb
|
202
204
|
- test/test_email_address.rb
|
203
205
|
- test/test_helper.rb
|