rails-real-email 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +79 -10
- data/lib/rails/real/email.rb +11 -0
- data/lib/rails/real/email/version.rb +1 -1
- data/rails-real-email.gemspec +4 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85f7fce059869b7b6af68c2fc8300d86a678540
|
4
|
+
data.tar.gz: 12c423f3f793fd0691f5c964ed782826f4e82d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcf984508758776fc0bd91b169844f78f289f1729fa9e6b3f935681cdffe6877a4ec58fc6cf9b897504dde6cd54cbb04d1808d8eb2efac3a1e6cdcde2e8209c0
|
7
|
+
data.tar.gz: e768b4dcfcecdd2425128d73f4398c2746524055d65f561c2a2f2b5bdf3d62942950773e28477d8eb5cfec9caf08cc9943c9003ed819530ddb6d63bd19532259
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# Rails
|
1
|
+
# Rails Real Email
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
The Ruby Gem check the email address live for Ruby on Rails.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,18 +20,89 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
```
|
24
|
+
Rails::Real::Email.email_is_real?('email')
|
25
|
+
```
|
26
|
+
or
|
27
|
+
```
|
28
|
+
EmailVerify.excute('email')
|
29
|
+
```
|
30
|
+
|
31
|
+
result will `true` or `false`
|
26
32
|
|
27
|
-
|
33
|
+
Example:
|
28
34
|
|
29
|
-
|
35
|
+
- with real email:
|
30
36
|
|
31
|
-
|
37
|
+
```
|
38
|
+
EmailVerify.excute('hello@gmail.com') # true
|
39
|
+
```
|
32
40
|
|
33
|
-
|
41
|
+
- with unreal email:
|
42
|
+
|
43
|
+
```
|
44
|
+
EmailVerify.excute('azqqqq33334444kkk@gmail') # false
|
45
|
+
```
|
46
|
+
|
47
|
+
- with invalid email:
|
48
|
+
|
49
|
+
```
|
50
|
+
EmailVerify.excute('invalid@email') # false
|
51
|
+
```
|
52
|
+
|
53
|
+
### Use with Devise
|
54
|
+
Note: This approach has been used with Devise 1.5.4 under Rails 3.2.12, YMMV.
|
55
|
+
|
56
|
+
Email validation in a production apps is challenging because the RFC is complex, and in the real world different email sub-systems differ in their adherence to the RFC spec. It is not uncommon for a "valid" email to be rejected by a system that may validate email addresses with a too-narrow subset of rules.
|
57
|
+
|
58
|
+
The Devise email validator is intentionally relaxed to reduce the likelihood of rejecting a valid email, but, as a result, may permit users to register with an email address that is not deliverable. One specific example is `someone@example.co,`. Whether or not that address is valid according to the RFC, it clearly cannot be delivered. (And since the comma key is next to the "m" key on most keyboards, it's not that hard for a user to type ".co," instead of ".com")
|
59
|
+
|
60
|
+
Rails permits custom validators, so it is quite simple to add your own custom email validator, and no change to Devise is necessary (as long as you want Devise's built-in validator to also be applied). You'll get the union of the two validators, eg, an email has to pass both validators. If your custom validator is "more strict" than Devise's validator (as in this example), your app will have the benefit of the stricter validation automatically.
|
61
|
+
|
62
|
+
|
63
|
+
If your goal is to supplement, but not replace, the Devise email validation, the approach is simpler:
|
64
|
+
|
65
|
+
Add to your User model:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
validates :email, :presence => true, :email => true
|
69
|
+
```
|
70
|
+
|
71
|
+
(Update 2015-Mar-24: the :tree method used was private and is no longer available. A limited check/hack would be to ensure the domain contains at least one '.')
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# app/validators/email_validator.rb
|
75
|
+
require 'mail'
|
76
|
+
class EmailValidator < ActiveModel::EachValidator
|
77
|
+
def validate_each(record,attribute,value)
|
78
|
+
begin
|
79
|
+
m = Mail::Address.new(value)
|
80
|
+
# We must check that value contains a domain, the domain has at least
|
81
|
+
# one '.' and that value is an email address
|
82
|
+
r = m.domain!=nil && m.domain.match('\.') && m.address == value
|
83
|
+
|
84
|
+
# Update 2015-Mar-24
|
85
|
+
# the :tree method was private and is no longer available.
|
86
|
+
# t = m.__send__(:tree)
|
87
|
+
# We need to dig into treetop
|
88
|
+
# A valid domain must have dot_atom_text elements size > 1
|
89
|
+
# user@localhost is excluded
|
90
|
+
# treetop must respond to domain
|
91
|
+
# We exclude valid email values like <user@localhost.com>
|
92
|
+
# Hence we use m.__send__(tree).domain
|
93
|
+
# r &&= (t.domain.dot_atom_text.elements.size > 1)
|
94
|
+
r = EmailVerify.excute(m.address) ? true : false
|
95
|
+
rescue
|
96
|
+
r = false
|
97
|
+
end
|
98
|
+
record.errors[attribute] << (options[:message] || "is invalid") unless r
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
34
102
|
|
35
|
-
|
103
|
+
## Maintainers
|
36
104
|
|
105
|
+
- [Libra-](https://github.com/minhquan4080)
|
37
106
|
|
38
107
|
## License
|
39
108
|
|
data/lib/rails/real/email.rb
CHANGED
@@ -4,9 +4,20 @@ require "rails/real/email/mail_check.rb"
|
|
4
4
|
module Rails
|
5
5
|
module Real
|
6
6
|
module Email
|
7
|
+
|
8
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
9
|
+
|
7
10
|
def self.email_is_real?(email)
|
11
|
+
return false unless email.match VALID_EMAIL_REGEX
|
12
|
+
MailCheck.run(email).invalid?
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.excute(email)
|
16
|
+
return false unless email.match VALID_EMAIL_REGEX
|
8
17
|
MailCheck.run(email).invalid?
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
12
21
|
end
|
22
|
+
|
23
|
+
EmailVerify = Rails::Real::Email
|
data/rails-real-email.gemspec
CHANGED
@@ -6,12 +6,12 @@ require 'rails/real/email/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rails-real-email"
|
8
8
|
spec.version = Rails::Real::Email::VERSION
|
9
|
-
spec.authors = ["
|
9
|
+
spec.authors = ["Libra-"]
|
10
10
|
spec.email = ["quanmn.libra@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = ""
|
13
|
-
spec.description = ""
|
14
|
-
spec.homepage = ""
|
12
|
+
spec.summary = "The Ruby Gem check the email address live for Ruby on Rails."
|
13
|
+
spec.description = "The Ruby Gem check the email address live for Ruby on Rails."
|
14
|
+
spec.homepage = "https://github.com/minhquan4080/rails-real-email"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-real-email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Libra-
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description: The Ruby Gem check the email address live for Ruby on Rails.
|
56
56
|
email:
|
57
57
|
- quanmn.libra@gmail.com
|
58
58
|
executables: []
|
@@ -73,7 +73,7 @@ files:
|
|
73
73
|
- lib/rails/real/email/mail_check.rb
|
74
74
|
- lib/rails/real/email/version.rb
|
75
75
|
- rails-real-email.gemspec
|
76
|
-
homepage:
|
76
|
+
homepage: https://github.com/minhquan4080/rails-real-email
|
77
77
|
licenses:
|
78
78
|
- MIT
|
79
79
|
metadata: {}
|
@@ -93,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.6.
|
96
|
+
rubygems_version: 2.6.8
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
|
-
summary:
|
99
|
+
summary: The Ruby Gem check the email address live for Ruby on Rails.
|
100
100
|
test_files: []
|