rfc-822 0.4.0 → 0.4.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rfc822.rb +17 -17
  3. data/spec/rfc822_spec.rb +46 -44
  4. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc27d6a8f4a5e74135bc1b45f043ecadd3f54396
4
- data.tar.gz: 05754014b5b287fc651903082bc6db274f1bfe8c
3
+ metadata.gz: 31093e28dadc0e6463032bbacab6a932ff834561
4
+ data.tar.gz: d5aa904a3dc3d422e7e24d9c2573105fec52851b
5
5
  SHA512:
6
- metadata.gz: afe3f3e8b7c5cc9c29c7c611d619042c7f19c125746215778764f958ab8e0b7dfdc716a1065696966166bac835a8a9fbcbd2bed809a6b5b4a84dfdce47dfbac6
7
- data.tar.gz: 5d2c4a43b34f8f0110b21476497763b843aca7f63244e228d547b3a1ec6e69d5d097143709cea6f5b8b849c8d5a11a4404f585e0244e1eb3553246e46607b501
6
+ metadata.gz: 414b95c3e8c18bd877eafdb2ca7c8e4722ad48cee813806c1fba6bc7aff96a54ade491e85e93e0f7160ae6033dc0b5fa23f3e86f4349e943bf004e4863a85c4d
7
+ data.tar.gz: 16f85b720fa3ee9b19372f810223f206cc8ec15abb0b19f6ce18fc2733a72e538386b6758b79c33c3154b5aeab0f19f8abed6926d6a6b2ec53dd36d3bbaac879
@@ -2,29 +2,29 @@ require 'timeout'
2
2
  require 'uri'
3
3
 
4
4
  module RFC822
5
-
5
+
6
6
  module Patterns
7
-
7
+
8
8
  ATOM = "[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\u00ff]+"
9
-
10
- QTEXT = "[^\\x0d\\x22\\x5c\\u0080-\\u00ff]"
9
+
10
+ QTEXT = "[^\\x0d\\x22\\x5c\\u0080-\\u00ff]"
11
11
  QPAIR = "\\x5c[\\x00-\\x7f]"
12
12
  QSTRING = "\\x22(?:#{QTEXT}|#{QPAIR})*\\x22"
13
-
13
+
14
14
  WORD = "(?:#{ATOM}|#{QSTRING})"
15
15
 
16
16
  LOCAL_PT = "#{WORD}(?:\\x2e#{WORD})*"
17
- ADDRESS = "#{LOCAL_PT}\\x40#{URI::REGEXP::PATTERN::HOSTNAME}"
17
+ ADDRESS = "#{LOCAL_PT}\\x40(?:#{URI::REGEXP::PATTERN::HOSTNAME})?#{ATOM}"
18
18
 
19
19
  end
20
-
21
- MXRecord = Struct.new(:priority, :host)
20
+
21
+ MXRecord = Struct.new(:priority, :host)
22
22
  EMAIL = /\A#{Patterns::ADDRESS}\z/
23
-
23
+
24
24
  @@host_command = '/usr/bin/env host'
25
-
25
+
26
26
  class << self
27
-
27
+
28
28
  def host_command
29
29
  @@host_command
30
30
  end
@@ -36,8 +36,8 @@ module RFC822
36
36
  def mx_records(address)
37
37
  address = address.to_s
38
38
  return [] unless address =~ EMAIL
39
-
40
- Timeout::timeout(2) do
39
+
40
+ Timeout::timeout(2) do
41
41
  raw_mx_records(address.split('@').last).map do |priority, host|
42
42
  MXRecord.new(priority.to_i, host)
43
43
  end
@@ -46,12 +46,12 @@ module RFC822
46
46
  []
47
47
  end
48
48
 
49
- def raw_mx_records(domain)
50
- host_mx(domain).scan(/#{Regexp.escape(domain)}[\w ]+?(\d+) (#{URI::REGEXP::PATTERN::HOSTNAME})\./)
49
+ def raw_mx_records(domain)
50
+ host_mx(domain).scan(/#{Regexp.escape(domain)}[\w ]+?(\d+) (#{URI::REGEXP::PATTERN::HOSTNAME})\./)
51
51
  end
52
-
52
+
53
53
  def host_mx(domain)
54
- `#{host_command} -t MX #{domain}`
54
+ `#{host_command} -t MX #{domain}`
55
55
  end
56
56
 
57
57
  end
@@ -3,52 +3,54 @@ require File.dirname(__FILE__) + '/helper'
3
3
  describe RFC822 do
4
4
 
5
5
  after do
6
- RFC822.host_command = '/usr/bin/env host'
6
+ RFC822.host_command = '/usr/bin/env host'
7
7
  end
8
-
8
+
9
9
  describe 'email pattern' do
10
-
10
+
11
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-dashed-@home.com".should match(RFC822::EMAIL)
12
+ expect("user@x").to match(RFC822::EMAIL)
13
+ expect("user@home").to match(RFC822::EMAIL)
14
+ expect("user@home.com").to match(RFC822::EMAIL)
15
+ expect("user@dashed-home.info").to match(RFC822::EMAIL)
16
+ expect("user@separated.home.info").to match(RFC822::EMAIL)
17
+ expect("dashed-user@home.com").to match(RFC822::EMAIL)
18
+ expect("underscored_user@home.com").to match(RFC822::EMAIL)
19
+ expect("separated.user@home.com").to match(RFC822::EMAIL)
20
+ expect("slashed/user@home.com").to match(RFC822::EMAIL)
21
+ expect("plussed+user@home.com").to match(RFC822::EMAIL)
22
+ expect("{wrapped}user@home.com").to match(RFC822::EMAIL)
23
+ expect("end-dashed-@home.com").to match(RFC822::EMAIL)
23
24
  end
24
25
 
25
26
  it 'should not match non-RFC822 compliant addresses' do
26
- "user-home".should_not match(RFC822::EMAIL)
27
- "@home.com".should_not match(RFC822::EMAIL)
28
- "user@".should_not match(RFC822::EMAIL)
29
- "user@underscored_home.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
- "user@just wrong.org".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
- "wrong(user)@home.com".should_not match(RFC822::EMAIL)
38
- end
39
-
27
+ expect("user-home").not_to match(RFC822::EMAIL)
28
+ expect("@home.com").not_to match(RFC822::EMAIL)
29
+ expect("user@").not_to match(RFC822::EMAIL)
30
+ expect("user@trailing.period.").not_to match(RFC822::EMAIL)
31
+ expect("user@underscored_home.org").not_to match(RFC822::EMAIL)
32
+ expect("user@just,wrong.org").not_to match(RFC822::EMAIL)
33
+ expect("user@just/wrong.org").not_to match(RFC822::EMAIL)
34
+ expect("user@just wrong.org").not_to match(RFC822::EMAIL)
35
+ expect("wrong,user@home.com").not_to match(RFC822::EMAIL)
36
+ expect("wrong-user.@home.com").not_to match(RFC822::EMAIL)
37
+ expect("wrong@user@home.com").not_to match(RFC822::EMAIL)
38
+ expect("wrong user@home.com").not_to match(RFC822::EMAIL)
39
+ expect("wrong(user)@home.com").not_to match(RFC822::EMAIL)
40
+ end
41
+
40
42
  end
41
-
43
+
42
44
  it 'should allow to change the host command' do
43
- RFC822.host_command.should == '/usr/bin/env host'
45
+ expect(RFC822.host_command).to eq('/usr/bin/env host')
44
46
  RFC822.host_command = '/opt/bin host'
45
- RFC822.host_command.should == '/opt/bin host'
47
+ expect(RFC822.host_command).to eq('/opt/bin host')
46
48
  end
47
-
49
+
48
50
  describe 'MX record check' do
49
51
 
50
52
  before do
51
- RFC822.stub(:host_mx).and_return(%Q(
53
+ allow(RFC822).to receive(:host_mx).and_return(%Q(
52
54
  hotmail.com mail is handled by 5 mx3.hotmail.com.
53
55
  hotmail.com mail is handled by 5 mx4.hotmail.com.
54
56
  hotmail.com mail is handled by 5 mx1.hotmail.com.
@@ -57,24 +59,24 @@ hotmail.com mail is handled by 5 mx2.hotmail.com.
57
59
  end
58
60
 
59
61
  it 'should return raw MX records fo a domain' do
60
- RFC822.raw_mx_records('hotmail.com').should == [
61
- ["5", "mx3.hotmail.com"],
62
- ["5", "mx4.hotmail.com"],
63
- ["5", "mx1.hotmail.com"],
64
- ["5", "mx2.hotmail.com"]
65
- ]
62
+ expect(RFC822.raw_mx_records('hotmail.com')).to eq([
63
+ ["5", "mx3.hotmail.com"],
64
+ ["5", "mx4.hotmail.com"],
65
+ ["5", "mx1.hotmail.com"],
66
+ ["5", "mx2.hotmail.com"],
67
+ ])
66
68
  end
67
69
 
68
70
  it 'should return prioritised MX records of an address' do
69
- RFC822.mx_records('user@hotmail.com').should have(4).items
71
+ expect(RFC822.mx_records('user@hotmail.com').size).to eq(4)
70
72
  record = RFC822.mx_records('user@hotmail.com').first
71
- record.priority.should == 5
72
- record.host.should == "mx3.hotmail.com"
73
+ expect(record.priority).to eq(5)
74
+ expect(record.host).to eq("mx3.hotmail.com")
73
75
  end
74
76
 
75
77
  it 'should return an empty result if address is invalid' do
76
- RFC822.mx_records('user@hotmail@com').should == []
78
+ expect(RFC822.mx_records('user@hotmail@com')).to eq([])
77
79
  end
78
-
80
+
79
81
  end
80
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfc-822
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-12 00:00:00.000000000 Z
12
+ date: 2015-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description: RFC822 compatible email validation and MX record check
@@ -50,8 +50,8 @@ files:
50
50
  - init.rb
51
51
  - lib/rfc-822.rb
52
52
  - lib/rfc822.rb
53
- - spec/rfc822_spec.rb
54
53
  - spec/helper.rb
54
+ - spec/rfc822_spec.rb
55
55
  homepage: http://github.com/dim/rfc-822
56
56
  licenses: []
57
57
  metadata: {}
@@ -61,20 +61,20 @@ require_paths:
61
61
  - lib
62
62
  required_ruby_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.9.1
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - '>='
69
+ - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: 1.3.6
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.0.14
74
+ rubygems_version: 2.4.8
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: RFC822 compatible email validation and MX record check
78
78
  test_files:
79
- - spec/rfc822_spec.rb
80
79
  - spec/helper.rb
80
+ - spec/rfc822_spec.rb