email_valid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/LICENSE +23 -0
- data/README.rdoc +47 -0
- data/Rakefile +47 -0
- data/lib/email.rb +4 -0
- data/lib/email/rfc822.rb +91 -0
- data/lib/email/valid.rb +53 -0
- data/lib/email/version.rb +3 -0
- data/test/email_valid/email_valid_test.rb +56 -0
- metadata +65 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
The MIT License
|
4
|
+
|
5
|
+
Copyright (c) 2010 Stephen Walker
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
=Email::Valid
|
2
|
+
|
3
|
+
Email::Valid is a simple class to check the validity of email addresses, copied from the perl Email::Valid module.
|
4
|
+
|
5
|
+
==Quick Start
|
6
|
+
|
7
|
+
if Email::Valid.address(email_address)
|
8
|
+
# do something
|
9
|
+
end
|
10
|
+
|
11
|
+
==Usage
|
12
|
+
|
13
|
+
Call the class method:
|
14
|
+
|
15
|
+
if Email::Valid.address(email_address)
|
16
|
+
# do something
|
17
|
+
end
|
18
|
+
|
19
|
+
or the instance methods:
|
20
|
+
|
21
|
+
email = Email::Valid.new(:check_domain => true, :check_rfc822 => true)
|
22
|
+
|
23
|
+
if email.valid(email_address)
|
24
|
+
# do something
|
25
|
+
else
|
26
|
+
raise "Invalid Email: #{email.errors.join ', '}"
|
27
|
+
end
|
28
|
+
|
29
|
+
Possible arguments to Email::Valid.new
|
30
|
+
|
31
|
+
:check_domain - checks the mx record for the domain, default true
|
32
|
+
|
33
|
+
:check_rfc822 - checks the address against the rfc822 pattern, default true
|
34
|
+
|
35
|
+
Other instance methods:
|
36
|
+
|
37
|
+
valid_domain(email) - returns true if it finds a valid mx record, false otherwise
|
38
|
+
|
39
|
+
valid_rfc822(email) - returns true if it matches the rfc822 pattern, false otherwise
|
40
|
+
|
41
|
+
==Credit
|
42
|
+
|
43
|
+
This is an incomplete adaptation of the perl Email::Valid module.
|
44
|
+
|
45
|
+
http://search.cpan.org/~rjbs/Email-Valid-0.184/lib/Email/Valid.pm
|
46
|
+
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
#require 'rspec/core/rake_task'
|
5
|
+
#Rspec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/testtask'
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
|
11
|
+
desc 'Default: run unit tests.'
|
12
|
+
task :default => [:clean, :test]
|
13
|
+
|
14
|
+
desc 'Test the email_valid plugin.'
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.libs << 'lib' << 'profile'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Clean up files.'
|
22
|
+
task :clean do |t|
|
23
|
+
FileUtils.rm_rf "doc"
|
24
|
+
FileUtils.rm_rf "tmp"
|
25
|
+
FileUtils.rm_rf "pkg"
|
26
|
+
FileUtils.rm "test/test.log" rescue nil
|
27
|
+
Dir.glob("email_valid-*.gem").each{|f| FileUtils.rm f }
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Generate documentation for the email_valid plugin.'
|
31
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
32
|
+
rdoc.rdoc_dir = 'doc'
|
33
|
+
rdoc.title = 'Email::Valid'
|
34
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
38
|
+
|
39
|
+
gemspec = eval(File.read("email_valid.gemspec"))
|
40
|
+
|
41
|
+
task :gem => "#{gemspec.full_name}.gem"
|
42
|
+
task :build => "#{gemspec.full_name}.gem"
|
43
|
+
|
44
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["email_valid.gemspec"] do
|
45
|
+
system "gem build email_valid.gemspec"
|
46
|
+
system "gem install email_valid-#{Email::VERSION}.gem"
|
47
|
+
end
|
data/lib/email.rb
ADDED
data/lib/email/rfc822.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Email
|
2
|
+
class Valid
|
3
|
+
|
4
|
+
# Regular expression built using Jeffrey Friedl's example in
|
5
|
+
# _Mastering Regular Expressions_ (http://www.ora.com/catalog/regexp/).
|
6
|
+
def rfc822
|
7
|
+
Regexp.new(/
|
8
|
+
[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]
|
9
|
+
*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)
|
10
|
+
[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])
|
11
|
+
|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*
|
12
|
+
(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
13
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*
|
14
|
+
)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
15
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)
|
16
|
+
[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])
|
17
|
+
|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*
|
18
|
+
(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
19
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)
|
20
|
+
[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
21
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
22
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
23
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]
|
24
|
+
|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
25
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
26
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
27
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
28
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
29
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]
|
30
|
+
|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
31
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
32
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
33
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*
|
34
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*
|
35
|
+
(?:(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
36
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)
|
37
|
+
|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")
|
38
|
+
[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*)*<[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
39
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
40
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
41
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
42
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
43
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])
|
44
|
+
[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
45
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*
|
46
|
+
(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
47
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*
|
48
|
+
(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])
|
49
|
+
|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
50
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
51
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
52
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
53
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
54
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
55
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
56
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]
|
57
|
+
|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
58
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)
|
59
|
+
[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*
|
60
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*
|
61
|
+
(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])
|
62
|
+
|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
63
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
64
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
65
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
66
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
67
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*
|
68
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
69
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
70
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
71
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
72
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
73
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*
|
74
|
+
(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
75
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)
|
76
|
+
*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
77
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
78
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
79
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]
|
80
|
+
|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
81
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
82
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*
|
83
|
+
(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
84
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+
|
85
|
+
(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]
|
86
|
+
|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]
|
87
|
+
|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))
|
88
|
+
[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*>)/ox)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/email/valid.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Email
|
2
|
+
class Valid
|
3
|
+
attr_accessor :check_domain, :check_rfc822, :errors
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# class method to check for email address validity
|
7
|
+
def address(email, args = {})
|
8
|
+
obj = self.new(args)
|
9
|
+
obj.valid(email)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
@errors = []
|
15
|
+
# check mx, default on
|
16
|
+
@check_domain = (args[:check_domain].nil? ? true : args[:check_domain])
|
17
|
+
|
18
|
+
# check pattern, default on
|
19
|
+
@check_rfc822 = (args[:check_rfc822].nil? ? true : args[:check_rfc822])
|
20
|
+
end
|
21
|
+
|
22
|
+
# checks email address for validity
|
23
|
+
def valid(email)
|
24
|
+
valid_rfc822(email) && valid_domain(email)
|
25
|
+
end
|
26
|
+
|
27
|
+
# checks against the rfc822 pattern
|
28
|
+
def valid_rfc822(email)
|
29
|
+
return true unless check_rfc822 == true
|
30
|
+
if email =~ rfc822
|
31
|
+
true
|
32
|
+
else
|
33
|
+
errors << "Does not conform to rfc822"
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# check for valid mx record
|
39
|
+
def valid_domain(email)
|
40
|
+
return true unless check_domain == true
|
41
|
+
domain = email.match(/\@(.+)/)[1]
|
42
|
+
Resolv::DNS.open do |dns|
|
43
|
+
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
44
|
+
end
|
45
|
+
if @mx.size > 0
|
46
|
+
true
|
47
|
+
else
|
48
|
+
errors << "Invalid Domain (no mx record)"
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# test_email_valid.rb
|
3
|
+
#
|
4
|
+
# Created by Stephen Walker on 2010-08-10.
|
5
|
+
# Copyright 2010 Stephen Walker. All rights reserved.
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'rubygems'
|
10
|
+
|
11
|
+
|
12
|
+
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
13
|
+
require 'email'
|
14
|
+
|
15
|
+
class Test::Unit::TestCase
|
16
|
+
end
|
17
|
+
|
18
|
+
class EmailValidTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@email_with_domain = Email::Valid.new(:check_domain => true, :check_rfc822 => true)
|
22
|
+
@email_witho_domain = Email::Valid.new(:check_domain => false, :check_rfc822 => true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_email_class_method
|
29
|
+
assert_equal true, Email::Valid.address('swalker@walkertek.com'), "Testing: swalker@walkertek.com"
|
30
|
+
assert_equal true, Email::Valid.address('swalker@blackboxweb.com'), "Testing: swalker@blackboxweb.com"
|
31
|
+
assert_equal false, Email::Valid.address('swalker@blackbox.us'), "Testing: swalker@blackbox.us"
|
32
|
+
assert_equal false, Email::Valid.address('swalker@com'), "Testing: swalker@com"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_email_valid
|
36
|
+
assert_equal true, @email_with_domain.valid('swalker@walkertek.com'), "Testing: swalker@walkertek.com"
|
37
|
+
assert_equal true, @email_with_domain.valid('swalker@blackboxweb.com'), "Testing: swalker@blackboxweb.com"
|
38
|
+
assert_equal false, @email_with_domain.valid('swalker@blackbox.us'), "Testing: swalker@blackbox.us"
|
39
|
+
assert_equal false, @email_with_domain.valid('swalker@com'), "Testing: swalker@com"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_email_valid_failures
|
43
|
+
assert_equal false, @email_with_domain.valid('swalker.walkertek.com'), "Testing: swalker.walkertek.com"
|
44
|
+
assert_equal false, @email_with_domain.valid('walkertek.com'), "Testing: walkertek.com"
|
45
|
+
assert_equal false, @email_with_domain.valid('swalker@.com'), "Testing: swalker@.com"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_email_valid_without_domain
|
49
|
+
assert_equal true, @email_witho_domain.valid('swalker@walkertek.com'), "Testing: swalker@walkertek.com"
|
50
|
+
assert_equal true, @email_witho_domain.valid('swalker@blackboxweb.com'), "Testing: swalker@blackboxweb.com"
|
51
|
+
assert_equal true, @email_witho_domain.valid('swalker@blackbox.us'), "Testing: swalker@blackbox.us"
|
52
|
+
assert_equal true, @email_witho_domain.valid('swalker@walkertek1.com'), "Testing: swalker@com"
|
53
|
+
assert_equal false, @email_witho_domain.valid('swalker@'), "Testing: swalker@"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_valid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Walker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-29 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Validate an email address
|
18
|
+
email:
|
19
|
+
- swalker@walkertek.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- lib/email/rfc822.rb
|
28
|
+
- lib/email/valid.rb
|
29
|
+
- lib/email/version.rb
|
30
|
+
- lib/email.rb
|
31
|
+
- LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- test/email_valid/email_valid_test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/stw/email_valid
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.3.6
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: email_valid
|
60
|
+
rubygems_version: 1.6.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Validate an email address
|
64
|
+
test_files: []
|
65
|
+
|