rfc-822 0.2.1
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/.gitignore +1 -0
- data/LICENSE +22 -0
- data/README.textile +52 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/rfc822.rb +66 -0
- data/rfc-822.gemspec +51 -0
- data/spec/helper.rb +4 -0
- data/spec/rfc822_spec.rb +79 -0
- metadata +78 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
Copyright (C) 2009 Dimitrij Denissenko
|
3
|
+
Inspired by work of Cal Henderson, Tim Fletcher and Dan Kubb
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
h1. RFC822
|
2
|
+
|
3
|
+
RFC822 compatible email validation and MX record check.
|
4
|
+
|
5
|
+
|
6
|
+
h2. Features
|
7
|
+
|
8
|
+
* Ruby 1.8 & 1.9 compatible
|
9
|
+
* Email validation
|
10
|
+
* MX checks (requires 'host' command line application)
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
h2. Installation
|
15
|
+
|
16
|
+
h6. Download from GitHub
|
17
|
+
|
18
|
+
bc. wget http://github.com/dim/rfc-822/tarball/master
|
19
|
+
|
20
|
+
h6. As a GEM
|
21
|
+
|
22
|
+
bc. gem install rfc-822
|
23
|
+
|
24
|
+
h6. Clone from GitHub
|
25
|
+
|
26
|
+
bc. git clone git://github.com/dim/rfc-822.git
|
27
|
+
|
28
|
+
h6. As a Rails plugin
|
29
|
+
|
30
|
+
bc. ruby script/plugin install git://github.com/dim/rfc-822.git
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
h2. Usage Examples
|
35
|
+
|
36
|
+
bc. validates_format_of :email, :with => RFC822::EMAIL
|
37
|
+
|
38
|
+
bc. "user@example.com" =~ RFC822::EMAIL ? puts("Email is valid.") : puts("Email is invalid")
|
39
|
+
|
40
|
+
bc. RFC822.mx_records('user@mail.com') # => [#<struct RFC822::MXRecord priority=15, host="mailin-01.mx.aol.com">]
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
h2. License
|
45
|
+
|
46
|
+
Please see LICENSE document
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
h2. Acknowledgements
|
51
|
+
|
52
|
+
* Inspired by previous work of Cal Henderson, Tim Fletcher and Dan Kubb.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
require 'spec/version'
|
4
|
+
|
5
|
+
desc 'Default: run specs.'
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
Spec::Rake::SpecTask.new do |t|
|
9
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
10
|
+
t.spec_opts = ['--colour', '--format', 'profile', '--timeout', '20']
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gemspec|
|
16
|
+
gemspec.name = "rfc-822"
|
17
|
+
gemspec.summary = "RFC822 compatible email validation and MX record check"
|
18
|
+
gemspec.description = "RFC822 compatible email validation and MX record check"
|
19
|
+
gemspec.email = "dimitrij@blacksquaremedia.com"
|
20
|
+
gemspec.homepage = "http://github.com/dim/rfc-822"
|
21
|
+
gemspec.authors = ["Dimitrij Denissenko"]
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
26
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rfc822'
|
data/lib/rfc822.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module RFC822
|
5
|
+
|
6
|
+
module Patterns
|
7
|
+
|
8
|
+
def self.compile(string)
|
9
|
+
Regexp.new string, nil, 'n'
|
10
|
+
end
|
11
|
+
|
12
|
+
QTEXT = compile "[^\\x0d\\x22\\x5c\\x80-\\xff]"
|
13
|
+
DTEXT = compile "[^\\x0d\\x5b-\\x5d\\x80-\\xff]"
|
14
|
+
|
15
|
+
ATOM_CORE = compile "[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+"
|
16
|
+
ATOM_EDGE = compile "[^\\x00-\\x20\\x22\\x28\\x29\\x2c-\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]"
|
17
|
+
ATOM = compile "(?:#{ATOM_EDGE}{1,2}|#{ATOM_EDGE}#{ATOM_CORE}#{ATOM_EDGE})"
|
18
|
+
|
19
|
+
QPAIR = compile "\\x5c[\\x00-\\x7f]"
|
20
|
+
QSTRING = compile "\\x22(?:#{QTEXT}|#{QPAIR})*\\x22"
|
21
|
+
|
22
|
+
WORD = compile "(?:#{ATOM}|#{QSTRING})"
|
23
|
+
|
24
|
+
LOCAL_PT = compile "#{WORD}(?:\\x2e#{WORD})*"
|
25
|
+
ADDRESS = compile "#{LOCAL_PT}\\x40#{URI::REGEXP::PATTERN::HOSTNAME}"
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
MXRecord = Struct.new(:priority, :host)
|
30
|
+
EMAIL = /\A#{Patterns::ADDRESS}\z/
|
31
|
+
|
32
|
+
@@host_command = '/usr/bin/env host'
|
33
|
+
|
34
|
+
class << self
|
35
|
+
|
36
|
+
def host_command
|
37
|
+
@@host_command
|
38
|
+
end
|
39
|
+
|
40
|
+
def host_command=(value)
|
41
|
+
@@host_command = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def mx_records(address)
|
45
|
+
address = address.to_s
|
46
|
+
return [] unless address =~ EMAIL
|
47
|
+
|
48
|
+
Timeout::timeout(2) do
|
49
|
+
raw_mx_records(address.split('@').last).map do |priority, host|
|
50
|
+
MXRecord.new(priority.to_i, host)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
rescue Timeout::Error
|
54
|
+
[]
|
55
|
+
end
|
56
|
+
|
57
|
+
def raw_mx_records(domain)
|
58
|
+
host_mx(domain).scan(/#{Regexp.escape(domain)}[\w ]+?(\d+) (#{URI::REGEXP::PATTERN::HOSTNAME})\./)
|
59
|
+
end
|
60
|
+
|
61
|
+
def host_mx(domain)
|
62
|
+
`#{host_command} -t MX #{domain}`
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/rfc-822.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rfc-822}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dimitrij Denissenko"]
|
12
|
+
s.date = %q{2010-08-04}
|
13
|
+
s.description = %q{RFC822 compatible email validation and MX record check}
|
14
|
+
s.email = %q{dimitrij@blacksquaremedia.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.textile",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/rfc822.rb",
|
27
|
+
"rfc-822.gemspec",
|
28
|
+
"spec/helper.rb",
|
29
|
+
"spec/rfc822_spec.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/dim/rfc-822}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
|
+
s.summary = %q{RFC822 compatible email validation and MX record check}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/rfc822_spec.rb",
|
38
|
+
"spec/helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/spec/helper.rb
ADDED
data/spec/rfc822_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe RFC822 do
|
4
|
+
|
5
|
+
after do
|
6
|
+
RFC822.host_command = '/usr/bin/env host'
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'email pattern' do
|
10
|
+
|
11
|
+
it 'should match RFC822 compliant addresses' do
|
12
|
+
"user@home".should match(RFC822::EMAIL)
|
13
|
+
"user@home.com".should match(RFC822::EMAIL)
|
14
|
+
"user@dashed-home.info".should match(RFC822::EMAIL)
|
15
|
+
"user@separated.home.info".should match(RFC822::EMAIL)
|
16
|
+
"dashed-user@home.com".should match(RFC822::EMAIL)
|
17
|
+
"underscored_user@home.com".should match(RFC822::EMAIL)
|
18
|
+
"separated.user@home.com".should match(RFC822::EMAIL)
|
19
|
+
"slashed/user@home.com".should match(RFC822::EMAIL)
|
20
|
+
"plussed+user@home.com".should match(RFC822::EMAIL)
|
21
|
+
"{wrapped}user@home.com".should match(RFC822::EMAIL)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should not match non-RFC822 compliant addresses' do
|
25
|
+
"user-home".should_not match(RFC822::EMAIL)
|
26
|
+
"@home.com".should_not match(RFC822::EMAIL)
|
27
|
+
"user@".should_not match(RFC822::EMAIL)
|
28
|
+
"user@underscored_home.org".should_not match(RFC822::EMAIL)
|
29
|
+
"user@just,wrong.org".should_not match(RFC822::EMAIL)
|
30
|
+
"user@just/wrong.org".should_not match(RFC822::EMAIL)
|
31
|
+
"user@just wrong.org".should_not match(RFC822::EMAIL)
|
32
|
+
"wrong,user@home.com".should_not match(RFC822::EMAIL)
|
33
|
+
"wrong-user.@home.com".should_not match(RFC822::EMAIL)
|
34
|
+
"wrong@user@home.com".should_not match(RFC822::EMAIL)
|
35
|
+
"wrong user@home.com".should_not match(RFC822::EMAIL)
|
36
|
+
"wrong(user)@home.com".should_not match(RFC822::EMAIL)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should allow to change the host command' do
|
42
|
+
RFC822.host_command.should == '/usr/bin/env host'
|
43
|
+
RFC822.host_command = '/opt/bin host'
|
44
|
+
RFC822.host_command.should == '/opt/bin host'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'MX record check' do
|
48
|
+
|
49
|
+
before do
|
50
|
+
RFC822.stub!(:host_mx).and_return(%Q(
|
51
|
+
hotmail.com mail is handled by 5 mx3.hotmail.com.
|
52
|
+
hotmail.com mail is handled by 5 mx4.hotmail.com.
|
53
|
+
hotmail.com mail is handled by 5 mx1.hotmail.com.
|
54
|
+
hotmail.com mail is handled by 5 mx2.hotmail.com.
|
55
|
+
))
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return raw MX records fo a domain' do
|
59
|
+
RFC822.raw_mx_records('hotmail.com').should == [
|
60
|
+
["5", "mx3.hotmail.com"],
|
61
|
+
["5", "mx4.hotmail.com"],
|
62
|
+
["5", "mx1.hotmail.com"],
|
63
|
+
["5", "mx2.hotmail.com"]
|
64
|
+
]
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return prioritised MX records of an address' do
|
68
|
+
RFC822.mx_records('user@hotmail.com').should have(4).items
|
69
|
+
record = RFC822.mx_records('user@hotmail.com').first
|
70
|
+
record.priority.should == 5
|
71
|
+
record.host.should == "mx3.hotmail.com"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return an empty result if address is invalid' do
|
75
|
+
RFC822.mx_records('user@hotmail@com').should == []
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rfc-822
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dimitrij Denissenko
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-04 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: RFC822 compatible email validation and MX record check
|
23
|
+
email: dimitrij@blacksquaremedia.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.textile
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.textile
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- init.rb
|
38
|
+
- lib/rfc822.rb
|
39
|
+
- rfc-822.gemspec
|
40
|
+
- spec/helper.rb
|
41
|
+
- spec/rfc822_spec.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/dim/rfc-822
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.7
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: RFC822 compatible email validation and MX record check
|
76
|
+
test_files:
|
77
|
+
- spec/rfc822_spec.rb
|
78
|
+
- spec/helper.rb
|