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 +4 -4
- data/lib/mail_box_validator/mail_box.rb +37 -0
- data/lib/mail_box_validator/version.rb +1 -1
- data/lib/mail_box_validator.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4dfe300c33d9814590f119f978dd32c7ef4e630
|
4
|
+
data.tar.gz: c61cbfba40995c3ac6ecccbe803e6524abcbd5ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/mail_box_validator.rb
CHANGED
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
|
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: ''
|