email_detected 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 347e647a4741ba319e4af10c64e7efd367bf8d5d
4
- data.tar.gz: 1267dab70b3fbdce14049bed1380978ad0c67494
2
+ SHA256:
3
+ metadata.gz: bc4669438d6c88db760bea1d85e9d19c5057782d023236c29dacbdbf3b5a1897
4
+ data.tar.gz: c8eed2b71c6aa4ec60958d86a69a6dbcd7a42d4d0042fc361c3eec682adbb16d
5
5
  SHA512:
6
- metadata.gz: 447f8551a3cf83e5dfe843a6d70e073980ed1c8459f2ac9761c1811c0d2ce5a349af17a491578dbb70482b246123e3696cdf9f00bef82caeeb68aafcec1b3654
7
- data.tar.gz: b0e2086071e5f9a358334402b3b943c31a6ef68c47510fe5baf1fbb306cbdd771e3e5007792741b4474f227bce2d4e34046d4440d52ed9cfb5d96fa70e37cd1d
6
+ metadata.gz: 6c14ac2e596f4a72dff52cf8b3bc2bcc980eb864c85184388b977bffef20eaf71bfa3aa135b93ec7aa8b10d6993844121bc97a321d92f600f3f116b7ee5675a9
7
+ data.tar.gz: 30416b73c74a9443bff72672e4b91d6b3d0095bdadc7729bb3fad47bf742f16827eb8cf0db17dbb7ac43da9e6145ecde94ac77974694ba86650acd0051d7bf09
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Email Detected
2
2
 
3
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5445a5fe4bca464c8f2b055e09e2fd73)](https://www.codacy.com/app/quanmn.libra/email_detected_2?utm_source=github.com&utm_medium=referral&utm_content=minhquan4080/email_detected&utm_campaign=badger)
4
+ [![CircleCI](https://circleci.com/gh/minhquan4080/email_detected/tree/master.svg?style=svg)](https://circleci.com/gh/minhquan4080/email_detected/tree/master)
5
+
3
6
  Email Detected is a simple tool for verifying an email address exists. It's free and quite easy to use :smile: .
4
7
 
5
8
  Many times as developers we were putting validation statements for checking email addresses format. This gem will complete your existing setups with validator that actually connects with a given mail server and asks if the address in question exists for real.
@@ -30,7 +33,7 @@ First thing you need to set up is placing something like this either in initiali
30
33
 
31
34
  ```ruby
32
35
  EmailDetected.config do |config|
33
- config.verifier_email = "quannguyen@bestcoder.info"
36
+ config.verifier_email = "youremail@email.com"
34
37
  end
35
38
  ```
36
39
 
@@ -1,27 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "email_detected/version"
5
+ require 'email_detected/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "email_detected"
8
+ spec.name = 'email_detected'
8
9
  spec.version = EmailDetected::VERSION
9
- spec.authors = ["Nguyen Quan"]
10
- spec.email = ["quannguyen@bestcoder.info"]
10
+ spec.authors = ['Nguyen Quan']
11
+ spec.email = ['quannguyen@bestcoder.info']
11
12
 
12
- spec.summary = %q{Email Detected help checking email address is real.}
13
- spec.description = %q{Email Detected is a simple tool for verifying an email address exists. It's free and quite easy to use :smile: .Many times as developers we were putting validation statements for checking email addresses format. This gem will complete your existing setups with validator that actually connects with a given mail server and asks if the address in question exists for real.}
14
- spec.homepage = "https://github.com/minhquan4080/email_detected"
15
- spec.license = "MIT"
13
+ spec.summary = 'Email Detected help checking email address is real.'
14
+ spec.description = "Email Detected is a simple tool for verifying an email address exists. It's free and quite easy to use :smile: .Many times as developers we were putting validation statements for checking email addresses format. This gem will complete your existing setups with validator that actually connects with a given mail server and asks if the address in question exists for real."
15
+ spec.homepage = 'https://github.com/dereknguyen269/email_detected'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
19
20
  end
20
- spec.bindir = "exe"
21
+ spec.bindir = 'exe'
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
27
28
  end
@@ -1,38 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'resolv'
2
4
  require 'net/smtp'
3
5
 
4
6
  class EmailDetected::Checker < Net::SMTP
5
-
6
7
  class MailCheckStatus
7
8
  attr_accessor :errors
8
9
 
9
10
  def self.rcpt_responses
10
11
  @@rcpt_responses ||=
11
- {
12
- -1 => :fail, # Validation failed (non-SMTP)
13
- 250 => :valid, # Requested mail action okay, completed
14
- 251 => :dunno, # User not local; will forward to <forward-path>
15
- 550 => :invalid, # Requested action not taken:, mailbox unavailable
16
- 551 => :dunno, # User not local; please try <forward-path>
17
- 552 => :valid, # Requested mail action aborted:, exceeded storage allocation
18
- 553 => :invalid, # Requested action not taken:, mailbox name not allowed
19
- 450 => :valid_fails, # Requested mail action not taken:, mailbox unavailable
20
- 451 => :valid_fails, # Requested action aborted:, local error in processing
21
- 452 => :valid_fails, # Requested action not taken:, insufficient system storage
22
- 500 => :fail, # Syntax error, command unrecognised
23
- 501 => :invalid, # Syntax error in parameters or arguments
24
- 503 => :fail, # Bad sequence of commands
25
- 521 => :invalid, # <domain> does not accept mail [rfc1846]
26
- 421 => :fail, # <domain> Service not available, closing transmission channel
27
- }
12
+ {
13
+ -1 => :fail, # Validation failed (non-SMTP)
14
+ 250 => :valid, # Requested mail action okay, completed
15
+ 251 => :dunno, # User not local; will forward to <forward-path>
16
+ 550 => :invalid, # Requested action not taken:, mailbox unavailable
17
+ 551 => :dunno, # User not local; please try <forward-path>
18
+ 552 => :valid, # Requested mail action aborted:, exceeded storage allocation
19
+ 553 => :invalid, # Requested action not taken:, mailbox name not allowed
20
+ 450 => :valid_fails, # Requested mail action not taken:, mailbox unavailable
21
+ 451 => :valid_fails, # Requested action aborted:, local error in processing
22
+ 452 => :valid_fails, # Requested action not taken:, insufficient system storage
23
+ 500 => :fail, # Syntax error, command unrecognised
24
+ 501 => :invalid, # Syntax error in parameters or arguments
25
+ 503 => :fail, # Bad sequence of commands
26
+ 521 => :invalid, # <domain> does not accept mail [rfc1846]
27
+ 421 => :fail # <domain> Service not available, closing transmission channel
28
+ }
28
29
  end
29
30
 
30
31
  def initialize(response_code, error = nil)
31
- errors = Array.new
32
- unless error.nil?
33
- errors.push(EmailDetected::MESSAGES[response_code])
34
- end
35
- @response = (self.class.rcpt_responses.has_key?(response_code) ?
32
+ errors = []
33
+ errors.push(EmailDetected::MESSAGES[response_code]) unless error.nil?
34
+ @response = (self.class.rcpt_responses.key?(response_code) ?
36
35
  response_code : -1)
37
36
  @errors = errors
38
37
  end
@@ -50,18 +49,18 @@ class EmailDetected::Checker < Net::SMTP
50
49
 
51
50
  # true if verified address is known to be valid
52
51
  def valid?
53
- [:valid, :valid_fails].include? self.status
52
+ %i[valid valid_fails].include? status
54
53
  end
55
54
 
56
55
  # true if verified address is known to be invalid
57
56
  def invalid?
58
- self.status == :invalid
57
+ status == :invalid
59
58
  end
60
59
  end
61
60
 
62
61
  def self.run(addr, server = nil, decoy_from = nil)
63
62
  # FIXME: needs a better mail address parser
64
- server = get_mail_server(addr[(addr.index('@')+1)..-1]) if server.nil?
63
+ server = get_mail_server(addr[(addr.index('@') + 1)..-1]) if server.nil?
65
64
 
66
65
  # This only needs to be something the receiving SMTP server
67
66
  # accepts. We aren't actually sending any mail.
@@ -73,20 +72,21 @@ class EmailDetected::Checker < Net::SMTP
73
72
  ret = MailCheckStatus.new(ret.status.to_i)
74
73
  end
75
74
  rescue Net::SMTPAuthenticationError,
76
- Net::SMTPServerBusy,
77
- Net::SMTPSyntaxError,
78
- Net::SMTPFatalError,
79
- Net::SMTPUnknownError => error
80
- ret = MailCheckStatus.new(error.to_s[0..2].to_i, error)
81
- rescue IOError, TimeoutError, ArgumentError => error
82
- ret = MailCheckStatus.new(-1, error)
75
+ Net::SMTPServerBusy,
76
+ Net::SMTPSyntaxError,
77
+ Net::SMTPFatalError,
78
+ Net::SMTPUnknownError => e
79
+ ret = MailCheckStatus.new(e.to_s[0..2].to_i, e)
80
+ rescue IOError, TimeoutError, ArgumentError => e
81
+ ret = MailCheckStatus.new(-1, e)
83
82
  end
84
- return ret
83
+ ret
85
84
  end
86
85
 
87
86
  def check_mail_addr(to_addr, decoy_from = nil)
88
87
  raise IOError, 'closed session' unless @socket
89
88
  raise ArgumentError, 'mail destination not given' if to_addr.empty?
89
+
90
90
  mailfrom decoy_from
91
91
  rcptto to_addr
92
92
  end
@@ -95,9 +95,9 @@ class EmailDetected::Checker < Net::SMTP
95
95
  res = Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::MX)
96
96
  unless res.empty?
97
97
  # FIXME: should return the whole list
98
- return res.sort {|x,y| x.preference <=> y.preference}.first.exchange.to_s
98
+ return res.min { |x, y| x.preference <=> y.preference }.exchange.to_s
99
99
  end
100
+
100
101
  nil
101
102
  end
102
-
103
103
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(ActiveSupport)
2
4
  ActiveSupport.on_load(:active_record) do
3
5
  module EmailDetected
@@ -9,16 +11,17 @@ if defined?(ActiveSupport)
9
11
  def validate_each(record, attribute, value)
10
12
  begin
11
13
  m = Mail::Address.new(value)
12
- r = m.domain!=nil && m.domain.match('\.') && m.address == value
14
+ r = !m.domain.nil? && m.domain.match('\.') && m.address == value
13
15
  r = EmailDetected.exist? m.address
14
16
  r = r[:status]
15
- rescue
17
+ rescue StandardError
16
18
  r = false
17
19
  end
18
- record.errors[attribute] << (options[:message] || "does not exist") unless r
20
+ unless r
21
+ record.errors[attribute] << (options[:message] || 'does not exist')
22
+ end
19
23
  end
20
24
  end
21
-
22
25
  end
23
26
 
24
27
  module ClassMethods
@@ -26,11 +29,10 @@ if defined?(ActiveSupport)
26
29
  validates_with ActiveRecord::Base::EmailExistValidator, _merge_attributes(attr_names)
27
30
  end
28
31
  end
29
-
30
32
  end
31
33
  end
32
34
 
33
- ActiveRecord::Base.send(:include, EmailDetected::ValidatesExistEmail::Validator)
34
- ActiveRecord::Base.send(:extend, EmailDetected::ValidatesExistEmail::ClassMethods)
35
+ ActiveRecord::Base.include EmailDetected::ValidatesExistEmail::Validator
36
+ ActiveRecord::Base.extend EmailDetected::ValidatesExistEmail::ClassMethods
35
37
  end
36
38
  end
@@ -1,3 +1,3 @@
1
1
  module EmailDetected
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,4 +1,6 @@
1
- require "email_detected/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'email_detected/version'
2
4
 
3
5
  module EmailDetected
4
6
  require 'email_detected/config'
@@ -6,16 +8,20 @@ module EmailDetected
6
8
  require 'email_detected/messages'
7
9
  require 'email_detected/validates_exist_email'
8
10
 
9
- VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
11
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.freeze
10
12
 
11
13
  def self.exist?(email)
12
14
  return true if config.test_mode
13
- return { status: false, message: 'The email address invalid.' } unless email.match VALID_EMAIL_REGEX
15
+ unless email.match VALID_EMAIL_REGEX
16
+ return { status: false, message: 'The email address invalid.' }
17
+ end
18
+
14
19
  email_detected = EmailDetected::Checker.run(email)
15
20
  if email_detected.invalid?
16
21
  resp = { status: false, message: email_detected.errors.first }
17
22
  else
18
- resp = { status: true, message: 'The email address has already been registered.' }
23
+ message = email_detected.errors.first || 'The email address has already been registered.'
24
+ resp = { status: true, message: message }
19
25
  end
20
26
  resp
21
27
  end
@@ -27,5 +33,4 @@ module EmailDetected
27
33
  EmailDetected::Config
28
34
  end
29
35
  end
30
-
31
36
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_detected
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nguyen Quan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2020-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '0'
55
55
  description: 'Email Detected is a simple tool for verifying an email address exists.
56
56
  It''s free and quite easy to use :smile: .Many times as developers we were putting
57
57
  validation statements for checking email addresses format. This gem will complete
@@ -80,7 +80,7 @@ files:
80
80
  - lib/email_detected/messages.rb
81
81
  - lib/email_detected/validates_exist_email.rb
82
82
  - lib/email_detected/version.rb
83
- homepage: https://github.com/minhquan4080/email_detected
83
+ homepage: https://github.com/dereknguyen269/email_detected
84
84
  licenses:
85
85
  - MIT
86
86
  metadata: {}
@@ -99,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.8
102
+ rubygems_version: 3.1.2
104
103
  signing_key:
105
104
  specification_version: 4
106
105
  summary: Email Detected help checking email address is real.