ruby-spfquery 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +10 -0
- data/lib/spfquery/version.rb +3 -0
- data/lib/spfquery.rb +33 -0
- data/ruby-spfquery.gemspec +17 -0
- data/test/spfquery_test.rb +64 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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
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
|