drillmail 0.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/drillmail/smtp.rb +120 -0
  3. data/lib/drillmail.rb +4 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 186a38793fadd8d744f887ab8d17651b3abe5ad7
4
+ data.tar.gz: fe73d341b7ccbce43cda5874994867ade69f90b9
5
+ SHA512:
6
+ metadata.gz: 65178e70f057ee13a395b090a92f50093b81db12c6f00c7b7341f75e218baf25280b6e4c43ef20b7613789f4a475865a546b11987d79acd98ebecd70876263f2
7
+ data.tar.gz: fe71c21c40e8de9a8f5b77a04866c21cd779294e37501e69f49c5656d40d851007918fed02d67a45ddf790f796580e9c73ae2f75ee2286361b2591136d618df1
@@ -0,0 +1,120 @@
1
+ require 'socket'
2
+ require_relative 'commands/definitions'
3
+ require_relative 'commands/hello'
4
+ require_relative 'commands/extended_hello'
5
+ require_relative 'commands/mail'
6
+ require_relative 'commands/recipient'
7
+ require_relative 'commands/data'
8
+ require_relative 'commands/reset'
9
+ require_relative 'commands/quit'
10
+
11
+ module SMTP
12
+ module_function
13
+
14
+ def listen(port, session_klass: SMTP::Session, host: '127.0.0.1')
15
+ @server = TCPServer.new port
16
+ puts "Listening on: #{port}"
17
+ loop do
18
+ Thread.start(session_klass.new(@server.accept, host)) do |session|
19
+ session.run
20
+ end
21
+ end
22
+ end
23
+
24
+ class Session
25
+ include Commands::Definitions
26
+
27
+ attr_accessor :connection
28
+ attr_accessor :host
29
+ attr_accessor :active
30
+ attr_accessor :domain
31
+ attr_accessor :reverse_path
32
+ attr_accessor :forward_path
33
+ attr_accessor :message
34
+
35
+ def initialize(connection, host)
36
+ @connection = connection
37
+ @host = host
38
+ @active = true
39
+ @domain = nil
40
+ setup_session
41
+ end
42
+
43
+ def setup_session
44
+ @reverse_path = ''
45
+ @forward_path = ''
46
+ @message = []
47
+ end
48
+
49
+ def run
50
+ begin
51
+ @connection.puts reply(220, "#{@host} Simple Mail Transfer")
52
+
53
+ while @active
54
+ @connection.sync = true
55
+ request = @connection.gets
56
+ response = route(process(request))
57
+ @connection.puts "#{response}\r\n"
58
+ end
59
+ rescue => e
60
+ @connection.puts reply(421, e)
61
+ puts e, e.backtrace
62
+ ensure
63
+ @connection.shutdown(:RDWR)
64
+ @connection.close
65
+ end
66
+ end
67
+
68
+ def process(request_string)
69
+ if request_string
70
+ request_array = request_string.split(' ')
71
+ {
72
+ command: request_array.shift.to_sym,
73
+ body: request_array.join(' ')
74
+ }
75
+ else
76
+ { command: :NOOP, body: '' }
77
+ end
78
+ end
79
+
80
+ def route(request)
81
+ puts "Requesting: #{request[:command]} #{request[:body]}"
82
+ if commands.key?(request[:command])
83
+ response = commands[request[:command]].call(request[:body])
84
+ else
85
+ response = reply(500)
86
+ end
87
+ puts "Responding: #{response}"
88
+ response
89
+ end
90
+ end
91
+ end
92
+
93
+ class MinimalSMTPSession < SMTP::Session
94
+ def hello(body)
95
+ HelloCommand.new(self, body).call
96
+ end
97
+ def extended_hello(body)
98
+ ExtendedHelloCommand.new(self, body).call
99
+ end
100
+ def mail(body)
101
+ MailCommand.new(self, body).call
102
+ end
103
+ def recipient(body)
104
+ RecipientCommand.new(self, body).call
105
+ end
106
+ def data(body)
107
+ DataCommand.new(self, body).call
108
+ end
109
+ def reset(body)
110
+ ResetCommand.new(self, body).call
111
+ end
112
+ def quit(body)
113
+ QuitCommand.new(self, body).call
114
+ end
115
+ def no_operation(body)
116
+ reply(250)
117
+ end
118
+ end
119
+
120
+ # SMTP.listen(5000, session_klass: MinimalSMTPSession)
data/lib/drillmail.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'drillmail/smtp'
2
+
3
+ module Drillmail
4
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drillmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jasper Lyons
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby implementation of the SMTP protocol that can be run as a deamon
14
+ email: jasper.lyons@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/drillmail.rb
20
+ - lib/drillmail/smtp.rb
21
+ homepage: https://github.com/releaseplatform/drillmail
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A Ruby mail server and library
45
+ test_files: []