email_inquire 0.4.0 → 0.5.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 +4 -4
- data/Gemfile +1 -0
- data/Guardfile +1 -0
- data/README.md +18 -3
- data/Rakefile +1 -0
- data/email_inquire.gemspec +4 -3
- data/lib/email_inquire.rb +2 -0
- data/lib/email_inquire/email_validator.rb +65 -0
- data/lib/email_inquire/inquirer.rb +33 -31
- data/lib/email_inquire/response.rb +1 -0
- data/lib/email_inquire/version.rb +2 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cc6da6d04f9d91202fac7e069e7a32cdd4dac56
|
4
|
+
data.tar.gz: d80e50d52a21208143d1ae9ed4bdd26117d293eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119f06284f5d36e51a5e8496a40fa9203796b17692a7983f9732ae7a91cc07ede53362d19cf8db0a40d3f6bfefa4b636209aa2754a7c873edd821438f8cd98bb
|
7
|
+
data.tar.gz: 8674574dde20545502ab0e8181dd51fecbe9941b0ad4e1a57ac4fe8fe39b3cb1d5ac33685ae8f5d53ee9d947a1ee6df82d9f0b05417dd45b95570261ed5b51fc
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/email_inquire) [](https://travis-ci.org/maximeg/email_inquire) [](https://codeclimate.com/github/maximeg/email_inquire)
|
4
4
|
|
5
|
-
EmailInquire is a library to validate email for common typos and one-time email providers.
|
5
|
+
EmailInquire is a library to validate email for format, common typos and one-time email providers.
|
6
6
|
|
7
7
|
## Why?
|
8
8
|
|
@@ -22,7 +22,20 @@ And also, we don't want for users to use one-time email addresses (also called b
|
|
22
22
|
|
23
23
|
### Supported cases
|
24
24
|
|
25
|
-
|
25
|
+
Format error. This doesn't strictly follow RFC 5322, it aims at validating email that will be
|
26
|
+
deliverable on Internet. It also takes into account length of email, name part and domain part as
|
27
|
+
per SMTP specification.
|
28
|
+
|
29
|
+
- `foo@example..com` => invalid
|
30
|
+
- `foo@example..foo.com` => invalid
|
31
|
+
- `foo@example--foo.com` => invalid
|
32
|
+
- `foo@localhost` => invalid
|
33
|
+
- `foo@123.123.123.123` => invalid
|
34
|
+
- `secrétariat@example.com` => invalid
|
35
|
+
- `foo+test@example.com` => valid
|
36
|
+
- ...
|
37
|
+
|
38
|
+
One char typo for 43 common email providers (worldwide and from France, United Kingdom and USA):
|
26
39
|
|
27
40
|
- `gmil.com` => hint `gmail.com`
|
28
41
|
- `hitmail.com` => hint `hotmail.com`
|
@@ -30,7 +43,7 @@ One char typo for 43 common email providers of France, United Kingdom and USA:
|
|
30
43
|
- `virinmedia.com` => hint `virginmedia.com`
|
31
44
|
- ...
|
32
45
|
|
33
|
-
United Kingdom `.xx.uk` domains:
|
46
|
+
ccTLD specificity, like United Kingdom `.xx.uk` domains:
|
34
47
|
|
35
48
|
- `foo.couk` => hint `foo.co.uk`
|
36
49
|
- `fooco.uk` => hint `foo.co.uk`
|
@@ -38,6 +51,8 @@ United Kingdom `.xx.uk` domains:
|
|
38
51
|
- `foo.judiciary.uk` => ok!
|
39
52
|
- ...
|
40
53
|
|
54
|
+
...and same thing with `.co.jp` domains.
|
55
|
+
|
41
56
|
Providers with an unique domain:
|
42
57
|
|
43
58
|
- `gmail.fr` => hint `gmail.com`
|
data/Rakefile
CHANGED
data/email_inquire.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
+
|
3
4
|
lib = File.expand_path("../lib", __FILE__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
6
|
require "email_inquire/version"
|
@@ -10,8 +11,8 @@ Gem::Specification.new do |spec|
|
|
10
11
|
spec.authors = ["Maxime Garcia"]
|
11
12
|
spec.email = ["maxime.garcia@gmail.com"]
|
12
13
|
|
13
|
-
spec.summary = "Library to validate email for common typos and one-time email
|
14
|
-
spec.description = "Library to validate email for common typos and one-time email
|
14
|
+
spec.summary = "Library to validate email for format, common typos and one-time email providers"
|
15
|
+
spec.description = "Library to validate email for format, common typos and one-time email providers"
|
15
16
|
spec.homepage = "https://github.com/maximeg/email_inquire"
|
16
17
|
spec.license = "MIT"
|
17
18
|
|
@@ -29,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.13"
|
30
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
33
|
+
spec.add_development_dependency "rubocop", "~> 0.48"
|
33
34
|
end
|
data/lib/email_inquire.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EmailInquire
|
4
|
+
|
5
|
+
class EmailValidator
|
6
|
+
|
7
|
+
def initialize(email)
|
8
|
+
@email = email.downcase
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :email
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
return false unless email.count("@") == 1
|
15
|
+
return false if email.length > 255
|
16
|
+
name, domain = email.split("@", 2)
|
17
|
+
|
18
|
+
name_valid?(name) && domain_valid?(domain)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
DOMAIN_REGEXP = /
|
24
|
+
\A
|
25
|
+
(?:
|
26
|
+
(?=
|
27
|
+
[a-z0-9-]{1,63}
|
28
|
+
\.
|
29
|
+
)
|
30
|
+
[a-z0-9]+
|
31
|
+
(?:
|
32
|
+
-
|
33
|
+
[a-z0-9]+
|
34
|
+
)*
|
35
|
+
\.
|
36
|
+
){1,8}
|
37
|
+
[a-z]{2,63}
|
38
|
+
\z
|
39
|
+
/x
|
40
|
+
|
41
|
+
def domain_valid?(domain)
|
42
|
+
return false if domain == ""
|
43
|
+
return false unless domain =~ DOMAIN_REGEXP
|
44
|
+
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
NAME_REGEXP = /
|
49
|
+
\A
|
50
|
+
[a-z0-9]
|
51
|
+
[a-z0-9._%+-]{0,63}
|
52
|
+
\z
|
53
|
+
/x
|
54
|
+
|
55
|
+
def name_valid?(name)
|
56
|
+
return false if name == ""
|
57
|
+
return false if name.length > 64
|
58
|
+
return false unless name =~ NAME_REGEXP
|
59
|
+
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "damerau-levenshtein"
|
3
4
|
require "set"
|
4
5
|
|
@@ -28,8 +29,29 @@ module EmailInquire
|
|
28
29
|
|
29
30
|
attr_reader :domain, :email, :name
|
30
31
|
|
32
|
+
VALIDATORS = %i(
|
33
|
+
validate_common_domains
|
34
|
+
validate_one_time_providers
|
35
|
+
validate_common_domain_mistakes
|
36
|
+
validate_cc_tld
|
37
|
+
validate_common_tld_mistakes
|
38
|
+
validate_domains_with_unique_tld
|
39
|
+
).freeze
|
40
|
+
|
31
41
|
def validate
|
32
|
-
|
42
|
+
email_validator = EmailValidator.new(email)
|
43
|
+
unless email_validator.valid?
|
44
|
+
response.invalid!
|
45
|
+
return response
|
46
|
+
end
|
47
|
+
|
48
|
+
VALIDATORS.each do |validator|
|
49
|
+
send(validator)
|
50
|
+
break if response.valid? || response.invalid?
|
51
|
+
end
|
52
|
+
|
53
|
+
# default
|
54
|
+
response.valid! unless response.status?
|
33
55
|
|
34
56
|
response
|
35
57
|
end
|
@@ -46,25 +68,6 @@ module EmailInquire
|
|
46
68
|
end
|
47
69
|
end
|
48
70
|
|
49
|
-
VALIDATORS = [
|
50
|
-
:validate_common_domains,
|
51
|
-
:validate_one_time_providers,
|
52
|
-
:validate_common_domain_mistakes,
|
53
|
-
:validate_cc_tld,
|
54
|
-
:validate_common_tld_mistakes,
|
55
|
-
:validate_domains_with_unique_tld,
|
56
|
-
].freeze
|
57
|
-
|
58
|
-
def validate_typos
|
59
|
-
VALIDATORS.each do |validator|
|
60
|
-
send(validator)
|
61
|
-
break if response.valid? || response.invalid?
|
62
|
-
end
|
63
|
-
|
64
|
-
# default
|
65
|
-
response.valid! unless response.status?
|
66
|
-
end
|
67
|
-
|
68
71
|
COMMON_DOMAIN_MISTAKES = {
|
69
72
|
/google(?!mail)/ => "gmail.com",
|
70
73
|
/windows.*\.com/ => "live.com",
|
@@ -112,26 +115,25 @@ module EmailInquire
|
|
112
115
|
end
|
113
116
|
end
|
114
117
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
[".jp", ".co.jp", VALID_JP_TLD],
|
119
|
-
[".uk", ".co.uk", VALID_UK_TLD],
|
118
|
+
VALID_CC_TLDS = [
|
119
|
+
[".jp", ".co.jp", load_data("jp_tld").freeze],
|
120
|
+
[".uk", ".co.uk", load_data("uk_tld").freeze],
|
120
121
|
].freeze
|
121
122
|
|
122
123
|
def validate_cc_tld
|
123
|
-
|
124
|
+
VALID_CC_TLDS.each do |tld, sld, valid_tlds|
|
124
125
|
next unless domain.end_with?(tld)
|
125
126
|
|
126
|
-
next if
|
127
|
+
next if valid_tlds.any? do |reference|
|
127
128
|
domain.end_with?(reference)
|
128
129
|
end
|
129
130
|
|
131
|
+
_, com, tld_without_dot = sld.split(".")
|
132
|
+
|
130
133
|
new_domain = domain.dup
|
131
|
-
tld_without_dot
|
132
|
-
new_domain.gsub!(
|
133
|
-
new_domain.gsub!(/(
|
134
|
-
new_domain.gsub!(/(?<!\.co)\.#{tld_without_dot}\z/, sld)
|
134
|
+
new_domain.gsub!(/\.[a-z]{2,#{com.length}}\.#{tld_without_dot}\z/, sld)
|
135
|
+
new_domain.gsub!(/(?<!\.)#{com}\.#{tld_without_dot}\z/, sld)
|
136
|
+
new_domain.gsub!(/(?<!\.#{com})\.#{tld_without_dot}\z/, sld)
|
135
137
|
response.hint!(domain: new_domain) if new_domain != domain
|
136
138
|
end
|
137
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_inquire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: damerau-levenshtein
|
@@ -72,15 +72,16 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.48'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
83
|
-
description: Library to validate email for common typos and one-time email
|
82
|
+
version: '0.48'
|
83
|
+
description: Library to validate email for format, common typos and one-time email
|
84
|
+
providers
|
84
85
|
email:
|
85
86
|
- maxime.garcia@gmail.com
|
86
87
|
executables: []
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- data/unique_domain_providers.txt
|
106
107
|
- email_inquire.gemspec
|
107
108
|
- lib/email_inquire.rb
|
109
|
+
- lib/email_inquire/email_validator.rb
|
108
110
|
- lib/email_inquire/inquirer.rb
|
109
111
|
- lib/email_inquire/response.rb
|
110
112
|
- lib/email_inquire/version.rb
|
@@ -131,5 +133,5 @@ rubyforge_project:
|
|
131
133
|
rubygems_version: 2.6.11
|
132
134
|
signing_key:
|
133
135
|
specification_version: 4
|
134
|
-
summary: Library to validate email for common typos and one-time email
|
136
|
+
summary: Library to validate email for format, common typos and one-time email providers
|
135
137
|
test_files: []
|