email_verifier 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -16,6 +16,7 @@ module EmailVerifier
16
16
  end
17
17
 
18
18
  def self.check(email)
19
+ return true if config.test_mode
19
20
  v = EmailVerifier::Checker.new(email)
20
21
  v.connect
21
22
  v.verify
@@ -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.on_load(:active_record) do
2
-
3
- module EmailVerifier
4
- module ValidatesEmailRealness
5
-
6
- module Validator
7
- class EmailRealnessValidator < ActiveModel::EachValidator
8
- def validate_each(record, attribute, value)
9
- begin
10
- record.errors.add attribute, I18n.t('errors.messages.email_verifier.email_not_real') unless EmailVerifier.check(value)
11
- rescue EmailVerifier::OutOfMailServersException
12
- record.errors.add attribute, I18n.t('errors.messages.email_verifier.out_of_mail_server')
13
- rescue EmailVerifier::NoMailServerException
14
- record.errors.add attribute, I18n.t('errors.messages.email_verifier.no_mail_server')
15
- rescue EmailVerifier::FailureException
16
- record.errors.add attribute, I18n.t('errors.messages.email_verifier.failure')
17
- rescue Exception
18
- record.errors.add attribute, I18n.t('errors.messages.email_verifier.exception')
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
- end
23
-
24
- module ClassMethods
25
- def validates_email_realness_of(*attr_names)
26
- validates_with ActiveRecord::Base::EmailRealnessValidator, _merge_attributes(attr_names)
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
@@ -1,3 +1,3 @@
1
1
  module EmailVerifier
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- en:
1
+ de:
2
2
  errors:
3
3
  messages:
4
4
  email_verifier:
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.9
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-03-06 00:00:00.000000000 Z
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