ruby-spfquery 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-spfquery.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brett Gibson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Ruby Spfquery
2
+
3
+ It's a thin wrapper around spfquery which is assumed to be in the PATH of the ruby process.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruby-spfquery', require: 'spfquery'
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ gem install ruby-spfquery
18
+
19
+ ## Usage
20
+
21
+ Spfquery.pass?(ip_address, mail_from, helo)
22
+
23
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc 'Run the tests'
4
+ task :test do
5
+ exec 'ruby -rminitest/pride test/spfquery_test.rb'
6
+ end
7
+
8
+ task default: :test
9
+
10
+
@@ -0,0 +1,3 @@
1
+ class Spfquery
2
+ VERSION = '0.0.1'
3
+ end
data/lib/spfquery.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'stringio'
2
+
3
+ class Spfquery
4
+ attr_reader :ip, :sender, :helo
5
+
6
+ def self.pass?(*args)
7
+ new(*args).pass?
8
+ end
9
+
10
+ def initialize(ip, sender, helo=nil)
11
+ @ip = ip
12
+ @sender = sender
13
+ @helo = helo
14
+ end
15
+
16
+ def pass?
17
+ 'pass' == result
18
+ end
19
+
20
+ def result
21
+ @result ||= output.lines.first.chomp.downcase
22
+ end
23
+
24
+ private
25
+
26
+ def output
27
+ @output ||= run_spfquery
28
+ end
29
+
30
+ def run_spfquery
31
+ `spfquery --ip=#{ip} --sender=#{sender} #{" --helo=#{helo}" if helo} 2>/dev/null`
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'spfquery/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "ruby-spfquery"
7
+ gem.version = '0.0.1'
8
+ gem.authors = ['Brett Gibson']
9
+ gem.email = ['bdg@brettdgibson.com']
10
+ gem.description = %q{very thin ruby wrapper for spfquery cli}
11
+ gem.summary = %q{very thin ruby wrapper for spfquery cli}
12
+ gem.required_ruby_version = '>= 1.9.2'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = gem.files.grep(%r{^test/})
16
+ gem.require_paths = ['lib']
17
+ end
@@ -0,0 +1,64 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+
4
+ require_relative '../lib/spfquery'
5
+
6
+ # Will change if outlook.com's SPF DNS record changes.
7
+ VALID_OUTLOOK_IP = '65.54.190.100'
8
+
9
+ describe Spfquery do
10
+ describe 'being created' do
11
+ it 'accepts an ip and a sender' do
12
+ ip = '1.1.1.1'
13
+ sender = 'abc@example.org'
14
+ sq = Spfquery.new(ip, sender)
15
+ sq.ip.must_equal(ip)
16
+ sq.sender.must_equal(sender)
17
+ end
18
+ it 'optionallys also accepts a helo' do
19
+ helo = 'abc.example.org'
20
+ sq = Spfquery.new('', '', helo)
21
+ sq.helo.must_equal(helo)
22
+ end
23
+ end
24
+
25
+ describe '.pass?' do
26
+ it 'should create an instance and return true if it is a pass' do
27
+ Spfquery.pass?('1.1.1.1', 'abc@probably-wont-have-spf.org').must_equal false
28
+ Spfquery.pass?(VALID_OUTLOOK_IP, 'abc@example.org', 'outlook.com').must_equal true
29
+ end
30
+ end
31
+
32
+ describe '#result' do
33
+ it 'handles none' do
34
+ Spfquery.new('1.1.1.1', 'abc@probably-wont-have-spf.org').result.must_equal 'none'
35
+ end
36
+ it 'handles neutral' do
37
+ Spfquery.new('1.1.1.1', 'abc@gmail.com').result.must_equal 'neutral'
38
+ end
39
+ it 'handles fail' do
40
+ Spfquery.new('1.1.1.1', 'abc@example.org').result.must_equal 'fail'
41
+ end
42
+ it 'handles pass' do
43
+ Spfquery.new(VALID_OUTLOOK_IP, 'abc@outlook.com').result.must_equal 'pass'
44
+ Spfquery.new(VALID_OUTLOOK_IP, 'abc@example.org', 'outlook.com').result.must_equal 'pass'
45
+ end
46
+ end
47
+
48
+ describe '#pass?' do
49
+ %w{neutral fail none something}.each do |non_pass|
50
+ it "should be false for #{non_pass} result" do
51
+ sq = Spfquery.new('', '')
52
+ sq.instance_eval { @output = non_pass }
53
+ sq.pass?.must_equal false
54
+ end
55
+ end
56
+ it 'should be false for a pass result' do
57
+ sq = Spfquery.new('', '')
58
+ sq.instance_eval { @output = 'pass' }
59
+ sq.pass?.must_equal true
60
+ end
61
+ end
62
+ end
63
+
64
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-spfquery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brett Gibson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: very thin ruby wrapper for spfquery cli
15
+ email:
16
+ - bdg@brettdgibson.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/spfquery.rb
27
+ - lib/spfquery/version.rb
28
+ - ruby-spfquery.gemspec
29
+ - test/spfquery_test.rb
30
+ homepage:
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.9.2
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.23
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: very thin ruby wrapper for spfquery cli
54
+ test_files:
55
+ - test/spfquery_test.rb