email_assessor 0.8.3 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/email_assessor/address.rb +20 -10
- data/lib/email_assessor/version.rb +1 -1
- data/lib/email_assessor.rb +17 -4
- data/vendor/disposable_domains.txt +1146 -2
- data/vendor/educational_domains.txt +72 -0
- data/vendor/fastpass_domains.txt +128 -27
- 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: c3d58f2ccff5295b5ca3a6a340906e4bf434ebe786e3c60018595ef28872070d
|
4
|
+
data.tar.gz: cba2edd82f57fa711dbc2a8e0d8762913be44a9b3853cea44dd67dc412f26a8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7e563e8586f5fbcc4979957b259d0af04ce624d907110edc23b605bec5d7dcffa099f1889a8b15b3dff4c62b023527130029f584d4e1819c935b84271c3002c
|
7
|
+
data.tar.gz: 6432e40e499237ba0c4a0a1a94b095a74bdaf702d3d84f1aeeeea24248da4b344bee645dc6cf6e5bc1ed8a976b28f80fcc3daf7e95322c1aa4852e45c270c4af
|
@@ -5,7 +5,7 @@ require "mail"
|
|
5
5
|
|
6
6
|
module EmailAssessor
|
7
7
|
class Address
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :parsed
|
9
9
|
|
10
10
|
PROHIBITED_DOMAIN_PREFIXES = [
|
11
11
|
'.',
|
@@ -83,12 +83,16 @@ module EmailAssessor
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def initialize(
|
86
|
+
def initialize(raw_address)
|
87
87
|
@parse_error = false
|
88
|
-
@raw_address =
|
88
|
+
@raw_address = raw_address
|
89
|
+
@address = nil
|
90
|
+
@valid = nil
|
91
|
+
@mx_servers = nil
|
92
|
+
@domain_tokens = nil
|
89
93
|
|
90
94
|
begin
|
91
|
-
@address = Mail::Address.new(
|
95
|
+
@address = Mail::Address.new(raw_address)
|
92
96
|
rescue Mail::Field::ParseError
|
93
97
|
@parse_error = true
|
94
98
|
end
|
@@ -99,12 +103,12 @@ module EmailAssessor
|
|
99
103
|
return false if @parse_error
|
100
104
|
|
101
105
|
@valid =
|
102
|
-
if address.domain && address.address == @raw_address
|
103
|
-
domain = address.domain
|
106
|
+
if @address.domain && @address.address == @raw_address
|
107
|
+
domain = @address.domain
|
104
108
|
|
105
109
|
domain.include?('.') &&
|
106
110
|
!domain.match?(self.class.prohibited_domain_regex) &&
|
107
|
-
|
111
|
+
!@address.local.match?(self.class.prohibited_local_regex)
|
108
112
|
else
|
109
113
|
false
|
110
114
|
end
|
@@ -127,7 +131,7 @@ module EmailAssessor
|
|
127
131
|
end
|
128
132
|
|
129
133
|
def domain_in_file?(filename)
|
130
|
-
valid? && EmailAssessor.
|
134
|
+
valid? && EmailAssessor.any_token_in_file?(domain_tokens, filename)
|
131
135
|
end
|
132
136
|
|
133
137
|
def valid_mx?
|
@@ -145,10 +149,16 @@ module EmailAssessor
|
|
145
149
|
|
146
150
|
def mx_servers
|
147
151
|
@mx_servers ||= Resolv::DNS.open do |dns|
|
148
|
-
mx_servers = dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX)
|
152
|
+
mx_servers = dns.getresources(@address.domain, Resolv::DNS::Resource::IN::MX)
|
149
153
|
(mx_servers.any? && mx_servers) ||
|
150
|
-
dns.getresources(address.domain, Resolv::DNS::Resource::IN::A)
|
154
|
+
dns.getresources(@address.domain, Resolv::DNS::Resource::IN::A)
|
151
155
|
end
|
152
156
|
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def domain_tokens
|
161
|
+
@domain_tokens ||= EmailAssessor.tokenize_domain(@address.domain)
|
162
|
+
end
|
153
163
|
end
|
154
164
|
end
|
data/lib/email_assessor.rb
CHANGED
@@ -16,13 +16,26 @@ module EmailAssessor
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.domain_in_file?(domain, file_name)
|
19
|
+
any_token_in_file?(tokenize_domain(domain), file_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.any_token_in_file?(domain_tokens, file_name)
|
19
23
|
file_name ||= ""
|
20
|
-
domain = domain.downcase
|
21
24
|
|
22
25
|
File.foreach(file_name, chomp: true).any? do |line|
|
23
|
-
|
24
|
-
# (hotmail.com is valid but tmail.com is not) regex is also necessary.
|
25
|
-
domain.end_with?(line) && domain.match?(%r{\A(?:.*\.)?#{Regexp.escape(line)}\z}i)
|
26
|
+
domain_tokens.key?(line)
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
def self.tokenize_domain(domain)
|
31
|
+
parts = domain.downcase.split(".")
|
32
|
+
tokens = {}
|
33
|
+
|
34
|
+
parts.length.times do
|
35
|
+
tokens[parts.join(".")] = nil
|
36
|
+
parts.shift
|
37
|
+
end
|
38
|
+
|
39
|
+
tokens
|
40
|
+
end
|
28
41
|
end
|