sixpounder 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: daebc7217416ee1c2e770e33cec1fcc54f1ddca6
4
+ data.tar.gz: b9a512de46dbd072fdce75584c907fc68a78668e
5
+ SHA512:
6
+ metadata.gz: bdb3e273c4b0e1b9814c91d87d24b3e526a0828e48077509f8295c896edbe45915278da16fdfc736c603f648d23819aa27a98833b39567ea3fc8622725358d12
7
+ data.tar.gz: 63509273547ce906f75ed67d1b141c61f6a5d005c4f58b525d5f4494a0b3b7af10c6ab4dbdc359c7a07c557ac6c6d674e768377ca95f9d10ca76439f945f0800
@@ -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
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pounder.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Akihito Nakano
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.
@@ -0,0 +1,34 @@
1
+ # Pounder
2
+
3
+ Pounder is a POP server for operation verification for the system to
4
+ parse the mail.
5
+
6
+ ## Installation
7
+
8
+ $ gem install pounder
9
+
10
+ ## Usage
11
+
12
+ ### mail data
13
+
14
+ Create a `.pounder` directory in the current directory.
15
+
16
+ Save `.pounder` directory the source of the email that you want to
17
+ operation verification.
18
+
19
+ ### start
20
+
21
+ $ bundle exec pounder {port}
22
+
23
+ If POP acceess to the host that started Pounder, you can get the mail
24
+ data that is prepared in advance.
25
+
26
+ It will not be deleted when you receive mail, you can repeat access.
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pounder'
4
+ port = $*[0].to_i
5
+ Pounder::Server.invoke(port)
@@ -0,0 +1,9 @@
1
+ require "pounder/version"
2
+ require "pounder/server/command"
3
+ require "pounder/server"
4
+ require "pounder/maildir/message"
5
+ require "pounder/maildir"
6
+
7
+ module Pounder
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,27 @@
1
+ module Pounder
2
+ class Maildir
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+
7
+ def messages
8
+ @messages ||=
9
+ begin
10
+ seq = 0
11
+ Dir.entries(@path).select { |entry| File.ftype("#{@path}/#{entry}") == "file" }.map { |filename| Message.new(@path, filename, (seq += 1), File.size("#{@path}/#{filename}")) }
12
+ end
13
+ end
14
+
15
+ def size
16
+ messages.size
17
+ end
18
+
19
+ def total_octets
20
+ messages.inject(0) { |total, message| total += message.octets }
21
+ end
22
+
23
+ def [](seq)
24
+ messages.find { |m| m.seq == seq }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module Pounder
2
+ class Maildir
3
+ class Message
4
+ attr_reader :octets, :seq
5
+
6
+ def initialize(dir, name, seq, octets)
7
+ @dir = dir
8
+ @name = name
9
+ @seq = seq
10
+ @octets = octets
11
+ end
12
+
13
+ def each_line
14
+ File.foreach("#{@dir}/#{@name}") do |line|
15
+ yield line.sub(/\r?\n\z/, "\r\n")
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,70 @@
1
+ module Pounder
2
+ class Server
3
+ include Command
4
+
5
+ def self.invoke(port)
6
+ new.listen(port)
7
+ end
8
+
9
+ def listen(port)
10
+ server = TCPServer.new(port)
11
+ puts "#{self.class}##{__method__} port=#{port}"
12
+
13
+ maildir_path = "#{Dir::pwd}/.pounder"
14
+ puts "Maildir: #{maildir_path}"
15
+ maildir = Maildir.new(maildir_path)
16
+
17
+ while true
18
+ Thread.fork(server.accept) do |sock|
19
+ p sock
20
+ service(sock, sock, maildir)
21
+ end
22
+ end
23
+ end
24
+
25
+ def service(input, output, maildir)
26
+ @input = input
27
+ @output = output
28
+ print_line "+OK pounder"
29
+
30
+ while cmds = read_cmd()
31
+ cmd_name = cmds.shift
32
+ args = cmds.shift
33
+ unless respond_to?(cmd_name)
34
+ print_line "-ERR unknown command"
35
+ next
36
+ end
37
+
38
+ __send__(cmd_name, maildir, args)
39
+ end
40
+ end
41
+
42
+ def print_line(str)
43
+ @output.print "#{str}\r\n"
44
+ end
45
+
46
+ def print_line_message(str)
47
+ @output.print str.sub(/\A\./, "..")
48
+ end
49
+
50
+ def read_cmd
51
+ cmd_name, *args = @input.gets.split
52
+ ["cmd_#{cmd_name.chomp}", args]
53
+ end
54
+
55
+ def terminate
56
+ begin
57
+ @input.close_read
58
+ rescue
59
+ end
60
+
61
+ begin
62
+ @output.close_write
63
+ rescue
64
+ end
65
+
66
+ Thread.exit
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,46 @@
1
+ module Pounder
2
+ class Server
3
+ module Command
4
+ def cmd_STAT(maildir, args)
5
+ print_line "+OK #{maildir.size} #{maildir.total_octets}"
6
+ end
7
+
8
+ def cmd_LIST(maildir, args)
9
+ print_line "+OK"
10
+ maildir.messages.each do |m|
11
+ print_line "#{m.seq} #{m.octets}"
12
+ end
13
+ print_line "."
14
+ end
15
+
16
+ def cmd_USER(maildir, args)
17
+ # nop.
18
+ print_line "+OK"
19
+ end
20
+
21
+ def cmd_PASS(maildir, args)
22
+ # nop.
23
+ print_line "+OK"
24
+ end
25
+
26
+ def cmd_DELE(maildir, args)
27
+ # nop.
28
+ print_line "+OK"
29
+ end
30
+
31
+ def cmd_QUIT(maildir, args)
32
+ print_line "+OK"
33
+ terminate
34
+ end
35
+
36
+ def cmd_RETR(maildir, args)
37
+ message = maildir[args.first.to_i]
38
+ print_line "+OK"
39
+ message.each_line do |line|
40
+ print_line_message line
41
+ end
42
+ print_line "."
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Pounder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pounder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sixpounder"
8
+ spec.version = Pounder::VERSION
9
+ spec.authors = ["Akihito Nakano"]
10
+ spec.email = ["sora.akatsuki@gmail.com"]
11
+ spec.description = %q{POP server}
12
+ spec.summary = %q{POP server for operation verification}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pounder::Maildir::Message do
4
+ context "when initialized" do
5
+ before do
6
+ @message = Pounder::Maildir::Message.new("/test", "test", 5, 100)
7
+ end
8
+
9
+ it "has a path" do
10
+ expect(@message.instance_variable_get(:@dir)).to eq "/test"
11
+ end
12
+
13
+ it "has a filename" do
14
+ expect(@message.instance_variable_get(:@name)).to eq "test"
15
+ end
16
+
17
+ it "has a sequence" do
18
+ expect(@message.instance_variable_get(:@seq)).to eq 5
19
+ end
20
+
21
+ it "has a bytes" do
22
+ expect(@message.instance_variable_get(:@octets)).to eq 100
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pounder::Maildir do
4
+ before :each do
5
+ @maildir = Pounder::Maildir.new("/test")
6
+ end
7
+
8
+ describe ".size" do
9
+ it "returns count of messages" do
10
+ @maildir.instance_variable_set(:@messages, ["m","m","m"])
11
+ expect(@maildir.size).to eq 3
12
+ end
13
+ end
14
+
15
+ describe ".total_octets" do
16
+ it "returns total number of bytes" do
17
+ messages = []
18
+ 3.times do |n|
19
+ m = Class.new
20
+ m.stub(:octets).and_return(100)
21
+ messages << m
22
+ end
23
+ @maildir.instance_variable_set(:@messages, messages)
24
+ expect(@maildir.total_octets).to eq 300
25
+ end
26
+ end
27
+
28
+ describe ".[]" do
29
+ it "returns the message specified by the argument" do
30
+ messages = []
31
+ 3.times do |n|
32
+ m = Class.new
33
+ m.instance_variable_set(:@idx, n)
34
+ m.stub(:seq).and_return(n + 1)
35
+ messages << m
36
+ end
37
+ @maildir.instance_variable_set(:@messages, messages)
38
+ expect(@maildir[2].instance_variable_get(:@idx)).to eq 1
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pounder::Server::Command do
4
+ before :each do
5
+ @server = Pounder::Server.new
6
+ @maildir = Pounder::Maildir.new("")
7
+ end
8
+
9
+ describe "#cmd_STAT" do
10
+ it "outputs size and total_octets of Pounder::Maildir" do
11
+ @maildir.stub(:size).and_return(100)
12
+ @maildir.stub(:total_octets).and_return(10000)
13
+ output = double("TCPSocket")
14
+ output.should_receive(:print).with("+OK 100 10000\r\n")
15
+ @server.instance_variable_set(:@output, output)
16
+ @server.cmd_STAT(@maildir, [])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pounder::Server do
4
+ before :each do
5
+ @server = Pounder::Server.new
6
+ end
7
+
8
+ describe "#print_line" do
9
+ it "outputs by adding new line to string" do
10
+ output = double("TCPSocket")
11
+ output.should_receive(:print).with("test\r\n")
12
+ @server.instance_variable_set(:@output, output)
13
+ @server.print_line("test")
14
+ end
15
+ end
16
+
17
+ describe "#print_line_message" do
18
+ it "outputs by replacing the dot at the beginning of the line" do
19
+ output = double("TCPSocket")
20
+ output.should_receive(:print).with("..test")
21
+ @server.instance_variable_set(:@output, output)
22
+ @server.print_line_message(".test")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pounder do
4
+ it 'has a version number' do
5
+ expect(Pounder::VERSION).to_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'pounder'
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixpounder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Akihito Nakano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: POP server
56
+ email:
57
+ - sora.akatsuki@gmail.com
58
+ executables:
59
+ - pounder
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .pounder/.gitkeep
65
+ - .rspec
66
+ - .travis.yml
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/pounder
72
+ - lib/pounder.rb
73
+ - lib/pounder/maildir.rb
74
+ - lib/pounder/maildir/message.rb
75
+ - lib/pounder/server.rb
76
+ - lib/pounder/server/command.rb
77
+ - lib/pounder/version.rb
78
+ - pounder.gemspec
79
+ - spec/pounder/maildir/message_spec.rb
80
+ - spec/pounder/maildir_spec.rb
81
+ - spec/pounder/server/command_spec.rb
82
+ - spec/pounder/server_spec.rb
83
+ - spec/pounder_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: ''
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: POP server for operation verification
109
+ test_files:
110
+ - spec/pounder/maildir/message_spec.rb
111
+ - spec/pounder/maildir_spec.rb
112
+ - spec/pounder/server/command_spec.rb
113
+ - spec/pounder/server_spec.rb
114
+ - spec/pounder_spec.rb
115
+ - spec/spec_helper.rb