ruby_email 0.1.6 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 992dcd485d48991c1e09827fefd0f396ba93099c
4
- data.tar.gz: f4c6e74256ad4f147bc32a4b99221424f85bb8b2
3
+ metadata.gz: fb0af7e294ab593344d60503c202e28101564e99
4
+ data.tar.gz: 68d07606c01697cac35810a6678b744f59a8e469
5
5
  SHA512:
6
- metadata.gz: d75c0b231723e17f9eeec5c34b8fb898f29c88c2b3a84ad72da406e2c426c7ce2d40ae1863bfd14485a49435d99e3e2dcbb0f17f2d594859c326bbd08a65cd9a
7
- data.tar.gz: 0477f20e580eb1165a69bcc89b31c203e1fe564faadc2f60be644eb72316ea0e435b9dee5474163285c54020d89d578f765e0e963eb0291cbb70fb6f04d0da63
6
+ metadata.gz: 1e759d12958e3fd79ceddde57f4a3fffd742593f0f590c6dca1c6a7723e8dcecde4ed279faf349a2ce52852bd2c21a9153e0cc280d18920bade8ef66cbc5dac1
7
+ data.tar.gz: a6313085eaa139c284bbd7e63fba0879053d6e0c8bdbdc4619e0ab417b0ba3694113a18065e1e548ff7c14e5517bc1054254b9ec4eab4f17d0d268d1fd1bc8ed
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.2.0
2
+ * Domain Name handled (Rfc1123)
3
+
1
4
  v0.1.6
2
5
  * Break compatibility (100%)
3
6
  * Improve architecture
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # A RFC compliant Email validator
2
2
 
3
- What is an [email address](https://en.wikipedia.org/wiki/Email_address) ?
3
+ - What is an [Email Address](https://en.wikipedia.org/wiki/Email_address) ?
4
+ - What is a [Domain Name](https://en.wikipedia.org/wiki/Hostname) ?
5
+
6
+ - Compliant to the [Rfc 5322](https://tools.ietf.org/html/rfc5322).
7
+ - Compliant to the [Rfc 1123](https://tools.ietf.org/html/rfc1123).
4
8
 
5
- - Compliant to the [rfc 5322](https://tools.ietf.org/html/rfc5322) standard.
6
9
  - To do [rfc 6530](https://tools.ietf.org/html/rfc6530).
7
10
 
8
11
 
@@ -0,0 +1,5 @@
1
+ require_relative '../public'
2
+
3
+ class String
4
+ include RubyEmail::Rfc1123::Public::String
5
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../rfc1123'
2
+
3
+ module RubyEmail
4
+ class Rfc1123
5
+
6
+ # Internet realist version of {Rfc5322}. It requires 2 names (a.b).
7
+ class Public < Rfc1123
8
+ DOT_ATOM_TEXT = "(?=.{1,253})((#{ATOM_ALL}\\.)+#{ATOM_FIRST})"
9
+ VALIDE = "(?<domain>#{DOT_ATOM_TEXT})"
10
+ REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
11
+
12
+ module String
13
+ # Check if the current [::String] instance is a valid domain on internet
14
+ # @return [TrueClass or FalseClass]
15
+ def is_public_domain?
16
+ RubyEmail::Rfc1123::Public.validates? self
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ require_relative '../rfc1123'
2
+
3
+ class String
4
+ include RubyEmail::Rfc1123::String
5
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'core'
2
+
3
+ module RubyEmail
4
+
5
+ # a Domain Name follows the Rfc1123: https://tools.ietf.org/html/rfc1123
6
+ class Rfc1123 < Core
7
+ # one valid character for domain part (first name first character)
8
+ ATEXT_FIRST_FIRST = '([A-Za-z])'
9
+ # one valid character for domain part (first name all other characters)
10
+ ATEXT_FIRST_ALL = '([A-Za-z0-9])'
11
+ # one valid character for domain part (all other names)
12
+ ATEXT_ALL = '([A-Za-z0-9\-])'
13
+
14
+ # a valid string for domain part (first name)
15
+ ATOM_FIRST = "#{ATEXT_FIRST_FIRST}#{ATEXT_ALL}{,62}"
16
+ # a valid string for domain part (all other names)
17
+ ATOM_ALL = "#{ATEXT_FIRST_ALL}#{ATEXT_ALL}{,62}"
18
+
19
+ # a valid string with subdomains, separated by dots for domain part as IPV4
20
+ IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
21
+ # a valid string with subdomains, separated by dots for domain part as Domain Name
22
+ DOT_ATOM_TEXT = "(?=.{1,253})((#{ATOM_ALL}\\.)*#{ATOM_FIRST})"
23
+
24
+ # email grammar
25
+ VALIDE = "(?<domain>((#{DOT_ATOM_TEXT})|(#{IPV4})))"
26
+
27
+ # regexp to validate complete email
28
+ REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
29
+
30
+ module String
31
+ # Check if the current [::String] instance is a valid domain
32
+ # @return [TrueClass or FalseClass]
33
+ def is_domain?
34
+ RubyEmail::Rfc1123.validates? self
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -1,11 +1,12 @@
1
1
  require_relative '../rfc5322'
2
+ require_relative '../rfc1123/public'
2
3
 
3
4
  module RubyEmail
4
5
  class Rfc5322
5
6
 
6
7
  # Internet realist version of {Rfc5322}. It requires a root domain.
7
8
  class Public < Rfc5322
8
- VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT}\\.#{DOT_ATOM_TEXT})"
9
+ VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(#{Rfc1123::Public::VALIDE})"
9
10
  REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
10
11
 
11
12
  module String
@@ -1,21 +1,29 @@
1
1
  require_relative 'core'
2
+ require_relative 'rfc1123'
2
3
 
3
4
  module RubyEmail
4
5
 
5
- # http://www.ietf.org/rfc/rfc5322.txt
6
- # The Rfc5322 designe an email with the format local@domain, wher local and
7
- # domain are a string of US-ASCII characters, without some symboles.
6
+ # an Email Address follows the Rfc5322: http://www.ietf.org/rfc/rfc5322.txt
7
+ # a Domain Name follows the Rfc1123: https://tools.ietf.org/html/rfc1123
8
+ # The Rfc5322 designate an email with the format local@domain, where
9
+ # - local is a string of US-ASCII characters, without some symboles.
10
+ # - domain is a valid Domain Name
8
11
  class Rfc5322 < Core
9
- # one valid character (not . because used to separe domains)
12
+ # one valid character for local part (do not take escaped because the Rfc prefere to avoid them)
10
13
  ATEXT = '([A-Za-z0-9!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
11
- # a valid string
14
+
15
+ # a valid string for local part
12
16
  ATOM = "#{ATEXT}+"
13
- # a valid string with subdomains, separated by dots
17
+
18
+ # a valid string with subdomains, separated by dots for local part
14
19
  DOT_ATOM_TEXT = "(#{ATOM})(\\.#{ATOM})*"
20
+
15
21
  # email grammar
16
- VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT})"
22
+ VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(#{Rfc1123::VALIDE})"
23
+
17
24
  # regexp to validate complete email
18
25
  REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
26
+
19
27
  module String
20
28
  # Check if the current [::String] instance is a valid email
21
29
  # @return [TrueClass or FalseClass]
data/lib/ruby_email.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require_relative 'ruby_email/core'
2
2
 
3
+ require_relative 'ruby_email/rfc1123'
3
4
  require_relative 'ruby_email/rfc5322'
4
5
 
6
+ require_relative 'ruby_email/rfc1123/public'
5
7
  require_relative 'ruby_email/rfc5322/public'
6
8
 
7
9
  #require_relative 'ruby_email/rfc5322/string'
data/ruby_email.gemspec CHANGED
@@ -13,6 +13,10 @@ lib/ruby_email/rfc5322.rb
13
13
  lib/ruby_email/rfc5322/string.rb
14
14
  lib/ruby_email/rfc5322/public.rb
15
15
  lib/ruby_email/rfc5322/public/string.rb
16
+ lib/ruby_email/rfc1123.rb
17
+ lib/ruby_email/rfc1123/string.rb
18
+ lib/ruby_email/rfc1123/public.rb
19
+ lib/ruby_email/rfc1123/public/string.rb
16
20
 
17
21
  README.md
18
22
  CHANGELOG
@@ -24,6 +28,8 @@ ruby_email.gemspec
24
28
  version
25
29
 
26
30
  test/unit_test.rb
31
+ test/rfc1123.rb
32
+ test/rfc5322.rb
27
33
  )
28
34
  s.executables = %w(
29
35
  )
data/test/rfc1123.rb ADDED
@@ -0,0 +1,84 @@
1
+ class TestRubyEmailRfc1123 < Test::Unit::TestCase
2
+
3
+ def test_simple_true
4
+ assert RubyEmail::Rfc1123.validates?("toto")
5
+ assert RubyEmail::Rfc1123.validates?("toto.toto")
6
+ assert RubyEmail::Rfc1123.validates?("toto.toto.toto")
7
+ assert RubyEmail::Rfc1123.validates?("toto.toto.toto.toto")
8
+ end
9
+
10
+ def test_simple_false
11
+ assert !RubyEmail::Rfc1123.validates?("-1")
12
+ assert !RubyEmail::Rfc1123.validates?("t@")
13
+ assert !RubyEmail::Rfc1123.validates?("@t")
14
+ end
15
+
16
+ def test_plus_true
17
+ assert RubyEmail::Rfc1123.validates?("mail.com")
18
+ assert RubyEmail::Rfc1123.validates?("0mail.com")
19
+ assert RubyEmail::Rfc1123.validates?("t1oto")
20
+ assert RubyEmail::Rfc1123.validates?("t1oto")
21
+ assert RubyEmail::Rfc1123.validates?("1.toto")
22
+ assert RubyEmail::Rfc1123.validates?("127.0.0.1")
23
+ assert RubyEmail::Rfc1123.validates?("255.254.251.0")
24
+ end
25
+
26
+ def test_plus_false
27
+ assert !RubyEmail::Rfc1123.validates?("some things")
28
+ assert !RubyEmail::Rfc1123.validates?("toto;toto")
29
+ assert !RubyEmail::Rfc1123.validates?("some things")
30
+ assert !RubyEmail::Rfc1123.validates?("toto,toto")
31
+ assert !RubyEmail::Rfc1123.validates?("toto()toto")
32
+ assert !RubyEmail::Rfc1123.validates?("toto[]toto")
33
+ assert !RubyEmail::Rfc1123.validates?("toto:toto")
34
+ assert !RubyEmail::Rfc1123.validates?("toto<>toto")
35
+ assert !RubyEmail::Rfc1123.validates?("toto\\toto")
36
+ assert !RubyEmail::Rfc1123.validates?("toto\"toto")
37
+ assert !RubyEmail::Rfc1123.validates?("-root")
38
+ assert !RubyEmail::Rfc1123.validates?("0.0.0.-1")
39
+ assert !RubyEmail::Rfc1123.validates?("256.255.254.1")
40
+ assert !RubyEmail::Rfc1123.validates?("1")
41
+ assert !RubyEmail::Rfc1123.validates?("111")
42
+ assert !RubyEmail::Rfc1123.validates?("a.1")
43
+ assert !RubyEmail::Rfc1123.validates?("1.1")
44
+ end
45
+
46
+ def test_match
47
+ m = RubyEmail::Rfc1123.match "toto.toto.toto.toto"
48
+ assert m.names & %w(domain)
49
+ assert_equal "toto.toto.toto.toto", m["domain"]
50
+ end
51
+
52
+ def test_string
53
+ assert_raise { "toto@toto".is_domain? }
54
+ require_relative '../lib/ruby_email/rfc1123/string'
55
+ assert "toto".is_domain?
56
+ assert !"___".is_domain?
57
+ end
58
+
59
+ def test_exceptions
60
+ assert_raise { RubyEmail::Rfc1123.match 1 }
61
+ assert_raise { RubyEmail::Rfc1123.validates? 1.0 }
62
+ assert_raise { RubyEmail::Rfc1123.validates? /toto/ }
63
+ assert_raise { RubyEmail::Rfc1123.validates? :ok }
64
+ assert_raise { RubyEmail::Rfc1123.validates? Class }
65
+ end
66
+
67
+ end
68
+
69
+ class TestRubyEmailRfc1123Public < Test::Unit::TestCase
70
+ def test_simpe
71
+ assert RubyEmail::Rfc1123::Public.validates?("toto.toto")
72
+ assert RubyEmail::Rfc1123::Public.validates?("toto.toto.toto")
73
+ assert RubyEmail::Rfc1123::Public.validates?("toto.toto.toto.toto")
74
+ assert !RubyEmail::Rfc1123::Public.validates?("toto")
75
+ assert RubyEmail::Rfc1123::Public.match("toto.toto")
76
+ end
77
+
78
+ def test_string
79
+ assert_raise { "toto.toto".is_public_domain? }
80
+ require_relative '../lib/ruby_email/rfc1123/public/string'
81
+ assert "toto.toto".is_public_domain?
82
+ assert !"toto".is_public_domain?
83
+ end
84
+ end
data/test/rfc5322.rb ADDED
@@ -0,0 +1,79 @@
1
+ class TestRubyEmailRfc5322 < Test::Unit::TestCase
2
+
3
+ def test_simple_true
4
+ assert RubyEmail::Rfc5322.validates?("toto@toto")
5
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto")
6
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto")
7
+ assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto.toto")
8
+ end
9
+
10
+ def test_simple_false
11
+ assert !RubyEmail::Rfc5322.validates?("t")
12
+ assert !RubyEmail::Rfc5322.validates?("t@")
13
+ assert !RubyEmail::Rfc5322.validates?("@t")
14
+ end
15
+
16
+ def test_plus_true
17
+ assert RubyEmail::Rfc5322.validates?("i'am%toto@here")
18
+ assert RubyEmail::Rfc5322.validates?("ich-bin-toto@ta-ta")
19
+ assert RubyEmail::Rfc5322.validates?("arthur+spam@mail.com")
20
+ assert RubyEmail::Rfc5322.validates?("arthur+spam@0mail.com")
21
+ assert RubyEmail::Rfc5322.validates?("arthur+spam@127.0.0.1")
22
+ assert RubyEmail::Rfc5322.validates?("arthur+spam@255.254.251.0")
23
+ end
24
+
25
+ def test_plus_false
26
+ assert !RubyEmail::Rfc5322.validates?("i have @ some things")
27
+ assert !RubyEmail::Rfc5322.validates?("toto;toto@toto;toto")
28
+ assert !RubyEmail::Rfc5322.validates?("toto,toto@toto,toto")
29
+ assert !RubyEmail::Rfc5322.validates?("toto()toto@toto()toto")
30
+ assert !RubyEmail::Rfc5322.validates?("toto[]toto@toto[]toto")
31
+ assert !RubyEmail::Rfc5322.validates?("toto:toto@toto:toto")
32
+ assert !RubyEmail::Rfc5322.validates?("toto<>toto@toto<>toto")
33
+ assert !RubyEmail::Rfc5322.validates?("toto\\toto@toto\\toto")
34
+ assert !RubyEmail::Rfc5322.validates?("toto\"toto@toto\"toto")
35
+ assert !RubyEmail::Rfc5322.validates?("arthur+spam@-root")
36
+ assert !RubyEmail::Rfc5322.validates?("arthur+spam@0.0.0.-1")
37
+ assert !RubyEmail::Rfc5322.validates?("arthur+spam@256.255.254.1")
38
+ end
39
+
40
+ def test_match
41
+ m = RubyEmail::Rfc5322.match "toto@toto.toto.toto.toto"
42
+ assert m.names & %w(local domain)
43
+ assert_equal "toto", m["local"]
44
+ assert_equal "toto.toto.toto.toto", m["domain"]
45
+ end
46
+
47
+ def test_string
48
+ assert_raise { "toto@toto".is_email? }
49
+ require_relative '../lib/ruby_email/rfc5322/string'
50
+ assert "toto@toto".is_email?
51
+ assert !"toto".is_email?
52
+ end
53
+
54
+ def test_exceptions
55
+ assert_raise { RubyEmail::Rfc5322.match 1 }
56
+ assert_raise { RubyEmail::Rfc5322.validates? 1.0 }
57
+ assert_raise { RubyEmail::Rfc5322.validates? /toto/ }
58
+ assert_raise { RubyEmail::Rfc5322.validates? :ok }
59
+ assert_raise { RubyEmail::Rfc5322.validates? Class }
60
+ end
61
+
62
+ end
63
+
64
+ class TestRubyEmailRfc5322Public < Test::Unit::TestCase
65
+ def test_simpe
66
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto")
67
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto")
68
+ assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto.toto")
69
+ assert !RubyEmail::Rfc5322::Public.validates?("toto@toto")
70
+ assert RubyEmail::Rfc5322::Public.match("toto@toto.toto")
71
+ end
72
+
73
+ def test_string
74
+ assert_raise { "toto@toto.toto".is_public_email? }
75
+ require_relative '../lib/ruby_email/rfc5322/public/string'
76
+ assert "toto@toto.toto".is_public_email?
77
+ assert !"toto@toto".is_public_email?
78
+ end
79
+ end
data/test/unit_test.rb CHANGED
@@ -4,76 +4,5 @@ require "test/unit"
4
4
 
5
5
  require_relative '../lib/ruby_email'
6
6
 
7
- class TestRubyEmail < Test::Unit::TestCase
8
-
9
- def test_simple_true
10
- assert RubyEmail::Rfc5322.validates?("toto@toto")
11
- assert RubyEmail::Rfc5322.validates?("toto@toto.toto")
12
- assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto")
13
- assert RubyEmail::Rfc5322.validates?("toto@toto.toto.toto.toto")
14
- end
15
-
16
- def test_simple_false
17
- assert !RubyEmail::Rfc5322.validates?("t")
18
- assert !RubyEmail::Rfc5322.validates?("t@")
19
- assert !RubyEmail::Rfc5322.validates?("@t")
20
- end
21
-
22
- def test_plus_true
23
- assert RubyEmail::Rfc5322.validates?("i'am%toto@here")
24
- assert RubyEmail::Rfc5322.validates?("ich-bin-toto@___")
25
- assert RubyEmail::Rfc5322.validates?("arthur+spam@mail.com")
26
- end
27
-
28
- def test_plus_false
29
- assert !RubyEmail::Rfc5322.validates?("i have @ some things")
30
- assert !RubyEmail::Rfc5322.validates?("toto;toto@toto;toto")
31
- assert !RubyEmail::Rfc5322.validates?("toto,toto@toto,toto")
32
- assert !RubyEmail::Rfc5322.validates?("toto()toto@toto()toto")
33
- assert !RubyEmail::Rfc5322.validates?("toto[]toto@toto[]toto")
34
- assert !RubyEmail::Rfc5322.validates?("toto:toto@toto:toto")
35
- assert !RubyEmail::Rfc5322.validates?("toto<>toto@toto<>toto")
36
- assert !RubyEmail::Rfc5322.validates?("toto\\toto@toto\\toto")
37
- assert !RubyEmail::Rfc5322.validates?("toto\"toto@toto\"toto")
38
- end
39
-
40
- def test_match
41
- m = RubyEmail::Rfc5322.match "toto@toto.toto.toto.toto"
42
- assert m.names & %w(local domain)
43
- assert_equal "toto", m["local"]
44
- assert_equal "toto.toto.toto.toto", m["domain"]
45
- end
46
-
47
- def test_string
48
- assert_raise { "toto@toto".is_email? }
49
- require_relative '../lib/ruby_email/rfc5322/string'
50
- assert "toto@toto".is_email?
51
- assert !"toto".is_email?
52
- end
53
-
54
- def test_exceptions
55
- assert_raise { RubyEmail::Rfc5322.match 1 }
56
- assert_raise { RubyEmail::Rfc5322.validates? 1.0 }
57
- assert_raise { RubyEmail::Rfc5322.validates? /toto/ }
58
- assert_raise { RubyEmail::Rfc5322.validates? :ok }
59
- assert_raise { RubyEmail::Rfc5322.validates? Class }
60
- end
61
-
62
- end
63
-
64
- class TestRubyEmailPublic < Test::Unit::TestCase
65
- def test_simpe
66
- assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto")
67
- assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto")
68
- assert RubyEmail::Rfc5322::Public.validates?("toto@toto.toto.toto.toto")
69
- assert !RubyEmail::Rfc5322::Public.validates?("toto@toto")
70
- assert RubyEmail::Rfc5322::Public.match("toto@toto.toto")
71
- end
72
-
73
- def test_string
74
- assert_raise { "toto@toto.toto".is_public_email? }
75
- require_relative '../lib/ruby_email/rfc5322/public/string'
76
- assert "toto@toto.toto".is_public_email?
77
- assert !"toto@toto".is_public_email?
78
- end
79
- end
7
+ require_relative 'rfc5322'
8
+ require_relative 'rfc1123'
data/version CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.0
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nephos (poulet_a)
@@ -61,11 +61,17 @@ files:
61
61
  - Rakefile
62
62
  - lib/ruby_email.rb
63
63
  - lib/ruby_email/core.rb
64
+ - lib/ruby_email/rfc1123.rb
65
+ - lib/ruby_email/rfc1123/public.rb
66
+ - lib/ruby_email/rfc1123/public/string.rb
67
+ - lib/ruby_email/rfc1123/string.rb
64
68
  - lib/ruby_email/rfc5322.rb
65
69
  - lib/ruby_email/rfc5322/public.rb
66
70
  - lib/ruby_email/rfc5322/public/string.rb
67
71
  - lib/ruby_email/rfc5322/string.rb
68
72
  - ruby_email.gemspec
73
+ - test/rfc1123.rb
74
+ - test/rfc5322.rb
69
75
  - test/unit_test.rb
70
76
  - version
71
77
  homepage: https://github.com/Nephos/RubyEmail
metadata.gz.sig CHANGED
Binary file