valid_email2 3.7.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +5 -0
- data/lib/valid_email2/address.rb +4 -1
- data/lib/valid_email2/email_validator.rb +2 -2
- data/lib/valid_email2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d71886fd78b212aba95930356a6c8881f1e9368561a2cf96a961ff31798ca2ce
|
4
|
+
data.tar.gz: a1e3e23dc457a405b7394d673773f82acb6366d21629e037038337a31a0748e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff81fb5ba77ed53af7835033cae8bb1a10efe35a18b51a24dbe6af1030b6ee5fac5db9ed6d28066e6d07875d9b84c5079f3b9f2e94131f68a6772254fd8266d0
|
7
|
+
data.tar.gz: 452ccbe3dee5b6df8b93625283c1e592474a56cc4dd5f8b51e043b9ff6dc41ad4ad023cb397a962edc0e9d26b3c4fa863a545feb8ff4dcb771c228a66de01ce1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -47,10 +47,15 @@ To validate that the domain has an MX record or A record:
|
|
47
47
|
```ruby
|
48
48
|
validates :email, 'valid_email_2/email': { mx: true }
|
49
49
|
```
|
50
|
+
|
50
51
|
To validate strictly that the domain has an MX record:
|
51
52
|
```ruby
|
52
53
|
validates :email, 'valid_email_2/email': { strict_mx: true }
|
53
54
|
```
|
55
|
+
`strict_mx` and `mx` both default to a 5 second timeout for DNS lookups. To
|
56
|
+
override this timeout, specify a `dns_timeout` option:
|
57
|
+
```ruby
|
58
|
+
validates :email, 'valid_email_2/email': { strict_mx: true, dns_timeout: 10 }
|
54
59
|
|
55
60
|
To validate that the domain is not a disposable email (checks domain and MX server):
|
56
61
|
```ruby
|
data/lib/valid_email2/address.rb
CHANGED
@@ -20,9 +20,10 @@ module ValidEmail2
|
|
20
20
|
@prohibited_domain_characters_regex = val
|
21
21
|
end
|
22
22
|
|
23
|
-
def initialize(address)
|
23
|
+
def initialize(address, dns_timeout = 5)
|
24
24
|
@parse_error = false
|
25
25
|
@raw_address = address
|
26
|
+
@dns_timeout = dns_timeout
|
26
27
|
|
27
28
|
begin
|
28
29
|
@address = Mail::Address.new(address)
|
@@ -132,12 +133,14 @@ module ValidEmail2
|
|
132
133
|
|
133
134
|
def mx_servers
|
134
135
|
@mx_servers ||= Resolv::DNS.open do |dns|
|
136
|
+
dns.timeouts = @dns_timeout
|
135
137
|
dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX)
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
139
141
|
def mx_or_a_servers
|
140
142
|
@mx_or_a_servers ||= Resolv::DNS.open do |dns|
|
143
|
+
dns.timeouts = @dns_timeout
|
141
144
|
(mx_servers.any? && mx_servers) ||
|
142
145
|
dns.getresources(address.domain, Resolv::DNS::Resource::IN::A)
|
143
146
|
end
|
@@ -5,14 +5,14 @@ require "active_model/validations"
|
|
5
5
|
module ValidEmail2
|
6
6
|
class EmailValidator < ActiveModel::EachValidator
|
7
7
|
def default_options
|
8
|
-
{ regex: true, disposable: false, mx: false, strict_mx: false, disallow_subaddressing: false, multiple: false }
|
8
|
+
{ regex: true, disposable: false, mx: false, strict_mx: false, disallow_subaddressing: false, multiple: false, dns_timeout: 5 }
|
9
9
|
end
|
10
10
|
|
11
11
|
def validate_each(record, attribute, value)
|
12
12
|
return unless value.present?
|
13
13
|
options = default_options.merge(self.options)
|
14
14
|
|
15
|
-
addresses = sanitized_values(value).map { |v| ValidEmail2::Address.new(v) }
|
15
|
+
addresses = sanitized_values(value).map { |v| ValidEmail2::Address.new(v, options[:dns_timeout]) }
|
16
16
|
|
17
17
|
error(record, attribute) && return unless addresses.all?(&:valid?)
|
18
18
|
|
data/lib/valid_email2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micke Lisinge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|