email_verifier 0.0.9 → 0.1.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.
- data/README.md +15 -1
- data/email_verifier.gemspec +0 -1
- data/lib/email_verifier.rb +1 -0
- data/lib/email_verifier/config.rb +5 -0
- data/lib/email_verifier/validates_email_realness.rb +29 -27
- data/lib/email_verifier/version.rb +1 -1
- data/locales/de.yml +1 -1
- metadata +2 -18
data/README.md
CHANGED
@@ -14,6 +14,7 @@ It also:
|
|
14
14
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
|
+
# place it at the bottom of rails/activesupport if you're working with them.
|
17
18
|
gem 'email_verifier'
|
18
19
|
|
19
20
|
And then execute:
|
@@ -44,6 +45,19 @@ Or - if you'd like to use it outside of your models:
|
|
44
45
|
|
45
46
|
This method will return true or false, or will throw an exception with nicely detailed info about what's wrong.
|
46
47
|
|
48
|
+
## Important: problems when using locally
|
49
|
+
|
50
|
+
When you're trying to use it from an IP that a server either cannot reach or trust (in any way) - then it returns 421 service not available (connection refused, too many connections) instead of letting you connect. Because of this you should most probably always be using it on a machine that the other SMTP server can reach.
|
51
|
+
|
52
|
+
## Disabling on Test
|
53
|
+
|
54
|
+
If you are using Rails in test environment, the check will always succeed, so that your CI servers will not try to contact SMTP servers.
|
55
|
+
You can change that behavior in the configuration block:
|
56
|
+
|
57
|
+
EmailVerifier.config do |config|
|
58
|
+
config.test_mode = Rails.env.test?
|
59
|
+
end
|
60
|
+
|
47
61
|
## Customizing messages
|
48
62
|
|
49
63
|
Add these lines to your locale file in config/locales:
|
@@ -51,7 +65,7 @@ Add these lines to your locale file in config/locales:
|
|
51
65
|
it:
|
52
66
|
errors:
|
53
67
|
messages:
|
54
|
-
email_verifier:
|
68
|
+
email_verifier:
|
55
69
|
email_not_real: must point to a real mail account
|
56
70
|
out_of_mail_server: appears to point to dead mail server
|
57
71
|
no_mail_server: appears to point to domain which doesn't handle e-mail
|
data/email_verifier.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
gem.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
20
19
|
gem.add_runtime_dependency(%q<dnsruby>, [">= 1.5"])
|
21
20
|
gem.license = 'MIT'
|
22
21
|
end
|
data/lib/email_verifier.rb
CHANGED
@@ -2,9 +2,14 @@ module EmailVerifier
|
|
2
2
|
module Config
|
3
3
|
class << self
|
4
4
|
attr_accessor :verifier_email
|
5
|
+
attr_accessor :test_mode
|
5
6
|
|
6
7
|
def reset
|
7
8
|
@verifier_email = "nobody@nonexistant.com"
|
9
|
+
@test_mode = false
|
10
|
+
if defined?(Rails) and defined?(Rails.env) and Rails.env.test?
|
11
|
+
@test_mode = true
|
12
|
+
end
|
8
13
|
end
|
9
14
|
end
|
10
15
|
self.reset
|
@@ -1,35 +1,37 @@
|
|
1
|
-
ActiveSupport
|
2
|
-
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
if defined?(ActiveSupport)
|
2
|
+
ActiveSupport.on_load(:active_record) do
|
3
|
+
|
4
|
+
module EmailVerifier
|
5
|
+
module ValidatesEmailRealness
|
6
|
+
|
7
|
+
module Validator
|
8
|
+
class EmailRealnessValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
begin
|
11
|
+
record.errors.add attribute, I18n.t('errors.messages.email_verifier.email_not_real') unless EmailVerifier.check(value)
|
12
|
+
rescue EmailVerifier::OutOfMailServersException
|
13
|
+
record.errors.add attribute, I18n.t('errors.messages.email_verifier.out_of_mail_server')
|
14
|
+
rescue EmailVerifier::NoMailServerException
|
15
|
+
record.errors.add attribute, I18n.t('errors.messages.email_verifier.no_mail_server')
|
16
|
+
rescue EmailVerifier::FailureException
|
17
|
+
record.errors.add attribute, I18n.t('errors.messages.email_verifier.failure')
|
18
|
+
rescue Exception
|
19
|
+
record.errors.add attribute, I18n.t('errors.messages.email_verifier.exception')
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
def validates_email_realness_of(*attr_names)
|
27
|
+
validates_with ActiveRecord::Base::EmailRealnessValidator, _merge_attributes(attr_names)
|
28
|
+
end
|
27
29
|
end
|
30
|
+
|
28
31
|
end
|
29
|
-
|
30
32
|
end
|
33
|
+
|
34
|
+
ActiveRecord::Base.send(:include, EmailVerifier::ValidatesEmailRealness::Validator)
|
35
|
+
ActiveRecord::Base.send(:extend, EmailVerifier::ValidatesEmailRealness::ClassMethods)
|
31
36
|
end
|
32
|
-
|
33
|
-
ActiveRecord::Base.send(:include, EmailVerifier::ValidatesEmailRealness::Validator)
|
34
|
-
ActiveRecord::Base.send(:extend, EmailVerifier::ValidatesEmailRealness::ClassMethods)
|
35
37
|
end
|
data/locales/de.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_verifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rails
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0.0
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.0.0
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: dnsruby
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|