email_repair 0.2.0 → 2.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 +5 -5
- data/README.md +68 -2
- data/lib/email_repair/constants.rb +2 -2
- data/lib/email_repair/mechanic.rb +7 -7
- data/lib/email_repair/version.rb +1 -1
- data/spec/lib/email_repair/constants_spec.rb +10 -0
- data/spec/lib/email_repair/mechanic_spec.rb +6 -8
- metadata +63 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5ee85877aa4e7df7d05e7084df4553209c6de6f4d555fe16ddd13070628f5ca5
|
|
4
|
+
data.tar.gz: e1ace67bbe8264421ae9c73dd77a7dde04097d694a90fcfae608b21e49d8e3be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58d21040563feed012c9218fb37f94173b895718ba103ff7d626e4dc3edb9c3c2c76f1f4395462522045b8eb88ad2ba393c81e995e709daaf663657a617c6e17
|
|
7
|
+
data.tar.gz: 66a4f543f9db2cf547dacfdb4eed8d55d1e9a98a9d6a9b7a2d5ca3ad9461769857458ccf18f02ff3faedc9b508634e0b36e4db13e681ea6f3444786d0fa133fe
|
data/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
[](https://travis-ci.org/ChalkSchools/email-repair)
|
|
5
5
|
[](https://coveralls.io/r/ChalkSchools/email-repair?branch=master)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Email Repair is a utility for sanitizing and validating user-provided email
|
|
8
|
+
address.
|
|
8
9
|
|
|
9
10
|
## Installation
|
|
10
11
|
|
|
@@ -22,7 +23,72 @@ Or install it yourself as:
|
|
|
22
23
|
|
|
23
24
|
## Usage
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
```ruby
|
|
27
|
+
require 'email_repair'
|
|
28
|
+
require 'ostruct'
|
|
29
|
+
|
|
30
|
+
EmailRepair::Mechanic.new.repair('blah@gmail')
|
|
31
|
+
# "blah@gmail.com"
|
|
32
|
+
|
|
33
|
+
EmailRepair::Mechanic.new.repair_all(%w[One@@two.com bleep@blop plooooooop])
|
|
34
|
+
# <OpenStruct sanitized_emails=["one@two.com"], invalid_emails=["bleep@blop", "plooooooop"]>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Public Methods
|
|
38
|
+
|
|
39
|
+
#### EmailRepair::Mechanic#repair(email)
|
|
40
|
+
|
|
41
|
+
Takes a single email address, applies the available repairs to it and returns
|
|
42
|
+
the repaired email. If the email cannot be repaired, `nil` is returned instead.
|
|
43
|
+
|
|
44
|
+
#### EmailRepair::Mechanic#repair_all(emails)
|
|
45
|
+
|
|
46
|
+
Takes an array of emails, applies available repairs to each email and returns an
|
|
47
|
+
`OpenStruct` containing keys `sanitized_emails:` with a unique array of the
|
|
48
|
+
emails that were able to be repaired, and `invalid_emails:` with unique array of
|
|
49
|
+
the emails that were unable to be repaired
|
|
50
|
+
|
|
51
|
+
#### EmailRepair::Constants::email_regex
|
|
52
|
+
|
|
53
|
+
Returns a regular expression to be used to validate user-supplied email
|
|
54
|
+
addresses.
|
|
55
|
+
|
|
56
|
+
### Available Repairs
|
|
57
|
+
|
|
58
|
+
#### CommonMistakeRepair
|
|
59
|
+
|
|
60
|
+
Repairs common email typos:
|
|
61
|
+
* downcases the email
|
|
62
|
+
* removes white space
|
|
63
|
+
* removes duplicate @ symbols
|
|
64
|
+
* replaces `.c0m` with `.com`
|
|
65
|
+
* replaces commas with periods
|
|
66
|
+
|
|
67
|
+
#### CommonDomainSuffixRepair
|
|
68
|
+
|
|
69
|
+
Adds missing top-level domain for common email domains. For example, it replaces
|
|
70
|
+
`blah@gmail` with `blah@gmail.com`.
|
|
71
|
+
|
|
72
|
+
#### CommonDomainPeriodAdder
|
|
73
|
+
|
|
74
|
+
Adds missing period between the domain and top-level domain for common email
|
|
75
|
+
domains. For example, it replaces `blah@gmailcom` with `blah@gmail.com`.
|
|
76
|
+
|
|
77
|
+
#### CommonDomainAtAdder
|
|
78
|
+
|
|
79
|
+
Replaces '#', '.', or '-', with '@', or adds missing @ symbol for common
|
|
80
|
+
domains. For example, it replaces `blahgmail.com` and `blah#gmail.com` with
|
|
81
|
+
`blah@gmail.com`.
|
|
82
|
+
|
|
83
|
+
#### CommonDomainSwapRepair
|
|
84
|
+
|
|
85
|
+
Fixes swapped letters ('ia' instead of 'ai') in common domains. For example, it
|
|
86
|
+
replaces `blah@gmial.com` with `blah@gmail.com`.
|
|
87
|
+
|
|
88
|
+
#### EmailRegexRepair
|
|
89
|
+
|
|
90
|
+
Extracts the email address from strings that contain other text. For example, it
|
|
91
|
+
replaces `blah <blah@email.com>` with `blah@email.com`.
|
|
26
92
|
|
|
27
93
|
## Contributing
|
|
28
94
|
|
|
@@ -4,7 +4,7 @@ module EmailRepair
|
|
|
4
4
|
def email_regex
|
|
5
5
|
local_part_regex = "[#{valid_chars}]" \
|
|
6
6
|
"([#{valid_chars_with_dot}]*[#{valid_chars}])?"
|
|
7
|
-
/#{local_part_regex}@(?:[a-
|
|
7
|
+
/#{local_part_regex}@(?:[a-zA-Z0-9\-]+\.)+(?:[a-zA-Z]{2,24})/
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
private
|
|
@@ -14,7 +14,7 @@ module EmailRepair
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def valid_chars
|
|
17
|
-
'a-
|
|
17
|
+
'a-zA-Z0-9_%\+\-\''
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -42,10 +42,10 @@ module EmailRepair
|
|
|
42
42
|
class CommonMistakeRepair
|
|
43
43
|
def self.repair(email)
|
|
44
44
|
email.downcase
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
.gsub(/\s/, '')
|
|
46
|
+
.sub(/@+/, '@')
|
|
47
|
+
.sub(/\.c0m$/, '.com')
|
|
48
|
+
.sub(/,[a-z]{2,24}$/) { |m| m.sub(',', '.') }
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -58,7 +58,7 @@ module EmailRepair
|
|
|
58
58
|
|
|
59
59
|
class CommonDomainRepair
|
|
60
60
|
def self.repair(*)
|
|
61
|
-
|
|
61
|
+
raise 'not implemented'
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def self.common_domains
|
|
@@ -78,7 +78,7 @@ module EmailRepair
|
|
|
78
78
|
class CommonDomainSuffixRepair < CommonDomainRepair
|
|
79
79
|
def self.repair(email)
|
|
80
80
|
common_domains.each do |name, suffix|
|
|
81
|
-
email = "#{email}.#{suffix}" if email.match(/#{name}$/)
|
|
81
|
+
email = "#{email}.#{suffix}" if email.match?(/#{name}$/)
|
|
82
82
|
end
|
|
83
83
|
email
|
|
84
84
|
end
|
|
@@ -100,7 +100,7 @@ module EmailRepair
|
|
|
100
100
|
punc_regex = /[.#-]#{name}.#{suffix}$/
|
|
101
101
|
if email.match(punc_regex)
|
|
102
102
|
email = email.sub(punc_regex, "@#{name}.#{suffix}")
|
|
103
|
-
elsif email.match(/[^@]#{name}.#{suffix}$/)
|
|
103
|
+
elsif email.match?(/[^@]#{name}.#{suffix}$/)
|
|
104
104
|
email = email.sub(/#{name}.#{suffix}$/, "@#{name}.#{suffix}")
|
|
105
105
|
end
|
|
106
106
|
end
|
data/lib/email_repair/version.rb
CHANGED
|
@@ -2,12 +2,11 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
module EmailRepair
|
|
4
4
|
describe Mechanic, '#repair_all' do
|
|
5
|
-
|
|
6
5
|
it 'sanitizes an array of emails and returns bulk results' do
|
|
7
6
|
mechanic = Mechanic.new
|
|
8
|
-
salvageable_emails = %w
|
|
9
|
-
sanitized_emails = %w
|
|
10
|
-
bad_emails = %w
|
|
7
|
+
salvageable_emails = %w[One@@two.com three@four.com one@twO.com]
|
|
8
|
+
sanitized_emails = %w[one@two.com three@four.com]
|
|
9
|
+
bad_emails = %w[bleep@blop plooooooop plooOOooop]
|
|
11
10
|
|
|
12
11
|
result = mechanic.repair_all(salvageable_emails + bad_emails)
|
|
13
12
|
expect(result.sanitized_emails).to match_array sanitized_emails
|
|
@@ -23,7 +22,6 @@ module EmailRepair
|
|
|
23
22
|
expect(result.sanitized_emails).to eq ['bleep@bloop.com']
|
|
24
23
|
expect(result.invalid_emails).to eq []
|
|
25
24
|
end
|
|
26
|
-
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
describe Mechanic, '#repair' do
|
|
@@ -34,7 +32,7 @@ module EmailRepair
|
|
|
34
32
|
# http://www.stuffaboutcode.com/2013/02/validating-email-address-bloody.html
|
|
35
33
|
# List of longest TLDs
|
|
36
34
|
# https://jasontucker.blog/8945/what-is-the-longest-tld-you-can-get-for-a-domain-name
|
|
37
|
-
good_emails = %w
|
|
35
|
+
good_emails = %w[
|
|
38
36
|
b@b.com
|
|
39
37
|
lobatifricha@gmail.com
|
|
40
38
|
mrspicy+whocares@whatevs.com
|
|
@@ -43,7 +41,7 @@ module EmailRepair
|
|
|
43
41
|
b@mps.school
|
|
44
42
|
b@kickstarter.engineering
|
|
45
43
|
b@joyful.christmas
|
|
46
|
-
|
|
44
|
+
]
|
|
47
45
|
|
|
48
46
|
good_emails.each do |good_email|
|
|
49
47
|
expect(mechanic.repair(good_email)).to eq good_email
|
|
@@ -73,7 +71,7 @@ module EmailRepair
|
|
|
73
71
|
end
|
|
74
72
|
|
|
75
73
|
it 'adds missing .com' do
|
|
76
|
-
no_com_mails = %w
|
|
74
|
+
no_com_mails = %w[blah@gmail bloo@yahoo blee@hotmail]
|
|
77
75
|
no_com_mails.each do |no_com_mail|
|
|
78
76
|
expect(mechanic.repair(no_com_mail)).to eq "#{no_com_mail}.com"
|
|
79
77
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: email_repair
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Holman Gao
|
|
@@ -9,8 +9,64 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
13
|
-
dependencies:
|
|
12
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: coveralls
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - "~>"
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: 0.8.23
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - "~>"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 0.8.23
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rake
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - "~>"
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: 13.0.6
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - "~>"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 13.0.6
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: rspec
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 3.12.0
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - "~>"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 3.12.0
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rubocop
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 1.50.2
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 1.50.2
|
|
14
70
|
description:
|
|
15
71
|
email:
|
|
16
72
|
- holman@golmansax.com
|
|
@@ -25,6 +81,7 @@ files:
|
|
|
25
81
|
- lib/email_repair/constants.rb
|
|
26
82
|
- lib/email_repair/mechanic.rb
|
|
27
83
|
- lib/email_repair/version.rb
|
|
84
|
+
- spec/lib/email_repair/constants_spec.rb
|
|
28
85
|
- spec/lib/email_repair/mechanic_spec.rb
|
|
29
86
|
- spec/spec_helper.rb
|
|
30
87
|
homepage: https://github.com/ChalkSchools/email-repair
|
|
@@ -46,11 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
46
103
|
- !ruby/object:Gem::Version
|
|
47
104
|
version: '0'
|
|
48
105
|
requirements: []
|
|
49
|
-
|
|
50
|
-
rubygems_version: 2.6.12
|
|
106
|
+
rubygems_version: 3.4.2
|
|
51
107
|
signing_key:
|
|
52
108
|
specification_version: 4
|
|
53
109
|
summary: Library to fix invalid emails
|
|
54
110
|
test_files:
|
|
55
|
-
- spec/
|
|
111
|
+
- spec/lib/email_repair/constants_spec.rb
|
|
56
112
|
- spec/lib/email_repair/mechanic_spec.rb
|
|
113
|
+
- spec/spec_helper.rb
|