email_address 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/email_address.gemspec +9 -6
- data/lib/email_address/active_record_validator.rb +6 -1
- data/lib/email_address/host.rb +3 -3
- data/lib/email_address/local.rb +1 -1
- data/lib/email_address/version.rb +1 -1
- data/test/activerecord/test_ar.rb +10 -0
- data/test/activerecord/user.rb +3 -0
- data/test/email_address/test_host.rb +9 -2
- data/test/email_address/test_local.rb +1 -1
- metadata +70 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0acf217d99455d8e47f25dc21b4ff25478234932c8618f3d5fe0fe4629e433
|
4
|
+
data.tar.gz: 5da4449168ec63611c8e510efd010b12995502b3162c67d3222c46cbabbbe6e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1703377fdf988adabaaf4d728db211320a1f33cf0daeeabd68448cf4a4d02b8647fcb9aad636d0aa14250386b8c8d2ede3cb89b42b55ffa2af793b1f788a9a08
|
7
|
+
data.tar.gz: 15d5b84368e692e6ce08db5ad596ec1ef684f87c70a8db4d1a2d69ab977c72ed5b5f80d9945fc6cdf42af3af5581a9f3a55b26c9138370ce228ad663c758f387
|
data/.github/workflows/ci.yml
CHANGED
@@ -5,9 +5,9 @@ jobs:
|
|
5
5
|
runs-on: ubuntu-latest
|
6
6
|
strategy:
|
7
7
|
matrix:
|
8
|
-
ruby-version: [
|
8
|
+
ruby-version: [3.2, 3.3, 3.4]
|
9
9
|
steps:
|
10
|
-
- uses: actions/checkout@
|
10
|
+
- uses: actions/checkout@v3
|
11
11
|
- uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
13
|
ruby-version: ${{ matrix.ruby-version }}
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -241,7 +241,7 @@ email.provider #=> :google
|
|
241
241
|
email.mailbox #=> "clark.kent"
|
242
242
|
email.tag #=> "scoops"
|
243
243
|
|
244
|
-
email.host.
|
244
|
+
email.host.exchangers.first[:ip] #=> "2a00:1450:400b:c02::1a"
|
245
245
|
email.host.txt_hash #=> {:v=>"spf1", :redirect=>"\_spf.google.com"}
|
246
246
|
|
247
247
|
EmailAddress.normal("HIRO@こんにちは世界.com")
|
data/email_address.gemspec
CHANGED
@@ -15,23 +15,26 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.required_ruby_version = ">= 2.5", "< 4"
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
20
|
spec.add_development_dependency "rake"
|
22
21
|
spec.add_development_dependency "minitest", "~> 5.11"
|
23
22
|
spec.add_development_dependency "bundler" # , "~> 1.16.0"
|
24
23
|
if RUBY_PLATFORM == "java"
|
25
|
-
spec.add_development_dependency "activerecord", "~>
|
26
|
-
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~>
|
24
|
+
spec.add_development_dependency "activerecord", "~> 7.2.0"
|
25
|
+
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 70.2"
|
27
26
|
else
|
28
|
-
spec.add_development_dependency "activerecord", "~>
|
29
|
-
spec.add_development_dependency "sqlite3"
|
30
|
-
spec.add_development_dependency "standard"
|
27
|
+
spec.add_development_dependency "activerecord", "~> 8.0.0"
|
28
|
+
spec.add_development_dependency "sqlite3", "~> 2.1"
|
29
|
+
spec.add_development_dependency "standard"
|
31
30
|
end
|
32
31
|
spec.add_development_dependency "net-smtp"
|
33
32
|
spec.add_development_dependency "simplecov"
|
34
33
|
spec.add_development_dependency "pry"
|
34
|
+
spec.add_development_dependency "bigdecimal"
|
35
|
+
spec.add_development_dependency "mutex_m"
|
36
|
+
spec.add_development_dependency "irb"
|
35
37
|
|
38
|
+
spec.add_dependency "base64"
|
36
39
|
spec.add_dependency "simpleidn"
|
37
40
|
end
|
@@ -12,8 +12,12 @@ module EmailAddress
|
|
12
12
|
# * field: email,
|
13
13
|
# * fields: [:email1, :email2]
|
14
14
|
#
|
15
|
+
# * code: custom error code (default: :invalid_address)
|
16
|
+
# * message: custom error message (default: "Invalid Email Address")
|
17
|
+
#
|
15
18
|
# Default field: :email or :email_address (first found)
|
16
19
|
#
|
20
|
+
#
|
17
21
|
class ActiveRecordValidator < ActiveModel::Validator
|
18
22
|
def initialize(options = {})
|
19
23
|
@opt = options
|
@@ -35,10 +39,11 @@ module EmailAddress
|
|
35
39
|
return if r[f].nil?
|
36
40
|
e = Address.new(r[f])
|
37
41
|
unless e.valid?
|
42
|
+
error_code = @opt[:code] || :invalid_address
|
38
43
|
error_message = @opt[:message] ||
|
39
44
|
Config.error_message(:invalid_address, I18n.locale.to_s) ||
|
40
45
|
"Invalid Email Address"
|
41
|
-
r.errors.add(f, error_message)
|
46
|
+
r.errors.add(f, error_code, message: error_message)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
data/lib/email_address/host.rb
CHANGED
@@ -381,7 +381,7 @@ module EmailAddress
|
|
381
381
|
# Returns true if the host name is valid according to the current configuration
|
382
382
|
def valid?(rules = {})
|
383
383
|
host_validation = rules[:host_validation] || @config[:host_validation] || :mx
|
384
|
-
dns_lookup = rules[:dns_lookup] || host_validation
|
384
|
+
dns_lookup = rules[:dns_lookup] || @config[:dns_lookup] || host_validation
|
385
385
|
self.error_message = nil
|
386
386
|
if host_name && !host_name.empty? && !@config[:host_size].include?(host_name.size)
|
387
387
|
return set_error(:invalid_host)
|
@@ -392,10 +392,10 @@ module EmailAddress
|
|
392
392
|
false
|
393
393
|
elsif dns_lookup == :connect
|
394
394
|
valid_mx? && connect
|
395
|
+
elsif dns_lookup == :a || host_validation == :a
|
396
|
+
valid_dns?
|
395
397
|
elsif dns_lookup == :mx
|
396
398
|
valid_mx?
|
397
|
-
elsif dns_lookup == :a
|
398
|
-
valid_dns?
|
399
399
|
else
|
400
400
|
true
|
401
401
|
end
|
data/lib/email_address/local.rb
CHANGED
@@ -116,7 +116,7 @@ module EmailAddress
|
|
116
116
|
|
117
117
|
def local=(raw)
|
118
118
|
self.original = raw
|
119
|
-
raw.downcase
|
119
|
+
raw = raw.downcase if @config[:local_downcase].nil? || @config[:local_downcase]
|
120
120
|
@local = raw
|
121
121
|
|
122
122
|
if @config[:local_parse].is_a?(Proc)
|
@@ -9,11 +9,21 @@ class TestAR < MiniTest::Test
|
|
9
9
|
user = User.new(email: "Pat.Jones+ASDF#GMAIL.com")
|
10
10
|
assert_equal false, user.valid?
|
11
11
|
assert user.errors.messages[:email].first
|
12
|
+
|
12
13
|
user = User.new(email: "Pat.Jones+ASDF@GMAIL.com")
|
13
14
|
assert_equal true, user.valid?
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def test_validation_error_message
|
19
|
+
if RUBY_PLATFORM != "java" # jruby
|
20
|
+
user = User.new(alternate_email: "Pat.Jones+ASDF#GMAIL.com")
|
21
|
+
assert_equal false, user.valid?
|
22
|
+
assert user.errors.messages[:alternate_email].first.include?("Check your email")
|
23
|
+
assert_equal :some_error_code, user.errors.details[:alternate_email].first[:error]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
17
27
|
def test_datatype
|
18
28
|
# Disabled JRuby checks... weird CI failures. Hopefully someone can help?
|
19
29
|
if RUBY_PLATFORM != "java" # jruby
|
data/test/activerecord/user.rb
CHANGED
@@ -48,10 +48,13 @@ class User < ApplicationRecord
|
|
48
48
|
if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
|
49
49
|
attribute :email, :email_address
|
50
50
|
attribute :canonical_email, :canonical_email_address
|
51
|
+
attribute :alternate_email, :email_address
|
51
52
|
end
|
52
53
|
|
53
54
|
validates_with EmailAddress::ActiveRecordValidator,
|
54
55
|
fields: %i[email canonical_email]
|
56
|
+
validates_with EmailAddress::ActiveRecordValidator,
|
57
|
+
field: :alternate_email, code: :some_error_code, message: "Check your email"
|
55
58
|
|
56
59
|
def email=(email_address)
|
57
60
|
self[:canonical_email] = email_address
|
@@ -52,7 +52,7 @@ class TestHost < MiniTest::Test
|
|
52
52
|
def test_dmarc
|
53
53
|
d = EmailAddress::Host.new("yahoo.com").dmarc
|
54
54
|
assert_equal "reject", d[:p]
|
55
|
-
d = EmailAddress::Host.new("
|
55
|
+
d = EmailAddress::Host.new("calculator.net").dmarc
|
56
56
|
assert_equal true, d.empty?
|
57
57
|
end
|
58
58
|
|
@@ -127,7 +127,7 @@ class TestHost < MiniTest::Test
|
|
127
127
|
def test_hosted_service
|
128
128
|
# Is there a gmail-hosted domain that will continue to exist? Removing until then
|
129
129
|
# assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
|
130
|
-
assert !EmailAddress.valid?("
|
130
|
+
assert !EmailAddress.valid?("t@gmail.com", dns_lookup: :mx)
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_yahoo_bad_tld
|
@@ -154,4 +154,11 @@ class TestHost < MiniTest::Test
|
|
154
154
|
def test_host_size
|
155
155
|
assert !EmailAddress::Host.new("stackoverflow.com", {host_size: 1..3}).valid?
|
156
156
|
end
|
157
|
+
|
158
|
+
# When a domain is not configured to receive email (missing MX record),
|
159
|
+
# Though some MTA's will fallback to the A/AAAA host record
|
160
|
+
def test_no_mx
|
161
|
+
assert !EmailAddress::Host.new("zaboz.com").valid?
|
162
|
+
assert EmailAddress::Host.new("zaboz.com", dns_lookup: :a).valid?
|
163
|
+
end
|
157
164
|
end
|
@@ -92,7 +92,7 @@ class TestLocal < MiniTest::Test
|
|
92
92
|
|
93
93
|
def test_hosted
|
94
94
|
assert EmailAddress.valid?("x@exposure.co")
|
95
|
-
assert EmailAddress.error("
|
95
|
+
assert EmailAddress.error("xx+subscriber@gmail.com")
|
96
96
|
assert EmailAddress.valid?("xxxxx+subscriber@gmail.com")
|
97
97
|
end
|
98
98
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_address
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Fair
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rake
|
@@ -58,42 +57,42 @@ dependencies:
|
|
58
57
|
requirements:
|
59
58
|
- - "~>"
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
60
|
+
version: 8.0.0
|
62
61
|
type: :development
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
65
|
- - "~>"
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
67
|
+
version: 8.0.0
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
69
|
name: sqlite3
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
|
-
- - "
|
72
|
+
- - "~>"
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
74
|
+
version: '2.1'
|
76
75
|
type: :development
|
77
76
|
prerelease: false
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
79
78
|
requirements:
|
80
|
-
- - "
|
79
|
+
- - "~>"
|
81
80
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
81
|
+
version: '2.1'
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
83
|
name: standard
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
86
85
|
requirements:
|
87
|
-
- - "
|
86
|
+
- - ">="
|
88
87
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
88
|
+
version: '0'
|
90
89
|
type: :development
|
91
90
|
prerelease: false
|
92
91
|
version_requirements: !ruby/object:Gem::Requirement
|
93
92
|
requirements:
|
94
|
-
- - "
|
93
|
+
- - ">="
|
95
94
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
95
|
+
version: '0'
|
97
96
|
- !ruby/object:Gem::Dependency
|
98
97
|
name: net-smtp
|
99
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +135,62 @@ dependencies:
|
|
136
135
|
- - ">="
|
137
136
|
- !ruby/object:Gem::Version
|
138
137
|
version: '0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: bigdecimal
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
- !ruby/object:Gem::Dependency
|
153
|
+
name: mutex_m
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
type: :development
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
- !ruby/object:Gem::Dependency
|
167
|
+
name: irb
|
168
|
+
requirement: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
type: :development
|
174
|
+
prerelease: false
|
175
|
+
version_requirements: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
- !ruby/object:Gem::Dependency
|
181
|
+
name: base64
|
182
|
+
requirement: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
type: :runtime
|
188
|
+
prerelease: false
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
139
194
|
- !ruby/object:Gem::Dependency
|
140
195
|
name: simpleidn
|
141
196
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,7 +246,6 @@ homepage: https://github.com/afair/email_address
|
|
191
246
|
licenses:
|
192
247
|
- MIT
|
193
248
|
metadata: {}
|
194
|
-
post_install_message:
|
195
249
|
rdoc_options: []
|
196
250
|
require_paths:
|
197
251
|
- lib
|
@@ -209,22 +263,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
263
|
- !ruby/object:Gem::Version
|
210
264
|
version: '0'
|
211
265
|
requirements: []
|
212
|
-
rubygems_version: 3.
|
213
|
-
signing_key:
|
266
|
+
rubygems_version: 3.6.2
|
214
267
|
specification_version: 4
|
215
268
|
summary: This gem provides a ruby language library for working with and validating
|
216
269
|
email addresses. By default, it validates against conventional usage, the format
|
217
270
|
preferred for user email addresses. It can be configured to validate against RFC
|
218
271
|
“Standard” formats, common email service provider formats, and perform DNS validation.
|
219
|
-
test_files:
|
220
|
-
- test/activerecord/test_ar.rb
|
221
|
-
- test/activerecord/user.rb
|
222
|
-
- test/email_address/test_address.rb
|
223
|
-
- test/email_address/test_config.rb
|
224
|
-
- test/email_address/test_exchanger.rb
|
225
|
-
- test/email_address/test_host.rb
|
226
|
-
- test/email_address/test_local.rb
|
227
|
-
- test/email_address/test_rewriter.rb
|
228
|
-
- test/test_aliasing.rb
|
229
|
-
- test/test_email_address.rb
|
230
|
-
- test/test_helper.rb
|
272
|
+
test_files: []
|