valid_email2 3.7.0 → 4.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cb2c121fd6702c7060c30c6b79be1bd4f08c40ed94f06aa3f360c333b28a5d6
4
- data.tar.gz: '09ed3d5c345731baaf90bda8bf5fca432c753277cdd909e19e58feef7525f404'
3
+ metadata.gz: d71886fd78b212aba95930356a6c8881f1e9368561a2cf96a961ff31798ca2ce
4
+ data.tar.gz: a1e3e23dc457a405b7394d673773f82acb6366d21629e037038337a31a0748e9
5
5
  SHA512:
6
- metadata.gz: 6718851acadedad38dd94c423a9fe84b71469fd9ee14b97687b4400f36edc7f31eeeb2fe63b973a3e451f6bcb3f8fda32f448571d1590e0b23319a78fcff3b7e
7
- data.tar.gz: f794802a5e7e4ee12a5c840e900d167e6d7ccaf3cefce4eaa285cf6b4d3fc100f364c37ebd9a00f4ab9368444745d0bc72e8237e3372f69145c5a471478a6f47
6
+ metadata.gz: ff81fb5ba77ed53af7835033cae8bb1a10efe35a18b51a24dbe6af1030b6ee5fac5db9ed6d28066e6d07875d9b84c5079f3b9f2e94131f68a6772254fd8266d0
7
+ data.tar.gz: 452ccbe3dee5b6df8b93625283c1e592474a56cc4dd5f8b51e043b9ff6dc41ad4ad023cb397a962edc0e9d26b3c4fa863a545feb8ff4dcb771c228a66de01ce1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Version 4.0.0
2
+ * Support setting a timout for DNS lookups and default to 5 seconds https://github.com/micke/valid_email2/pull/181
3
+
1
4
  ## Version 3.7.0
2
5
  * Support validating arrays https://github.com/micke/valid_email2/pull/178
3
6
  * Pull new domains
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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal:true
2
2
 
3
3
  module ValidEmail2
4
- VERSION = "3.7.0"
4
+ VERSION = "4.0.0"
5
5
  end
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: 3.7.0
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-26 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler