sixpounder 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -4
- data/bin/pounder +6 -3
- data/lib/pounder/server.rb +10 -8
- data/lib/pounder/server/command.rb +15 -12
- data/lib/pounder/version.rb +1 -1
- data/spec/pounder/server/command_spec.rb +32 -1
- data/spec/pounder/server_spec.rb +20 -0
- metadata +2 -3
- data/.pounder/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b08eb0964b59332aff102369f8b0e08252eee56
|
4
|
+
data.tar.gz: 13a55a771744725b12fb47fd573c9ed2f889973c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693f3897b518dd35cc2349ac52e1723ffdad8f40def3ecf2a4b81101f32a6e50e39ff7b5a15f6d0724db0781894639a544ced042832b036398213480389fef6e
|
7
|
+
data.tar.gz: c8f15b9b076983ea91e1441715007cd4c927366b453097d0d41f17868086fee62e34bdc7017232b3592312dfc92756d0c0768bd896866d49d5b554e6bf62dc77
|
data/README.md
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
Pounder is a POP server for operation verification for the system to
|
4
4
|
parse the mail.
|
5
5
|
|
6
|
+
## Build & Dependency Status
|
7
|
+
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/sixpounder.png)](http://badge.fury.io/rb/sixpounder) [![Code
|
9
|
+
Climate](https://codeclimate.com/github/ackintosh/pounder.png)](https://codeclimate.com/github/ackintosh/pounder)
|
10
|
+
|
6
11
|
master: [![Build
|
7
12
|
Status](https://travis-ci.org/ackintosh/pounder.png?branch=master)](https://travis-ci.org/ackintosh/pounder) [![Coverage
|
8
|
-
Status](https://coveralls.io/repos/ackintosh/pounder/badge.png?branch=master)](https://coveralls.io/r/ackintosh/pounder?branch=master)
|
9
|
-
Climate](https://codeclimate.com/github/ackintosh/pounder.png)](https://codeclimate.com/github/ackintosh/pounder)
|
13
|
+
Status](https://coveralls.io/repos/ackintosh/pounder/badge.png?branch=master)](https://coveralls.io/r/ackintosh/pounder?branch=master)
|
10
14
|
|
11
15
|
develop: [![Build
|
12
16
|
Status](https://travis-ci.org/ackintosh/pounder.png?branch=develop)](https://travis-ci.org/ackintosh/pounder) [![Coverage
|
@@ -14,7 +18,9 @@ Status](https://coveralls.io/repos/ackintosh/pounder/badge.png?branch=develop)](
|
|
14
18
|
|
15
19
|
## Installation
|
16
20
|
|
17
|
-
$ gem install
|
21
|
+
$ gem install sixpounder
|
22
|
+
|
23
|
+
*# Not a `pounder`*
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
@@ -27,13 +33,22 @@ operation verification.
|
|
27
33
|
|
28
34
|
### start
|
29
35
|
|
30
|
-
$ bundle exec pounder
|
36
|
+
$ bundle exec pounder [port]
|
31
37
|
|
32
38
|
If POP acceess to the host that started Pounder, you can get the mail
|
33
39
|
data that is prepared in advance.
|
34
40
|
|
35
41
|
It will not be deleted when you receive mail, you can repeat access.
|
36
42
|
|
43
|
+
`[port]` is optional.
|
44
|
+
If it is omitted, a free port will be used automatically by [Ackintosh::Net::EmptyPort](https://github.com/ackintosh/ackintosh-net-empty_port).
|
45
|
+
|
46
|
+
#### `-f` option
|
47
|
+
|
48
|
+
$ bundle exec pounder -f pounder@example.com
|
49
|
+
|
50
|
+
Pounder can change 'From' header to specified email address.
|
51
|
+
|
37
52
|
## Contributing
|
38
53
|
|
39
54
|
1. Fork it
|
data/bin/pounder
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'pounder'
|
4
|
-
require
|
5
|
-
|
4
|
+
require 'ackintosh/net/empty_port'
|
5
|
+
require 'optparse'
|
6
6
|
|
7
|
-
|
7
|
+
options = ARGV.getopts('p:f:')
|
8
|
+
port = options['p'] || Ackintosh::Net::EmptyPort.find
|
9
|
+
from_address = options['f'] || nil
|
10
|
+
Pounder::Server.invoke(port: port.to_i, from_address: from_address)
|
data/lib/pounder/server.rb
CHANGED
@@ -2,27 +2,29 @@ module Pounder
|
|
2
2
|
class Server
|
3
3
|
include Command
|
4
4
|
|
5
|
-
def self.invoke(
|
6
|
-
new.listen(
|
5
|
+
def self.invoke(options)
|
6
|
+
new.listen(options)
|
7
7
|
end
|
8
8
|
|
9
|
-
def listen(
|
10
|
-
server = TCPServer.new(port)
|
11
|
-
puts "#{self.class}##{__method__} port=#{port}"
|
9
|
+
def listen(options)
|
10
|
+
server = TCPServer.new(options[:port])
|
11
|
+
puts "#{self.class}##{__method__} port=#{options[:port]}"
|
12
12
|
|
13
13
|
maildir_path = "#{Dir::pwd}/.pounder"
|
14
14
|
puts "Maildir: #{maildir_path}"
|
15
15
|
maildir = Maildir.new(maildir_path)
|
16
16
|
|
17
|
+
puts "From: #{options[:from_address]}" if options[:from_address]
|
18
|
+
|
17
19
|
while true
|
18
20
|
Thread.fork(server.accept) do |sock|
|
19
21
|
p sock
|
20
|
-
service(sock, sock, maildir)
|
22
|
+
service(sock, sock, maildir, options)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
def service(input, output, maildir)
|
27
|
+
def service(input, output, maildir, options)
|
26
28
|
@input = input
|
27
29
|
@output = output
|
28
30
|
print_line "+OK pounder"
|
@@ -35,7 +37,7 @@ module Pounder
|
|
35
37
|
next
|
36
38
|
end
|
37
39
|
|
38
|
-
__send__(cmd_name, maildir, args)
|
40
|
+
__send__(cmd_name, maildir: maildir, args: args, options: options)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -3,45 +3,48 @@ require 'date'
|
|
3
3
|
module Pounder
|
4
4
|
class Server
|
5
5
|
module Command
|
6
|
-
def cmd_STAT(
|
7
|
-
print_line "+OK #{maildir.size} #{maildir.total_octets}"
|
6
|
+
def cmd_STAT(params)
|
7
|
+
print_line "+OK #{params[:maildir].size} #{params[:maildir].total_octets}"
|
8
8
|
end
|
9
9
|
|
10
|
-
def cmd_LIST(
|
10
|
+
def cmd_LIST(params)
|
11
11
|
print_line "+OK"
|
12
|
-
maildir.messages.each do |m|
|
12
|
+
params[:maildir].messages.each do |m|
|
13
13
|
print_line "#{m.seq} #{m.octets}"
|
14
14
|
end
|
15
15
|
print_line "."
|
16
16
|
end
|
17
17
|
|
18
|
-
def cmd_USER(
|
18
|
+
def cmd_USER(params)
|
19
19
|
# nop.
|
20
20
|
print_line "+OK"
|
21
21
|
end
|
22
22
|
|
23
|
-
def cmd_PASS(
|
23
|
+
def cmd_PASS(params)
|
24
24
|
# nop.
|
25
25
|
print_line "+OK"
|
26
26
|
end
|
27
27
|
|
28
|
-
def cmd_DELE(
|
28
|
+
def cmd_DELE(params)
|
29
29
|
# nop.
|
30
30
|
print_line "+OK"
|
31
31
|
end
|
32
32
|
|
33
|
-
def cmd_QUIT(
|
33
|
+
def cmd_QUIT(params)
|
34
34
|
print_line "+OK"
|
35
35
|
terminate
|
36
36
|
end
|
37
37
|
|
38
|
-
def cmd_RETR(
|
39
|
-
message = maildir[args.first.to_i]
|
38
|
+
def cmd_RETR(params)
|
39
|
+
message = params[:maildir][params[:args].first.to_i]
|
40
40
|
print_line "+OK"
|
41
41
|
message.each_line do |line|
|
42
|
-
if line.match(
|
42
|
+
if line.match(/\ADate: .*/) then
|
43
43
|
# Outputs a Date header of the time it was run.
|
44
|
-
|
44
|
+
print_line "Date: #{DateTime.now.httpdate}"
|
45
|
+
next
|
46
|
+
elsif (params[:options][:from_address] && line.match(/\AFrom: .*/)) then
|
47
|
+
print_line "From: \"#{params[:options][:from_address]}\" <#{params[:options][:from_address]}>"
|
45
48
|
next
|
46
49
|
end
|
47
50
|
print_line_message line
|
data/lib/pounder/version.rb
CHANGED
@@ -13,7 +13,38 @@ describe Pounder::Server::Command do
|
|
13
13
|
output = double("TCPSocket")
|
14
14
|
output.should_receive(:print).with("+OK 100 10000\r\n")
|
15
15
|
@server.instance_variable_set(:@output, output)
|
16
|
-
@server.cmd_STAT(@maildir, [])
|
16
|
+
@server.cmd_STAT(maildir: @maildir, args: [])
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
describe "#cmd_QUIT" do
|
21
|
+
it "prints '+OK' and terminate the thread" do
|
22
|
+
output = double("TCPSocket")
|
23
|
+
output.should_receive(:print).with("+OK\r\n")
|
24
|
+
@server.instance_variable_set(:@output, output)
|
25
|
+
expect(@server).to receive(:terminate)
|
26
|
+
@server.send(:cmd_QUIT, maildir: @maildir, args: [])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_examples("no operation") do |cmd|
|
31
|
+
it "prints '+OK'" do
|
32
|
+
output = double("TCPSocket")
|
33
|
+
output.should_receive(:print).with("+OK\r\n")
|
34
|
+
@server.instance_variable_set(:@output, output)
|
35
|
+
@server.send(cmd, maildir: @maildir, args: [])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#cmd_USER" do
|
40
|
+
it_behaves_like "no operation", :cmd_USER
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#cmd_PASS" do
|
44
|
+
it_behaves_like "no operation", :cmd_PASS
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#cmd_DELE" do
|
48
|
+
it_behaves_like "no operation", :cmd_DELE
|
49
|
+
end
|
19
50
|
end
|
data/spec/pounder/server_spec.rb
CHANGED
@@ -22,4 +22,24 @@ describe Pounder::Server do
|
|
22
22
|
@server.print_line_message(".test")
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
describe "#read_cmd" do
|
27
|
+
context "@input.gets returns Command name only" do
|
28
|
+
it "returns Command name and empty array" do
|
29
|
+
input = double("TCPSocket")
|
30
|
+
input.should_receive(:gets).and_return("STAT")
|
31
|
+
@server.instance_variable_set(:@input, input)
|
32
|
+
expect(@server.read_cmd).to eq(["cmd_STAT", []])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "@input.gets returns Command name and args" do
|
37
|
+
it "returns Command name and an array whose elements are the args" do
|
38
|
+
input = double("TCPSocket")
|
39
|
+
input.should_receive(:gets).and_return("RETR 2")
|
40
|
+
@server.instance_variable_set(:@input, input)
|
41
|
+
expect(@server.read_cmd).to eq(["cmd_RETR", ["2"]])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
25
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sixpounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akihito Nakano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ackintosh-net-empty_port
|
@@ -76,7 +76,6 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- .coveralls.yml
|
78
78
|
- .gitignore
|
79
|
-
- .pounder/.gitkeep
|
80
79
|
- .rspec
|
81
80
|
- .travis.yml
|
82
81
|
- Gemfile
|
data/.pounder/.gitkeep
DELETED
File without changes
|