minbox 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 34bfc6208f399c85b149fb9febe81a997940696a0802d7326aa91aa55261e8d5
4
+ data.tar.gz: 77d432c13608ac84e4c9dcee94c018569d52ab9bdf486b08d28f626dd3def4ab
5
+ SHA512:
6
+ metadata.gz: fb60ac240af6400731e5b4031ef5d86b73739761ccc82c650a0b931ed3e4e5562fe24ed97b1d5765d01ecae9c3334622dba72b1bed3aa235179bd47ba2a8d9bc
7
+ data.tar.gz: 2d5c4b97db3e4b5d1d0621bc0a4af5eb461bd44ba1165362335cf9609bb173301c5498d860e94933be95e611bc7a351d1682f6fa5ac25455bf5348d4d756e5cb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in minbox.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minbox (0.1.0)
5
+ mail (~> 2.7)
6
+ redis (~> 4.1)
7
+ thor (~> 0.20)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.3)
13
+ mail (2.7.1)
14
+ mini_mime (>= 0.1.1)
15
+ mini_mime (1.0.1)
16
+ rake (10.5.0)
17
+ redis (4.1.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ thor (0.20.3)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 2.0)
38
+ minbox!
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 mokha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Minbox
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/minbox`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'minbox'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install minbox
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/minbox.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "minbox"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/minbox ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "minbox/cli"
4
+
5
+ Minbox::Cli::Application.start(ARGV)
data/lib/minbox/cli.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'thor'
2
+ require 'mail'
3
+
4
+ require 'minbox'
5
+
6
+ module Minbox
7
+ module Cli
8
+ class Application < Thor
9
+ package_name "minbox"
10
+
11
+ desc 'client <HOST> <PORT>', 'SMTP client'
12
+ def client(host = 'localhost', port = 25)
13
+ mail = Mail.new do
14
+ from 'Your Name <me@example.org>'
15
+ to 'Destination Address <them@example.com>'
16
+ subject 'test message'
17
+ body 'This is a test message.'
18
+ end
19
+ require 'net/smtp'
20
+ Net::SMTP.start(host, port) do |smtp|
21
+ smtp.send_message(mail.to_s, 'me@example.org', 'them@example.com')
22
+ end
23
+ end
24
+
25
+ method_option :output, type: :array, default: ['stdout']
26
+ desc 'server <HOST> <PORT>', 'SMTP server'
27
+ def server(host = 'localhost', port = '25')
28
+ publisher = publishers_for(options[:output])
29
+ Server.new(host, port).listen! do |mail|
30
+ publisher.publish(mail)
31
+ end
32
+ end
33
+
34
+ desc 'version', 'Display the current version'
35
+ def version
36
+ say Minbox::VERSION
37
+ end
38
+
39
+ private
40
+
41
+ def publishers_for(output)
42
+ publisher = Publisher.new
43
+ output.each do |x|
44
+ case x
45
+ when 'stdout'
46
+ publisher.add(LogPublisher.new)
47
+ when 'redis'
48
+ publisher.add(RedisPublisher.new)
49
+ when 'file'
50
+ publisher.add(FilePublisher.new)
51
+ end
52
+ end
53
+ publisher
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,52 @@
1
+ require 'redis'
2
+
3
+ module Minbox
4
+ class Publisher
5
+ attr_reader :publishers
6
+
7
+ def initialize(*publishers)
8
+ @publishers = Array(publishers)
9
+ end
10
+
11
+ def add(publisher)
12
+ publishers.push(publisher)
13
+ end
14
+
15
+ def publish(mail)
16
+ publishers.each { |x| x.publish(mail) }
17
+ end
18
+ end
19
+
20
+ class LogPublisher
21
+ def initialize(logger = STDOUT)
22
+ @logger = logger
23
+ end
24
+
25
+ def publish(mail)
26
+ @logger.puts mail.to_s
27
+ end
28
+ end
29
+
30
+ class RedisPublisher
31
+ def initialize(redis = Redis.new)
32
+ @redis = redis
33
+ end
34
+
35
+ def publish(mail)
36
+ @redis.publish("minbox", mail.to_s)
37
+ end
38
+ end
39
+
40
+ class FilePublisher
41
+ attr_reader :dir
42
+
43
+ def initialize(dir = Dir.pwd)
44
+ @dir = File.join(dir, "tmp")
45
+ FileUtils.mkdir_p(@dir)
46
+ end
47
+
48
+ def publish(mail)
49
+ IO.write(File.join(dir, "#{Time.now.to_i}.eml"), mail.to_s)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,53 @@
1
+ module Minbox
2
+ class Server
3
+ attr_reader :host, :port
4
+
5
+ def initialize(host, port)
6
+ @host = host
7
+ @port = port
8
+ end
9
+
10
+ def listen!
11
+ server = TCPServer.new(port.to_i)
12
+ loop do
13
+ yield handle(server.accept)
14
+ end
15
+ end
16
+
17
+ def handle(client)
18
+ mail = { headers: [], body: [] }
19
+
20
+ client.puts "220"
21
+ ehlo, _client_domain = client.gets.split(" ")
22
+
23
+ if ["HELO", "EHLO"].include?(ehlo)
24
+ client.puts "250-#{host}"
25
+ client.puts "250 OK"
26
+ else
27
+ puts 'Ooops...'
28
+ client.close
29
+ return
30
+ end
31
+
32
+ data = client.gets
33
+ until data.start_with?("DATA")
34
+ mail[:headers] << data
35
+ client.puts "250 OK"
36
+ data = client.gets
37
+ end
38
+ client.puts "354 End data with <CR><LF>.<CR><LF>"
39
+
40
+ data = client.gets
41
+ until data.match(/^\.\r\n$/)
42
+ mail[:body] << data
43
+ data = client.gets
44
+ end
45
+
46
+ client.puts "250 OK"
47
+ client.puts "221 Bye"
48
+ client.close
49
+
50
+ Mail.new(mail[:body].join)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Minbox
2
+ VERSION = "0.1.0"
3
+ end
data/lib/minbox.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'socket'
2
+
3
+ require "minbox/publisher"
4
+ require "minbox/server"
5
+ require "minbox/version"
6
+
7
+ module Minbox
8
+ class Error < StandardError; end
9
+ end
data/minbox.gemspec ADDED
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "minbox/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minbox"
8
+ spec.version = Minbox::VERSION
9
+ spec.authors = ["mo khan"]
10
+ spec.email = ["mo@mokhan.ca"]
11
+
12
+ spec.summary = %q{A minimal smtp server.}
13
+ spec.description = %q{A minimal smtp server.}
14
+ spec.homepage = "https://www.mokhan.ca/"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/mokhan/minbox"
22
+ spec.metadata["changelog_uri"] = "https://github.com/mokhan/minbox/blob/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "mail", "~> 2.7"
38
+ spec.add_dependency "redis", "~> 4.1"
39
+ spec.add_dependency "thor", "~> 0.20"
40
+ spec.add_development_dependency "bundler", "~> 2.0"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mo khan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: A minimal smtp server.
98
+ email:
99
+ - mo@mokhan.ca
100
+ executables:
101
+ - minbox
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/minbox
116
+ - lib/minbox.rb
117
+ - lib/minbox/cli.rb
118
+ - lib/minbox/publisher.rb
119
+ - lib/minbox/server.rb
120
+ - lib/minbox/version.rb
121
+ - minbox.gemspec
122
+ homepage: https://www.mokhan.ca/
123
+ licenses:
124
+ - MIT
125
+ metadata:
126
+ homepage_uri: https://www.mokhan.ca/
127
+ source_code_uri: https://github.com/mokhan/minbox
128
+ changelog_uri: https://github.com/mokhan/minbox/blob/CHANGELOG.md
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubygems_version: 3.0.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A minimal smtp server.
148
+ test_files: []