email_repair 1.0.0 → 2.0.1
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 +3 -0
- 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 +4 -0
- metadata +67 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b61b1b2063f88892f084765ac14f503779b4b8ec762d913be9fa0c8e37c4e9e3
|
4
|
+
data.tar.gz: e5dc3b00f01d7f403e7bf2a3424d6054d24980003f3f72232a612b812b17f58a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e2a4144f8eda61738f62bdfe3f2530143eb75aca458f9f580e90f5342d9d006aefb87c58bca26784fb5fa8ce82acdc8c69c94ce33f1867849ec5a7d4f8e52a9
|
7
|
+
data.tar.gz: 521aaa4e93c7d06e75541d1e2841d60672b453b48a87223984d3972b618ead34b45d89af0fc5d6cdf2943b972358bfe56b8b5a8f79a9d98003ff7bc103bc6149
|
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
|
@@ -96,8 +96,11 @@ module EmailRepair
|
|
96
96
|
|
97
97
|
class CommonDomainAtAdder < CommonDomainRepair
|
98
98
|
def self.repair(email)
|
99
|
+
return email if email.match('.+@.+\..+')
|
100
|
+
|
99
101
|
common_domains.each do |name, suffix|
|
100
102
|
punc_regex = /[.#-]#{name}.#{suffix}$/
|
103
|
+
|
101
104
|
if email.match(punc_regex)
|
102
105
|
email = email.sub(punc_regex, "@#{name}.#{suffix}")
|
103
106
|
elsif email.match?(/[^@]#{name}.#{suffix}$/)
|
data/lib/email_repair/version.rb
CHANGED
@@ -123,6 +123,10 @@ module EmailRepair
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
it 'does not add an extra @ if there is already one' do
|
127
|
+
expect(mechanic.repair('bloo@myyahoo.com')).to eq 'bloo@myyahoo.com'
|
128
|
+
end
|
129
|
+
|
126
130
|
it 'replaces , with .' do
|
127
131
|
expect(mechanic.repair('b@b,com')).to eq 'b@b.com'
|
128
132
|
end
|
metadata
CHANGED
@@ -1,17 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_repair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Holman Gao
|
8
8
|
- JT Bowler
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2023-08-21 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
|
70
|
+
description:
|
15
71
|
email:
|
16
72
|
- holman@golmansax.com
|
17
73
|
- jbowler2400@gmail.com
|
@@ -25,13 +81,14 @@ 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
|
31
88
|
licenses:
|
32
89
|
- MIT
|
33
90
|
metadata: {}
|
34
|
-
post_install_message:
|
91
|
+
post_install_message:
|
35
92
|
rdoc_options: []
|
36
93
|
require_paths:
|
37
94
|
- lib
|
@@ -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
|
-
|
51
|
-
signing_key:
|
106
|
+
rubygems_version: 3.4.10
|
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
|