heycarsten-email-veracity 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008 Carsten Nielsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,67 @@
1
+ Email Veracity
2
+ ==============
3
+
4
+ A straight-forward Ruby library for checking the real-world validity of email
5
+ addresses.
6
+
7
+
8
+ ### It Can
9
+
10
+ * Validate email addresses for proper form against a pattern.
11
+ * Accept and reject addresses based whitelists and blacklists of domains.
12
+ * Check an address' domain for MX and/or A records.
13
+ * Be configured for a variety of use-cases, to be as discerning or as
14
+ indiscriminate as you would like.
15
+
16
+
17
+ ### It Can Not
18
+
19
+ * Validate all possible permutations of addresses to the RFC 2822
20
+ specification.
21
+
22
+
23
+ Using The Gem
24
+ -------------
25
+
26
+ In your project, you must require `email_veracity` after that you can try it
27
+ out, consider the following examples:
28
+
29
+
30
+ require 'email_veracity'
31
+
32
+ address = EmailVeracity::Address.new('heycarsten@gmail.com')
33
+
34
+ address.valid?
35
+ # => true
36
+
37
+ address.domain.to_s
38
+ # => 'gmail.com'
39
+
40
+ address.domain.address_servers.collect { |s| s.to_s }
41
+ # => ["64.233.171.83", "64.233.161.83", "209.85.171.83"]
42
+
43
+ address = EmailVeracity::Address.new('fakey@crazy-z3d9df-domain.com')
44
+
45
+ address.valid?
46
+ # => false
47
+
48
+ address.errors
49
+ # => [:no_address_servers]
50
+
51
+
52
+ As you can see, playing with the core library is pretty fun. The basic building
53
+ blocks are:
54
+
55
+ #### Address
56
+
57
+ Responsible for parsing full email addresses and checking for pattern-based
58
+ validity.
59
+
60
+ #### Domain
61
+
62
+ Contains methods to query the domain for information.
63
+
64
+ #### Resolver
65
+
66
+ Abstracts Resolv::DNS into a super-simple single public method, this is where
67
+ the timeout error is raised.
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # I used Haml as a template for these tasks: Thank you Nex3!
2
1
  require 'rubygems'
3
2
  require 'rake'
4
3
 
@@ -17,8 +16,8 @@ end
17
16
 
18
17
  ### Packaging
19
18
  require 'rake/gempackagetask'
20
- load 'email_veracity.gemspec'
21
- Rake::GemPackageTask.new(EMAIL_VERACITY_GEMSPEC) do |pkg|
19
+ load 'email_veracity.gemspec'
20
+ Rake::GemPackageTask.new(EV_GEMSPEC) do |pkg|
22
21
  if Rake.application.top_level_tasks.include?('release')
23
22
  pkg.need_tar_gz = true
24
23
  pkg.need_tar_bz2 = true
@@ -27,59 +26,12 @@ Rake::GemPackageTask.new(EMAIL_VERACITY_GEMSPEC) do |pkg|
27
26
  end
28
27
 
29
28
 
30
- task :revision_file do
31
- require 'lib/email_veracity'
32
-
33
- if EmailVeracity.version[:rev] && !Rake.application.top_level_tasks.include?('release')
34
- File.open('REVISION', 'w') { |f| f.puts EmailVeracity.version[:rev] }
35
- elsif Rake.application.top_level_tasks.include?('release')
36
- File.open('REVISION', 'w') { |f| f.puts '(release)' }
37
- else
38
- File.open('REVISION', 'w') { |f| f.puts '(unknown)' }
39
- end
40
- end
41
- Rake::Task[:package].prerequisites.insert(0, :revision_file)
42
-
43
- # We also need to get rid of this file after packaging.
44
- at_exit { File.delete('REVISION') rescue nil }
45
-
46
-
47
29
  task :install => [:package] do
48
30
  sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
49
- `#{sudo} gem install --no-ri pkg/email-veracity-#{File.read('VERSION').strip}`
31
+ `#{sudo} gem install --no-ri pkg/email-veracity-#{EV_VERSION}`
50
32
  end
51
33
 
52
34
 
53
- task :release => [:package] do
54
- name, version = ENV['NAME'], ENV['VERSION']
55
- raise "Must supply NAME and VERSION for release task." unless name && version
56
- `rubyforge login`
57
- `rubyforge add_release email-veracity email-veracity "#{name} (v#{version})" pkg/email-veracity-#{version}.gem`
58
- `rubyforge add_file email-veracity email-veracity "#{name} (v#{version})" pkg/email-veracity-#{version}.tar.gz`
59
- `rubyforge add_file email-veracity email-veracity "#{name} (v#{version})" pkg/email-veracity-#{version}.tar.bz2`
60
- `rubyforge add_file email-veracity email-veracity "#{name} (v#{version})" pkg/email-veracity-#{version}.zip`
61
- end
62
-
63
-
64
-
65
- ### Documentation
66
- require 'rake/rdoctask'
67
-
68
- Rake::RDocTask.new do |rdoc|
69
- rdoc.title = 'Email Veracity'
70
- rdoc.options << '--line-numbers' << '--inline-source'
71
- rdoc.rdoc_files.include(*FileList.new('*') do |list|
72
- list.exclude(/(^|[^.a-z])[a-z]+/)
73
- list.exclude('TODO')
74
- end.to_a)
75
- rdoc.rdoc_files.include('lib/**/*.rb')
76
- rdoc.rdoc_files.exclude('TODO')
77
- rdoc.rdoc_dir = 'rdoc'
78
- rdoc.main = 'README.rdoc'
79
- end
80
-
81
-
82
-
83
35
  ### Coverage
84
36
  require 'rcov/rcovtask'
85
37
 
@@ -5,7 +5,6 @@ require 'resolv'
5
5
  require 'timeout'
6
6
  require 'email_veracity/core_extensions'
7
7
  require 'email_veracity/validatability'
8
- require 'email_veracity/errors'
9
8
  require 'email_veracity/config'
10
9
  require 'email_veracity/server'
11
10
  require 'email_veracity/resolver'
@@ -15,42 +14,8 @@ require 'email_veracity/address'
15
14
 
16
15
  module EmailVeracity
17
16
 
18
- def self.version # :nodoc:
19
- return @@version if defined?(@@version)
20
-
21
- numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
22
-
23
- @@version = {
24
- :major => numbers[0],
25
- :minor => numbers[1],
26
- :teeny => numbers[2] }
27
-
28
- @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
29
-
30
- if File.exists?(scope('REVISION'))
31
- rev = File.read(scope('REVISION')).strip
32
- rev = nil if rev !~ /[a-f0-9]+/
33
- end
34
-
35
- if rev.nil? && File.exists?(scope('.git/HEAD'))
36
- rev = File.read(scope('.git/HEAD')).strip
37
- if rev =~ /^ref: (.*)$/
38
- rev = File.read(scope(".git/#{$1}")).strip
39
- end
40
- end
41
-
42
- if rev
43
- @@version[:rev] = rev
44
- @@version[:string] << "." << rev[0...7]
45
- end
46
-
47
- @@version
48
- end
49
-
50
- def self.scope(file) # :nodoc:
51
- File.join(File.dirname(__FILE__), '..', file)
52
- end
53
-
54
- VERSION = version[:string] unless defined?(EmailVeracity::VERSION)
17
+ class Error < StandardError; end
18
+ class MalformedEmailAddressError < Error; end
19
+ class DomainResourcesTimeoutError < Error; end
55
20
 
56
21
  end
@@ -8,7 +8,8 @@ module EmailVeracity
8
8
  rogers.com sympatico.ca yahoo.com telus.com sprint.com sprint.ca ],
9
9
  :blacklist => %w[ dodgeit.com mintemail.com mintemail.uni.cc
10
10
  1mintemail.mooo.com spammotel.com trashmail.net ],
11
- :valid_pattern => /\A(([\d\w\+_\-\.]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})){1}\Z/i,
11
+ :valid_pattern =>
12
+ /\A(([\w]+[\w\+_\-\.]+[\+_\-\.]{0})@((?:[-a-z0-9]+\.)+[a-z]{2,})){1}\Z/i,
12
13
  :timeout => 2,
13
14
  :lookup => [:a],
14
15
  :enforce_blacklist => false,
data/test/test_helper.rb CHANGED
@@ -1,15 +1,16 @@
1
+ require 'rubygems'
1
2
  require 'test/unit'
2
- require 'lib/email_veracity'
3
+ require 'mocha'
4
+ require File.dirname(__FILE__) + '/../lib/email_veracity'
3
5
  Dir.glob('test/mocks/*.rb') { |f| require(f) }
4
6
 
5
7
 
6
8
  class Test::Unit::TestCase
7
9
 
8
10
  def domain_names
9
- %w[ viarails.net heycarsten.com yahoo.com gmail.com savvica.com
10
- learnhub.com github.com google.com rogers.com amd.com adobe.com
11
- unspace.ca xerox.com webkit.org cooltown.net aiderss.com
12
- del.icio.us ]
11
+ %w[ viarails.net heycarsten.com yahoo.com gmail.com savvica.com
12
+ learnhub.com github.com google.com rogers.com amd.com adobe.com
13
+ unspace.ca xerox.com webkit.org cooltown.net aiderss.com del.icio.us ]
13
14
  end
14
15
 
15
16
  def assert_empty(array, message = nil)
@@ -25,20 +25,22 @@ class DefaultConfigurationAddressValidationsTest < Test::Unit::TestCase
25
25
 
26
26
  def test_a_well_formed_address_with_a_blacklisted_domain
27
27
  address = new_address('heycarsten@dodgeit.com')
28
- assert address.valid?,
29
- "Should be valid. @errors: #{address.errors.inspect}"
28
+ address.stubs(:domain).with(nil).
29
+ returns(stub(:errors => [:blacklisted]))
30
+ assert !address.valid?,"Should be valid. @errors: #{address.errors.inspect}"
30
31
  end
31
32
 
32
33
  def test_a_well_formed_address_that_does_not_exist
33
34
  address = new_address('heycarsten@i-surely-do-not-exist.nil')
34
- assert !address.valid?,
35
- 'Should not be valid.'
35
+ address.stubs(:domain).with(nil).
36
+ returns(stub(:errors => [:no_address_servers]))
37
+ assert !address.valid?, 'Should not be valid.'
36
38
  end
37
39
 
38
40
  def test_a_well_formed_address_that_exists
39
41
  address = new_address('itsme@heycarsten.com')
40
- assert address.valid?,
41
- "Should be valid. @errors: #{address.errors.inspect}"
42
+ address.stubs(:domain).with(nil).returns(stub(:errors => []))
43
+ assert address.valid?, "Should be valid. @errors: #{address.errors.inspect}"
42
44
  end
43
45
 
44
46
  private
@@ -95,6 +95,10 @@ class DefaultValidAddressPatternTest < Test::Unit::TestCase
95
95
  ungültige@adresse.de
96
96
  failure@10.0.0.1
97
97
  douche@@bag.net
98
+ -@fail.org
99
+ _@fail.org
100
+ +_-@fail.die
101
+ +___--@crashburn.net
98
102
  ].each do |address|
99
103
  assert_no_match EmailVeracity::Config[:valid_pattern],
100
104
  address,
@@ -5,9 +5,11 @@ class ArrayExtensionsTest < Test::Unit::TestCase
5
5
 
6
6
  def test_reject_blank_items
7
7
  array = [[], {}, '', nil, ' ', 'good times!']
8
- assert_equal ['good times!'], array.reject_blank_items, 'Should reject all blank and empty objects.'
8
+ assert_equal ['good times!'], array.reject_blank_items,
9
+ 'Should reject all blank and empty objects.'
9
10
  array = [{:neat => 'o'}, ['cool'], 1, 's']
10
- assert_equal array, array.reject_blank_items, 'Should not reject any filled or not-blank objects.'
11
+ assert_equal array, array.reject_blank_items,
12
+ 'Should not reject any filled or not-blank objects.'
11
13
  end
12
14
 
13
15
  def test_contains_single_item
@@ -31,23 +31,49 @@ class DomainTest < Test::Unit::TestCase
31
31
  assert_respond_to domain, :to_s, 'Should have a to_s method.'
32
32
  end
33
33
 
34
- def test_a_valid_domain_for_servers
35
- domain = new_domain('gmail.com')
36
- assert_not_empty domain.exchange_servers, 'Should contain mail servers.'
34
+ def test_a_valid_domain_for_address_servers
35
+ domain_name = 'gmail.com'
36
+ domain = new_domain(domain_name)
37
+ EmailVeracity::Resolver.expects(:get_servers_for).
38
+ with(domain_name.strip, :a).returns(["mail.#{domain_name}"])
37
39
  assert_not_empty domain.address_servers, 'Should contain address servers.'
38
40
  end
39
41
 
40
- def test_a_valid_domain_with_whitespace_for_servers
41
- domain = new_domain(' learnhub.com ')
42
+ def test_a_valid_domain_for_exchange_servers
43
+ domain_name = 'gmail.com'
44
+ domain = new_domain(domain_name)
45
+ EmailVeracity::Resolver.expects(:get_servers_for).
46
+ with(domain_name.strip, :mx).returns(["mail.#{domain_name}"])
42
47
  assert_not_empty domain.exchange_servers, 'Should contain mail servers.'
48
+ end
49
+
50
+ def test_a_valid_domain_with_whitespace_for_address_servers
51
+ domain_with_whitespace = ' learnhub.com '
52
+ domain = new_domain(domain_with_whitespace)
53
+ EmailVeracity::Resolver.expects(:get_servers_for).
54
+ with(domain_with_whitespace.strip, :a).returns(%w(mail.learnhub.com))
43
55
  assert_not_empty domain.address_servers, 'Should contain address servers.'
44
56
  end
45
57
 
46
- def test_an_invalid_domain_for_servers
58
+ def test_a_valid_domain_with_whitespace_for_exchange_servers
59
+ domain_with_whitespace = ' learnhub.com '
60
+ domain = new_domain(domain_with_whitespace)
61
+ EmailVeracity::Resolver.expects(:get_servers_for).
62
+ with(domain_with_whitespace.strip, :mx).returns(%w(mail.learnhub.com))
63
+ assert_not_empty domain.exchange_servers, 'Should contain address servers.'
64
+ end
65
+
66
+ def test_an_invalid_domain_for_address_servers
47
67
  domain = new_domain('i-surely-do-not.exist')
48
- assert_empty domain.exchange_servers, 'Should not contain exchange servers.'
68
+ domain.expects(:servers_in).with(:a).returns([])
49
69
  assert_empty domain.address_servers, 'Should not contain address servers.'
50
70
  end
71
+
72
+ def test_an_invalid_domain_for_exchange_servers
73
+ domain = new_domain('i-surely-do-not.exist')
74
+ domain.expects(:servers_in).with(:mx).returns([])
75
+ assert_empty domain.exchange_servers, 'Should not contain exchange servers.'
76
+ end
51
77
 
52
78
  def test_a_blank_domain_for_servers
53
79
  domain = new_domain('')
@@ -62,6 +88,8 @@ class DomainTest < Test::Unit::TestCase
62
88
 
63
89
  def test_for_errors_on_an_invalid_domain
64
90
  domain = new_domain('i-surely-do-not.exist')
91
+ domain.expects(:address_servers).returns([])
92
+ domain.expects(:exchange_servers).returns([])
65
93
  assert_not_empty domain.errors, 'Should have errors.'
66
94
  end
67
95
 
@@ -4,22 +4,26 @@ require File.dirname(__FILE__) + '/../test_helper'
4
4
  class ResolverTest < Test::Unit::TestCase
5
5
 
6
6
  def test_consecutive_queries
7
- EmailVeracity::Config[:timeout] = 60
7
+ domain_names.each do |domain_name|
8
+ EmailVeracity::Resolver.stubs(:get_resources_for).
9
+ with(domain_name, kind_of(Symbol)).returns(["mail.#{domain_name}"])
10
+ end
8
11
  assert_nothing_raised do
9
12
  domain_names.each do |domain|
10
- assert_instance_of Array,
11
- EmailVeracity::Resolver.get_servers_for(domain),
13
+ assert_instance_of Array, EmailVeracity::Resolver.get_servers_for(domain),
12
14
  'Should return an array of servers'
13
15
  end
14
16
  end
15
17
  end
16
18
 
17
19
  def test_timing_out_while_resolving_a_domain
18
- EmailVeracity::Config[:timeout] = 0.001
20
+ domain = 'learnhub.com'
21
+ timeout_exception = Timeout::Error.new('The connection has timed out')
22
+ EmailVeracity::Resolver.stubs(:get_resources_for).
23
+ with(domain, kind_of(Symbol)).raises(timeout_exception)
19
24
  assert_raise EmailVeracity::DomainResourcesTimeoutError, 'Should time out' do
20
- EmailVeracity::Resolver.get_servers_for('learnhub.com')
25
+ EmailVeracity::Resolver.get_servers_for(domain)
21
26
  end
22
- EmailVeracity::Config[:timeout] = 2
23
27
  end
24
28
 
25
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heycarsten-email-veracity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Nielsen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-06 00:00:00 -07:00
12
+ date: 2008-10-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,32 +19,26 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files:
23
- - README.rdoc
22
+ extra_rdoc_files: []
23
+
24
24
  files:
25
25
  - lib/email_veracity/address.rb
26
26
  - lib/email_veracity/config.rb
27
27
  - lib/email_veracity/core_extensions.rb
28
28
  - lib/email_veracity/domain.rb
29
- - lib/email_veracity/errors.rb
30
29
  - lib/email_veracity/resolver.rb
31
30
  - lib/email_veracity/server.rb
32
31
  - lib/email_veracity/validatability.rb
33
32
  - lib/email_veracity.rb
34
- - README.rdoc
35
- - VERSION
33
+ - README.markdown
34
+ - LICENSE
36
35
  - Rakefile
37
36
  - init.rb
38
- has_rdoc: true
37
+ has_rdoc: false
39
38
  homepage: http://github.com/heycarsten/email-veracity
40
39
  post_install_message:
41
- rdoc_options:
42
- - --title
43
- - Email Veracity
44
- - --main
45
- - README.rdoc
46
- - --line-numbers
47
- - --inline-source
40
+ rdoc_options: []
41
+
48
42
  require_paths:
49
43
  - lib
50
44
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -61,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
55
  version:
62
56
  requirements: []
63
57
 
64
- rubyforge_project:
58
+ rubyforge_project: email-veracity
65
59
  rubygems_version: 1.2.0
66
60
  signing_key:
67
61
  specification_version: 2
data/README.rdoc DELETED
@@ -1,72 +0,0 @@
1
- = Email Veracity
2
-
3
- A straight-forward Ruby library for checking the real-world validity of email
4
- addresses.
5
-
6
-
7
- === It Can
8
-
9
- * Validate email addresses for proper form against a pattern.
10
- * Accept and reject addresses based whitelists and blacklists of domains.
11
- * Check an address' domain for MX and/or A records.
12
- * Be configured for a variety of use-cases, to be as discerning or as
13
- indiscriminate as you would like.
14
-
15
-
16
- === It Can Not
17
-
18
- * Validate all possible permutations of addresses to the RFC 2822
19
- specification.
20
-
21
-
22
- == Using The Gem
23
-
24
- In your project, you must require +email_veracity+ after that you can try it
25
- out, consider the following examples:
26
-
27
-
28
- require 'email_veracity'
29
-
30
- address = EmailVeracity::Address.new('heycarsten@gmail.com')
31
-
32
- address.valid?
33
- # => true
34
-
35
- address.domain.to_s
36
- # => 'gmail.com'
37
-
38
- address.domain.address_servers.collect { |s| s.to_s }
39
- # => ["64.233.171.83", "64.233.161.83", "209.85.171.83"]
40
-
41
- address = EmailVeracity::Address.new('fakey@crazy-z3d9df-domain.com')
42
-
43
- address.valid?
44
- # => false
45
-
46
- address.errors
47
- # => [:no_address_servers]
48
-
49
-
50
- As you can see, playing with the core library is pretty fun. The basic building
51
- blocks are:
52
-
53
- ==== Address
54
-
55
- Responsible for parsing full email addresses and checking for pattern-based
56
- validity.
57
-
58
- ==== Domain
59
-
60
- Contains methods to query the domain for information.
61
-
62
- ==== Resolver
63
-
64
- Abstracts Resolv::DNS into a super-simple single public method, this is where
65
- the timeout error is raised.
66
-
67
-
68
- == Running The Tests
69
-
70
- A few of the tests will fail if you don't have a live connection to the
71
- internet, this is obviously not cool and it's high on my list of TODOs. [See
72
- TODO]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0
@@ -1,9 +0,0 @@
1
- module EmailVeracity
2
-
3
-
4
- class Error < StandardError; end
5
- class MalformedEmailAddressError < Error; end
6
- class DomainResourcesTimeoutError < Error; end
7
-
8
-
9
- end