email_address 0.0.1 → 0.0.2

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +99 -32
  4. data/email_address.gemspec +2 -1
  5. data/lib/email_address.rb +14 -142
  6. data/lib/email_address/address.rb +70 -0
  7. data/lib/email_address/config.rb +75 -0
  8. data/lib/email_address/domain_matcher.rb +90 -0
  9. data/lib/email_address/domain_parser.rb +71 -0
  10. data/lib/email_address/exchanger.rb +67 -0
  11. data/lib/email_address/host.rb +71 -1
  12. data/lib/email_address/local.rb +97 -0
  13. data/lib/email_address/validator.rb +135 -0
  14. data/lib/email_address/version.rb +1 -1
  15. data/test/email_address/test_address.rb +30 -0
  16. data/test/email_address/test_config.rb +13 -0
  17. data/test/email_address/test_domain_matcher.rb +15 -0
  18. data/test/email_address/test_domain_parser.rb +29 -0
  19. data/test/email_address/test_exchanger.rb +19 -0
  20. data/test/email_address/test_host.rb +43 -0
  21. data/test/email_address/test_local.rb +27 -0
  22. data/test/email_address/test_validator.rb +16 -0
  23. data/test/test_email_address.rb +12 -0
  24. metadata +40 -27
  25. data/lib/email_address/esp.rb +0 -4
  26. data/lib/email_address/providers/default.rb +0 -8
  27. data/lib/email_address/providers/google.rb +0 -8
  28. data/lib/email_providers/address.rb +0 -102
  29. data/lib/email_providers/config.rb +0 -36
  30. data/lib/email_providers/factory.rb +0 -17
  31. data/lib/email_providers/host.rb +0 -87
  32. data/lib/email_providers/mail_exchanger.rb +0 -60
  33. data/lib/email_providers/mailbox.rb +0 -44
  34. data/lib/email_providers/providers/default.rb +0 -55
  35. data/lib/email_providers/providers/google.rb +0 -27
  36. data/lib/email_providers/version.rb +0 -3
  37. data/test/email_address.rb +0 -52
  38. data/test/email_address/address.rb +0 -16
  39. data/test/email_address/config.rb +0 -13
  40. data/test/email_address/host.rb +0 -29
  41. data/test/email_address/mail_exchanger.rb +0 -9
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,30 @@
1
+ #encoding: utf-8
2
+ require_relative '../test_helper'
3
+
4
+ class TestAddress < Minitest::Test
5
+ def test_address
6
+ a = EmailAddress.new("User+tag@example.com")
7
+ assert_equal "user+tag", a.local.to_s
8
+ assert_equal "example.com", a.host.to_s
9
+ assert_equal :unknown, a.provider
10
+ end
11
+
12
+ def test_noramlize
13
+ a = EmailAddress.new("User+tag@Example.com")
14
+ assert_equal "user+tag@example.com", a.normalize
15
+ end
16
+
17
+ def test_canonical
18
+ a = EmailAddress.new("User+tag@Example.com")
19
+ assert_equal "user@example.com", a.canonical
20
+ a = EmailAddress.new("first.last+tag@gmail.com")
21
+ assert_equal "firstlast@gmail.com", a.canonical
22
+ end
23
+
24
+ def test_digest
25
+ a = EmailAddress.new("User+tag@Example.com")
26
+ assert_equal "b58996c504c5638798eb6b511e6f49af", a.md5
27
+ assert_equal "63a710569261a24b3766275b7000ce8d7b32e2f7", a.sha1
28
+ assert_equal "63a710569261a24b3766275b7000ce8d7b32e2f7@example.com", a.archive
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestConfig < MiniTest::Test
4
+ def test_setup
5
+ EmailAddress::Config.setup do
6
+ provider :disposable, domains:%w(mailenator)
7
+ option :downcase_mailboxes, true
8
+ end
9
+ assert_equal true, EmailAddress::Config.providers.has_key?(:disposable)
10
+ assert_equal true, EmailAddress::Config.options[:downcase_mailboxes]
11
+ end
12
+
13
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestDomainMatcher < MiniTest::Test
4
+ def test_hostname
5
+ assert_equal true, EmailAddress::DomainMatcher.matches?("example.com", "example.com")
6
+ assert_equal true, EmailAddress::DomainMatcher.matches?("example.com", "example")
7
+ assert_equal true, EmailAddress::DomainMatcher.matches?("example.com", ".com")
8
+ assert_equal true, EmailAddress::DomainMatcher.matches?("example.com", ".example.com")
9
+ end
10
+
11
+ def test_list
12
+ assert_equal true, EmailAddress::DomainMatcher.matches?("example.com", %w(ex .tld example))
13
+ end
14
+
15
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestDomainParser < MiniTest::Test
4
+ def test_hostname
5
+ parts = EmailAddress::DomainParser.parse("Example.com")
6
+ assert_equal 'example.com', parts[:domain_name]
7
+ assert_equal 'example', parts[:registration_name]
8
+ assert_equal 'com', parts[:tld]
9
+ assert_equal '', parts[:subdomains]
10
+ end
11
+
12
+ def test_sld
13
+ parts = EmailAddress::DomainParser.parse("sub.Example.co.uk")
14
+ assert_equal 'example.co.uk', parts[:domain_name]
15
+ assert_equal 'co.uk', parts[:tld]
16
+ assert_equal 'sub', parts[:subdomains]
17
+ end
18
+
19
+ def test_provider
20
+ parser = EmailAddress::DomainParser.new("gmail.com")
21
+ assert_equal :google, parser.provider
22
+ end
23
+
24
+ def test_yahoo
25
+ parser = EmailAddress::DomainParser.new("yahoo.co.uk")
26
+ assert_equal :yahoo, parser.provider
27
+ end
28
+
29
+ end
@@ -0,0 +1,19 @@
1
+ #encoding: utf-8
2
+ require_relative '../test_helper'
3
+
4
+ class TestExchanger < MiniTest::Test
5
+ def test_exchanger
6
+ a = EmailAddress::Exchanger.new("example.com")
7
+ assert_equal true, a.has_dns_a_record? # example.com has no MX'ers
8
+ end
9
+
10
+ def test_dns
11
+ good = EmailAddress::Exchanger.new("gmail.com")
12
+ bad = EmailAddress::Exchanger.new("exampldkeie4iufe.com")
13
+ assert_equal true, good.has_dns_a_record?
14
+ assert_equal false, bad.has_dns_a_record?
15
+ assert_equal "gmail.com", good.dns_a_record.first
16
+ assert(/google.com\z/, good.mxers.first.first)
17
+ assert_equal 'google.com', good.domains.first
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+ require_relative '../test_helper'
3
+
4
+
5
+ class TestHost < MiniTest::Unit::TestCase
6
+ def test_host
7
+ a = EmailAddress::Host.new("example.com")
8
+ assert_equal "example.com", a.host_name
9
+ assert_equal "example.com", a.domain_name
10
+ assert_equal "example", a.registration_name
11
+ assert_equal "com", a.tld
12
+ assert_equal "", a.subdomains
13
+ end
14
+
15
+ def test_foreign_host
16
+ a = EmailAddress::Host.new("my.yahoo.co.jp")
17
+ assert_equal "my.yahoo.co.jp", a.host_name
18
+ assert_equal "yahoo.co.jp", a.domain_name
19
+ assert_equal "yahoo", a.registration_name
20
+ assert_equal "co.jp", a.tld
21
+ assert_equal "my", a.subdomains
22
+ end
23
+
24
+ def test_ip_host
25
+ a = EmailAddress::Host.new("[127.0.0.1]")
26
+ assert_equal "[127.0.0.1]", a.host_name
27
+ assert_equal "127.0.0.1", a.ip_address
28
+
29
+ end
30
+
31
+ def test_unicode_host
32
+ a = EmailAddress::Host.new("å.com")
33
+ assert_equal "xn--5ca.com", a.dns_host_name
34
+ end
35
+
36
+ def test_provider
37
+ a = EmailAddress::Host.new("my.yahoo.co.jp")
38
+ assert_equal :yahoo, a.provider
39
+ a = EmailAddress::Host.new("example.com")
40
+ assert_equal :unknown, a.provider
41
+ end
42
+
43
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ require_relative '../test_helper'
3
+
4
+ class TestLocal < MiniTest::Unit::TestCase
5
+ def test_local
6
+ a = EmailAddress::Local.new("TestMonkey")
7
+ assert_equal "testmonkey", a.to_s
8
+ end
9
+
10
+ def test_tag_comment
11
+ a = EmailAddress::Local.new("User+tag(comment!)")
12
+ assert_equal "user", a.mailbox
13
+ assert_equal "comment!", a.comment
14
+ assert_equal "tag", a.tag
15
+ end
16
+
17
+ def test_format
18
+ a = EmailAddress::Local.new("(Comment!)First Last+tag")
19
+ assert_equal 'firstlast+tag', a.normalize
20
+ end
21
+
22
+ def test_gmail
23
+ a = EmailAddress::Local.new("first.last", :google)
24
+ assert_equal "firstlast", a.canonical
25
+ end
26
+
27
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../test_helper'
2
+
3
+ class EmailAddress::TestValidator < MiniTest::Test
4
+
5
+ def test_basic
6
+ assert_equal true, EmailAddress.new('user.name@gmail.com').valid?
7
+ assert_equal true, EmailAddress.new('user.name+tagme@gmail.com').valid?
8
+ end
9
+
10
+ def test_bad_local
11
+ assert_equal false, EmailAddress.new('user!name@gmail.com').valid?
12
+ assert_equal false, EmailAddress.new('***@yahoo.com').valid?
13
+ assert_equal false, EmailAddress.new('***@unknowndom41n.com').valid?
14
+ end
15
+
16
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+ require_relative 'test_helper'
3
+
4
+ class TestEmailAddress < MiniTest::Test
5
+
6
+ def test_new
7
+ a = EmailAddress.new('user@example.com')
8
+ assert_equal a.local.to_s, 'user'
9
+ assert_equal a.host.to_s, 'example.com'
10
+ end
11
+
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -45,7 +45,21 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: netaddr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
@@ -70,26 +84,22 @@ files:
70
84
  - lib/email_address.rb
71
85
  - lib/email_address/address.rb
72
86
  - lib/email_address/config.rb
73
- - lib/email_address/esp.rb
87
+ - lib/email_address/domain_matcher.rb
88
+ - lib/email_address/domain_parser.rb
89
+ - lib/email_address/exchanger.rb
74
90
  - lib/email_address/host.rb
75
91
  - lib/email_address/local.rb
76
- - lib/email_address/providers/default.rb
77
- - lib/email_address/providers/google.rb
92
+ - lib/email_address/validator.rb
78
93
  - lib/email_address/version.rb
79
- - lib/email_providers/address.rb
80
- - lib/email_providers/config.rb
81
- - lib/email_providers/factory.rb
82
- - lib/email_providers/host.rb
83
- - lib/email_providers/mail_exchanger.rb
84
- - lib/email_providers/mailbox.rb
85
- - lib/email_providers/providers/default.rb
86
- - lib/email_providers/providers/google.rb
87
- - lib/email_providers/version.rb
88
- - test/email_address.rb
89
- - test/email_address/address.rb
90
- - test/email_address/config.rb
91
- - test/email_address/host.rb
92
- - test/email_address/mail_exchanger.rb
94
+ - test/email_address/test_address.rb
95
+ - test/email_address/test_config.rb
96
+ - test/email_address/test_domain_matcher.rb
97
+ - test/email_address/test_domain_parser.rb
98
+ - test/email_address/test_exchanger.rb
99
+ - test/email_address/test_host.rb
100
+ - test/email_address/test_local.rb
101
+ - test/email_address/test_validator.rb
102
+ - test/test_email_address.rb
93
103
  - test/test_helper.rb
94
104
  homepage: https://github.com/afair/email_address
95
105
  licenses:
@@ -111,15 +121,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
121
  version: '0'
112
122
  requirements: []
113
123
  rubyforge_project:
114
- rubygems_version: 2.2.0.rc.1
124
+ rubygems_version: 2.2.2
115
125
  signing_key:
116
126
  specification_version: 4
117
127
  summary: EmailAddress checks on validates an acceptable set of email addresses.
118
128
  test_files:
119
- - test/email_address.rb
120
- - test/email_address/address.rb
121
- - test/email_address/config.rb
122
- - test/email_address/host.rb
123
- - test/email_address/mail_exchanger.rb
129
+ - test/email_address/test_address.rb
130
+ - test/email_address/test_config.rb
131
+ - test/email_address/test_domain_matcher.rb
132
+ - test/email_address/test_domain_parser.rb
133
+ - test/email_address/test_exchanger.rb
134
+ - test/email_address/test_host.rb
135
+ - test/email_address/test_local.rb
136
+ - test/email_address/test_validator.rb
137
+ - test/test_email_address.rb
124
138
  - test/test_helper.rb
125
- has_rdoc:
@@ -1,4 +0,0 @@
1
- module EmailAddress
2
- class Esp
3
- end
4
- end
@@ -1,8 +0,0 @@
1
- module EmailAddress
2
- module Providers
3
- class Default
4
- def initialize(local, host)
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module EmailAddress
2
- module Providers
3
- class Google < EmailAddress::Providers::Default
4
- def initialize(local, host)
5
- end
6
- end
7
- end
8
- end
@@ -1,102 +0,0 @@
1
- module EmailAddress
2
-
3
- # EmailAddress::Address - Inspects a Email Address.
4
- #
5
- # * hostname - Everything to the rigth of the @
6
- # * mailbox - Everything to the left of the @
7
- #
8
- class Address
9
- attr_reader :address, :mailbox, :host, :account, :tags
10
-
11
- def initialize(mailbox, host_object)
12
- self.mailbox = mailbox
13
- @host = host_object
14
- end
15
-
16
- def mailbox=(mailbox)
17
- @mailbox = mailbox.strip.downcase
18
- (@account, @tags) = @mailbox.split(tag_separator)
19
- @mailbox
20
- end
21
-
22
- def address=(address)
23
- @address = address.strip
24
- (mailbox_name, host_name) = @address.split(/\@/)
25
- return unless host_part
26
-
27
- @mailbox_name = mailbox_name
28
- @host = EmailAddress::Host.new(host_part)
29
- @mailbox = host.provider_mailbox(mailbox_part, @host)
30
- @address
31
- end
32
-
33
- def provider
34
- 'unknown'
35
- end
36
-
37
- def tag_separator
38
- '+'
39
- end
40
-
41
- def case_sensitive_mailbox
42
- false
43
- end
44
-
45
- # Letters, numbers, period (no start) 6-30chars
46
- def user_pattern
47
- /\A[a-z0-9][\.a-z0-9]{5,29}\z/i
48
- end
49
-
50
- # Returns the unique address as simplified account@hostname
51
- def unique_address
52
- "#{account}@#{dns_hostname}"
53
- end
54
-
55
- def valid?
56
- return false unless @mailbox.valid?
57
- return false unless @host.valid?
58
- true
59
- end
60
-
61
- def valid_format?
62
- return false unless @mailbox.match(user_pattern)
63
- return false unless @host.valid_format?
64
- true
65
- end
66
-
67
- ############################################################################
68
- # Host Deletation: domain parts
69
- ############################################################################
70
-
71
- # Returns the fully-qualified host name (everything to the right of the @).
72
- def hostname
73
- host.host
74
- end
75
-
76
- # Returns the host without any subdomains (domain.tld(
77
- def domain_name
78
- host.domain_name
79
- end
80
-
81
- # Returns the Top-Level-Domain parts (after domain): com, co.jp
82
- def tld
83
- host.tld
84
- end
85
-
86
- # Returns the registration name without subdomains or TLD.
87
- def base_domain
88
- host.base_domain
89
- end
90
-
91
- # Returns any given subdomains of the domain name
92
- def subdomains
93
- host.subdomains
94
- end
95
-
96
- # Returns an ASCII name for DNS lookup, Punycode for Unicode domains.
97
- def dns_hostname
98
- host.dns_hostname
99
- end
100
-
101
- end
102
- end