mail_box_validator 0.0.1 → 0.9.0

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
2
  SHA1:
3
- metadata.gz: c60f4e9d6e41a128613f40fd1831707256c8114c
4
- data.tar.gz: aef7afda1fd4fd4846217c7086c56d3659d2c02d
3
+ metadata.gz: b4dfe300c33d9814590f119f978dd32c7ef4e630
4
+ data.tar.gz: c61cbfba40995c3ac6ecccbe803e6524abcbd5ad
5
5
  SHA512:
6
- metadata.gz: 5ccc096672d3be4ada6953bdde5aeed0366433135058721f555f19ae2a075478438219688fe109ce9a25624f1822a5d1b414a7809e530f8fde8a01abe2bde26c
7
- data.tar.gz: 784c82cd4c9b1fdbb653f3a59385860b22628b7412d60b4af741698d5e2d62be34d91b03737b2f891df02c33cad0b0cbd683448c470995bb44a6c2cbcdb00009
6
+ metadata.gz: 9514b1ee70388e43bdc30f6f839b3e328e9c4acafc77a13cdfe1bc4c63d1d45fa4d0b583f3c3f5966f0530b2adc970413246984b701b1818c16ab4a324e2383e
7
+ data.tar.gz: 8950c6565d3d5297a29e19fecaafc466222fff30177a77100a35c7864b0cb117d713ddd63749f16dee4d2009ca580392d9415fb68507add3dcca0c8085b0fe1c
@@ -0,0 +1,37 @@
1
+ require 'net/telnet'
2
+
3
+ module MailBoxValidator
4
+ class MailBox
5
+ include Singleton
6
+
7
+ def valid?(mail_address)
8
+ domain = mail_address.slice(/@(.*)/, 1)
9
+ mx = mail_exchanger_record_for(domain)
10
+ return false unless mx.present?
11
+ mx.all? {|host| response_for(mail_address, host).match(/^2\d{2}/).present? }
12
+ end
13
+
14
+ private
15
+
16
+ def response_for(mail_address, host)
17
+ response = ''
18
+ telnet = Net::Telnet::new(
19
+ 'Host' => host,
20
+ 'Port' => 25,
21
+ 'Telnetmode' => true,
22
+ 'Prompt' => /\d{3}.*/n
23
+ )
24
+ telnet.cmd('helo hi')
25
+ telnet.cmd("mail from: <#{mail_address}>")
26
+ telnet.cmd("rcpt to: <#{mail_address}>") { |c| response = c }
27
+ telnet.close
28
+ response
29
+ end
30
+
31
+ def mail_exchanger_record_for(domain)
32
+ Resolv::DNS.open do |dns|
33
+ dns.getresources(domain, Resolv::DNS::Resource::IN::MX).map { |r| r.exchange.to_s }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module MailBoxValidator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require "mail_box_validator/version"
2
-
2
+ require "mail_box_validator/mail_box"
3
3
  module MailBoxValidator
4
- # Your code goes here...
4
+
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_box_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bidu Developers
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/mail_box_validator.rb
54
+ - lib/mail_box_validator/mail_box.rb
54
55
  - lib/mail_box_validator/version.rb
55
56
  - mail_box_validator.gemspec
56
57
  homepage: ''