email_assessor 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +28 -4
- data/lib/email_assessor.rb +7 -30
- data/lib/email_assessor/version.rb +1 -1
- data/pull_mailchecker_emails.rb +1 -1
- data/spec/email_assessor_spec.rb +2 -33
- data/vendor/blacklisted_domains.txt +1 -1
- data/vendor/disposable_domains.txt +0 -1
- metadata +2 -6
- data/spec/fixtures/blacklisted_domains.txt +0 -1
- data/spec/fixtures/disposable_domains.txt +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e6bbdf20e2b76943db2c9957b2b3e689c6d4956
|
4
|
+
data.tar.gz: 744a37974466b6c82744821b93bc7ec66362482c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1712d4c2ed8d66046fc707830954c3b1a406e2f27e7a6f7f0eb089e3fe2cc2c24d19fe8e5f7ed0bc171e3b0ef5d800b36f40e2bf276ca838d3223e9012092904
|
7
|
+
data.tar.gz: 5ce7e6899e887a555d654defcf2429aa9bbc3b4a6da102baeed3d120c5c932d7075374bf9016396c499a90237c20506f03ec9d0e9240f0b2aa238f481e77f480
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# EmailAssessor
|
2
2
|
[![Build Status](https://travis-ci.org/wolfemm/email_assessor.png?branch=master)](https://travis-ci.org/wolfemm/email_assessor)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/email_assessor.png)](http://badge.fury.io/rb/email_assessor)
|
4
4
|
|
5
|
-
A fork of
|
5
|
+
A fork of [Micke Lisinge](https://github.com/lisinge)'s [ValidEmail2](https://github.com/lisinge/valid_email2).
|
6
6
|
|
7
7
|
ValidEmail2:
|
8
8
|
|
@@ -36,6 +36,30 @@ Or install it yourself as:
|
|
36
36
|
|
37
37
|
$ gem install email_assessor
|
38
38
|
|
39
|
+
## Domain List Files
|
40
|
+
|
41
|
+
Domain list files, used for blacklisting and blocking disposable emails, are plain-text files with one **lower case** domain per line.
|
42
|
+
|
43
|
+
Valid domain list file:
|
44
|
+
```
|
45
|
+
example.com
|
46
|
+
subdomain.example.org
|
47
|
+
```
|
48
|
+
|
49
|
+
Invalid domain list file:
|
50
|
+
```
|
51
|
+
http://example.com
|
52
|
+
example.com/mail
|
53
|
+
```
|
54
|
+
|
55
|
+
Be careful with subdomains. Given the following domain list file:
|
56
|
+
|
57
|
+
```
|
58
|
+
sub.example.com
|
59
|
+
```
|
60
|
+
|
61
|
+
A user would be able to register with the email `jake@example.com` but not `tom@sub.example.com` or `jerry@deep.sub.example.com`.
|
62
|
+
|
39
63
|
## Usage
|
40
64
|
|
41
65
|
### Use with ActiveModel
|
@@ -57,14 +81,14 @@ To validate that the domain is not a disposable email:
|
|
57
81
|
validates :email, email: { disposable: true }
|
58
82
|
```
|
59
83
|
|
60
|
-
To validate that the domain is not blacklisted (
|
84
|
+
To validate that the domain is not blacklisted (via `vendor/blacklisted_domains.txt`):
|
61
85
|
```ruby
|
62
86
|
validates :email, email: { blacklist: true }
|
63
87
|
```
|
64
88
|
|
65
89
|
All together:
|
66
90
|
```ruby
|
67
|
-
validates :email, email: { mx: true, disposable: true }
|
91
|
+
validates :email, email: { mx: true, disposable: true, blacklist: true }
|
68
92
|
```
|
69
93
|
|
70
94
|
> Note that this gem will let an empty email pass through so you will need to
|
data/lib/email_assessor.rb
CHANGED
@@ -1,46 +1,23 @@
|
|
1
1
|
require "email_assessor/email_validator"
|
2
2
|
|
3
3
|
module EmailAssessor
|
4
|
+
DISPOSABLE_DOMAINS_FILE_NAME = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
|
5
|
+
BLACKLISTED_DOMAINS_FILE_NAME = File.expand_path("vendor/blacklisted_domains.txt")
|
6
|
+
|
4
7
|
def self.domain_is_disposable?(domain)
|
5
|
-
domain_in_file?(domain,
|
8
|
+
domain_in_file?(domain, DISPOSABLE_DOMAINS_FILE_NAME)
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.domain_is_blacklisted?(domain)
|
9
|
-
domain_in_file?(domain,
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.configuration
|
13
|
-
@configuration ||= Configuration.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.configure
|
17
|
-
yield(configuration) if block_given?
|
18
|
-
end
|
19
|
-
|
20
|
-
class Configuration
|
21
|
-
attr_accessor :disposable_domains_file_name, :blacklisted_domains_file_name
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@disposable_domains_file_name = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
|
25
|
-
@blacklisted_domains_file_name = File.expand_path("vendor/blacklisted_domains.txt")
|
26
|
-
end
|
12
|
+
domain_in_file?(domain, BLACKLISTED_DOMAINS_FILE_NAME)
|
27
13
|
end
|
28
14
|
|
29
15
|
protected
|
30
16
|
|
31
17
|
def self.domain_in_file?(domain, file_name)
|
32
|
-
|
33
|
-
|
18
|
+
file_name ||= ""
|
34
19
|
domain = domain.downcase
|
35
|
-
domain_matched = false
|
36
|
-
|
37
|
-
File.open(file_name).each do |line|
|
38
|
-
if domain.end_with?(line.chomp)
|
39
|
-
domain_matched = true
|
40
|
-
break
|
41
|
-
end
|
42
|
-
end
|
43
20
|
|
44
|
-
|
21
|
+
File.open(file_name).each_line.any? { |line| domain.end_with?(line) }
|
45
22
|
end
|
46
23
|
end
|
data/pull_mailchecker_emails.rb
CHANGED
@@ -5,7 +5,7 @@ require "yaml"
|
|
5
5
|
require "json"
|
6
6
|
require "net/http"
|
7
7
|
|
8
|
-
whitelisted_domains = %w(poczta.onet.pl fastmail.fm hushmail.com naver.com)
|
8
|
+
whitelisted_domains = %w(poczta.onet.pl fastmail.fm hushmail.com naver.com qq.com)
|
9
9
|
|
10
10
|
existing_domains = File.readlines("vendor/disposable_domains.txt")
|
11
11
|
|
data/spec/email_assessor_spec.rb
CHANGED
@@ -22,10 +22,10 @@ describe EmailAssessor do
|
|
22
22
|
let(:blacklist_user) { TestUserDisallowBlacklisted.new(email: "foo@gmail.com") }
|
23
23
|
let(:mx_user) { TestUserMX.new(email: "foo@gmail.com") }
|
24
24
|
|
25
|
-
let(:blacklisted_domains_file_name) { described_class
|
25
|
+
let(:blacklisted_domains_file_name) { described_class::BLACKLISTED_DOMAINS_FILE_NAME }
|
26
26
|
let(:blacklisted_domain) { File.open(blacklisted_domains_file_name, &:readline) }
|
27
27
|
|
28
|
-
let(:disposable_domains_file_name) { described_class
|
28
|
+
let(:disposable_domains_file_name) { described_class::DISPOSABLE_DOMAINS_FILE_NAME }
|
29
29
|
let(:disposable_domain) { File.open(disposable_domains_file_name, &:readline) }
|
30
30
|
|
31
31
|
describe "basic validation" do
|
@@ -110,35 +110,4 @@ describe EmailAssessor do
|
|
110
110
|
is_expected.to be_invalid
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
114
|
-
describe "configuration" do
|
115
|
-
subject(:configuration) { described_class.configuration }
|
116
|
-
let(:disposable_domains_file_name) { File.expand_path("../fixtures/disposable_domains.txt", __FILE__) }
|
117
|
-
let(:blacklisted_domains_file_name) { File.expand_path("../fixtures/blacklisted_domains.txt", __FILE__) }
|
118
|
-
|
119
|
-
before do
|
120
|
-
described_class.configure do |config|
|
121
|
-
config.disposable_domains_file_name = disposable_domains_file_name
|
122
|
-
config.blacklisted_domains_file_name = blacklisted_domains_file_name
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "sets the disposable domains file" do
|
127
|
-
is_expected.to have_attributes disposable_domains_file_name: disposable_domains_file_name
|
128
|
-
end
|
129
|
-
|
130
|
-
it "sets the blacklisted domains file" do
|
131
|
-
is_expected.to have_attributes blacklisted_domains_file_name: blacklisted_domains_file_name
|
132
|
-
end
|
133
|
-
|
134
|
-
it "uses the configured disposable domains file" do
|
135
|
-
disposable_user.email = disposable_domain
|
136
|
-
expect(disposable_user).to be_invalid
|
137
|
-
end
|
138
|
-
|
139
|
-
it "uses the configured blacklisted domains file" do
|
140
|
-
blacklist_user.email = blacklisted_domain
|
141
|
-
expect(blacklist_user).to be_invalid
|
142
|
-
end
|
143
|
-
end
|
144
113
|
end
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
blacklist.example.com
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_assessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Wolfe Millard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,8 +103,6 @@ files:
|
|
103
103
|
- lib/email_assessor/version.rb
|
104
104
|
- pull_mailchecker_emails.rb
|
105
105
|
- spec/email_assessor_spec.rb
|
106
|
-
- spec/fixtures/blacklisted_domains.txt
|
107
|
-
- spec/fixtures/disposable_domains.txt
|
108
106
|
- spec/spec_helper.rb
|
109
107
|
- vendor/blacklisted_domains.txt
|
110
108
|
- vendor/disposable_domains.txt
|
@@ -134,6 +132,4 @@ specification_version: 4
|
|
134
132
|
summary: Advanced ActiveModel email validation
|
135
133
|
test_files:
|
136
134
|
- spec/email_assessor_spec.rb
|
137
|
-
- spec/fixtures/blacklisted_domains.txt
|
138
|
-
- spec/fixtures/disposable_domains.txt
|
139
135
|
- spec/spec_helper.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
rspec-blacklisted.txt
|
@@ -1 +0,0 @@
|
|
1
|
-
rspec-disposable.txt
|