remailer 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -5
- data/README.md +3 -2
- data/VERSION +1 -1
- data/lib/remailer/abstract_connection.rb +14 -3
- data/lib/remailer/interpreter.rb +25 -12
- data/lib/remailer/interpreter/state_proxy.rb +1 -1
- data/remailer.gemspec +6 -4
- data/test/config.example.yml +15 -0
- data/test/config.rb +41 -0
- data/test/config.yml.enc +0 -0
- data/test/helper.rb +33 -14
- data/test/unit/remailer_imap_client_test.rb +5 -7
- data/test/unit/remailer_interpreter_test.rb +29 -21
- data/test/unit/remailer_smtp_client_test.rb +41 -38
- data/test/unit/remailer_smtp_server_test.rb +11 -5
- metadata +5 -3
- data/test/config.example.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022aa4b49c91bd2c7f1ae3658ae9d78e9a04d685
|
4
|
+
data.tar.gz: b83390f1d9584990b4d2667109c9ac6b72d22add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e92d0bb514b5206c8f58c2d235af41afe3bf6038f501eb596f3499f97ad5cdc74505a2ec13fdf54e384a99eff49d4727717cb9fbbbfa35ae7b7e144448fe1018
|
7
|
+
data.tar.gz: b52a67442c4f6ce913edca676bb0f1a25fa1d546c531197332f0e9e07845b09fe30a586ee76c55ba20a0a39c9bf85c6658081f77b0f477ff3bf6a57eeb6cdf5c
|
data/.travis.yml
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
language: ruby
|
2
|
-
before_install:
|
2
|
+
before_install:
|
3
|
+
- openssl aes-256-cbc -K $encrypted_fdddf752110a_key -iv $encrypted_fdddf752110a_iv
|
4
|
+
-in test/config.yml.enc -out test/config.yml -d
|
5
|
+
- gem install bundler
|
3
6
|
rvm:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
- 1.9.3-p551
|
8
|
+
- 2.0.0-p598
|
9
|
+
- 2.1.5
|
10
|
+
- 2.2.0
|
data/README.md
CHANGED
@@ -92,9 +92,10 @@ A status code of nil is sent if the server timed out or the connection failed.
|
|
92
92
|
|
93
93
|
## Tests
|
94
94
|
|
95
|
-
In order to run tests, copy `test/config.example.
|
95
|
+
In order to run tests, copy `test/config.example.yml` to `test/config.yml` and
|
96
96
|
adjust as required. For obvious reasons, passwords to SMTP test accounts are
|
97
|
-
not included in the source code of this library.
|
97
|
+
not included in the source code of this library. Any Gmail-type account should
|
98
|
+
serve as a useful test target.
|
98
99
|
|
99
100
|
## Status
|
100
101
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.1
|
@@ -151,9 +151,19 @@ class Remailer::AbstractConnection < EventMachine::Connection
|
|
151
151
|
self.after_initialize
|
152
152
|
|
153
153
|
rescue Object => e
|
154
|
-
|
154
|
+
report_exception(e)
|
155
|
+
|
156
|
+
STDERR.puts "#{e.class}: #{e}" rescue nil
|
155
157
|
end
|
156
|
-
|
158
|
+
|
159
|
+
def after_complete
|
160
|
+
if (block_given?)
|
161
|
+
@options[:after_complete] = Proc.new
|
162
|
+
elsif (@options[:after_complete])
|
163
|
+
@options[:after_complete].call
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
157
167
|
# Returns true if the connection requires TLS support, or false otherwise.
|
158
168
|
def use_tls?
|
159
169
|
!!@options[:use_tls]
|
@@ -244,7 +254,8 @@ class Remailer::AbstractConnection < EventMachine::Connection
|
|
244
254
|
end
|
245
255
|
|
246
256
|
rescue Object => e
|
247
|
-
|
257
|
+
self.report_exception(e)
|
258
|
+
STDERR.puts("[#{e.class}] #{e}") rescue nil
|
248
259
|
|
249
260
|
raise e
|
250
261
|
end
|
data/lib/remailer/interpreter.rb
CHANGED
@@ -27,21 +27,37 @@ class Remailer::Interpreter
|
|
27
27
|
def self.initial_state=(state)
|
28
28
|
@initial_state = state
|
29
29
|
end
|
30
|
+
|
31
|
+
def self.config
|
32
|
+
{
|
33
|
+
states: @states,
|
34
|
+
default_interpreter: @default,
|
35
|
+
default_parser: @parser,
|
36
|
+
on_error_handler: @on_error
|
37
|
+
}
|
38
|
+
end
|
30
39
|
|
40
|
+
def self.states_default
|
41
|
+
{
|
42
|
+
:initialized => { },
|
43
|
+
:terminated => { }
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
31
47
|
# Returns the states that are defined as a has with their associated
|
32
48
|
# options. The default keys are :initialized and :terminated.
|
33
49
|
def self.states
|
34
50
|
@states ||=
|
35
|
-
|
36
|
-
when true
|
51
|
+
if (superclass.respond_to?(:states))
|
37
52
|
superclass.states.dup
|
38
53
|
else
|
39
|
-
|
40
|
-
:initialized => { },
|
41
|
-
:terminated => { }
|
42
|
-
}
|
54
|
+
self.states_default
|
43
55
|
end
|
44
56
|
end
|
57
|
+
|
58
|
+
def self.states_empty?
|
59
|
+
self.states == self.states_default
|
60
|
+
end
|
45
61
|
|
46
62
|
# Returns true if a given state is defined, false otherwise.
|
47
63
|
def self.state_defined?(state)
|
@@ -114,8 +130,7 @@ class Remailer::Interpreter
|
|
114
130
|
# Returns the parser used when no state-specific parser has been defined.
|
115
131
|
def self.default_parser
|
116
132
|
@parser ||=
|
117
|
-
|
118
|
-
when true
|
133
|
+
if (superclass.respond_to?(:default_parser))
|
119
134
|
superclass.default_parser
|
120
135
|
else
|
121
136
|
lambda { |s| _s = s.dup; s.replace(''); _s }
|
@@ -125,8 +140,7 @@ class Remailer::Interpreter
|
|
125
140
|
# Returns the current default_interpreter.
|
126
141
|
def self.default_interpreter
|
127
142
|
@default ||=
|
128
|
-
|
129
|
-
when true
|
143
|
+
if (superclass.respond_to?(:default_interpreter))
|
130
144
|
superclass.default_interpreter
|
131
145
|
else
|
132
146
|
nil
|
@@ -136,8 +150,7 @@ class Remailer::Interpreter
|
|
136
150
|
# Returns the defined error handler
|
137
151
|
def self.on_error_handler
|
138
152
|
@on_error ||=
|
139
|
-
|
140
|
-
when true
|
153
|
+
if (superclass.respond_to?(:on_error_handler))
|
141
154
|
superclass.on_error_handler
|
142
155
|
else
|
143
156
|
nil
|
@@ -14,7 +14,7 @@ class Remailer::Interpreter::StateProxy
|
|
14
14
|
|
15
15
|
# Defines a parser specification.
|
16
16
|
def parse(spec = nil, &block)
|
17
|
-
@options[:parser] = Remailer::Interpreter.
|
17
|
+
@options[:parser] = Remailer::Interpreter.create_parser_for_spec(spec, &block)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Defines a block that will execute when the state is entered.
|
data/remailer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: remailer 0.
|
5
|
+
# stub: remailer 0.7.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "remailer"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.7.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Scott Tadman"]
|
14
|
-
s.date = "2015-01-
|
14
|
+
s.date = "2015-01-31"
|
15
15
|
s.description = "EventMachine SMTP Mail User Agent"
|
16
16
|
s.email = "scott@twg.ca"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -47,7 +47,9 @@ Gem::Specification.new do |s|
|
|
47
47
|
"lib/remailer/support.rb",
|
48
48
|
"remailer.gemspec",
|
49
49
|
"test/bin/exercise",
|
50
|
-
"test/config.example.
|
50
|
+
"test/config.example.yml",
|
51
|
+
"test/config.rb",
|
52
|
+
"test/config.yml.enc",
|
51
53
|
"test/helper.rb",
|
52
54
|
"test/unit/remailer_imap_client_interpreter_test.rb",
|
53
55
|
"test/unit/remailer_imap_client_test.rb",
|
@@ -0,0 +1,15 @@
|
|
1
|
+
smtp_server:
|
2
|
+
host: "smtp.gmail.com"
|
3
|
+
identifier: "smtp.gmail.com"
|
4
|
+
|
5
|
+
public_smtp_server:
|
6
|
+
host: "smtp.gmail.com"
|
7
|
+
identifier: "mx.google.com"
|
8
|
+
username: "<account>@gmail.com"
|
9
|
+
password: "<password>"
|
10
|
+
port: 587
|
11
|
+
|
12
|
+
proxy_server: "<proxy.server>"
|
13
|
+
|
14
|
+
recipient: "<account>@gmail.com"
|
15
|
+
sender: "<account>@gmail.com"
|
data/test/config.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class TestConfig < Hash
|
4
|
+
CONFIG_FILE = 'config.yml'
|
5
|
+
|
6
|
+
def self.options
|
7
|
+
@options ||= begin
|
8
|
+
config_path = File.expand_path(CONFIG_FILE, File.dirname(__FILE__))
|
9
|
+
|
10
|
+
unless (File.exist?(config_path))
|
11
|
+
raise "Config #{CONFIG_FILE} not found. Copy test/config.example.yml and fill in appropriate test settings."
|
12
|
+
end
|
13
|
+
|
14
|
+
new(config_path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(path)
|
19
|
+
merge!(symbolized_keys(YAML.load(File.open(path))))
|
20
|
+
end
|
21
|
+
|
22
|
+
def symbolized_keys(object)
|
23
|
+
case (object)
|
24
|
+
when Hash
|
25
|
+
Hash[
|
26
|
+
object.collect do |key, value|
|
27
|
+
[
|
28
|
+
key ? key.to_sym : key,
|
29
|
+
symbolized_keys(value)
|
30
|
+
]
|
31
|
+
end
|
32
|
+
]
|
33
|
+
when Array
|
34
|
+
object.collect do |value|
|
35
|
+
symbolized_keys(value)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
object
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test/config.yml.enc
ADDED
Binary file
|
data/test/helper.rb
CHANGED
@@ -51,36 +51,64 @@ module TestTriggerHelper
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
if (ENV['DEBUG'])
|
55
|
+
STDERR.sync = true
|
56
|
+
end
|
57
|
+
|
54
58
|
class MiniTest::Test
|
59
|
+
def debug_channel
|
60
|
+
ENV['DEBUG'] ? STDERR : nil
|
61
|
+
end
|
62
|
+
|
55
63
|
def engine
|
56
64
|
exception = nil
|
65
|
+
test_thread = nil
|
57
66
|
|
58
|
-
|
67
|
+
engine_thread =
|
59
68
|
Thread.new do
|
60
69
|
Thread.abort_on_exception = true
|
61
70
|
|
62
71
|
# Create a thread for the engine to run on
|
63
72
|
begin
|
64
73
|
EventMachine.run
|
74
|
+
|
65
75
|
rescue Object => exception
|
66
76
|
end
|
67
|
-
end
|
77
|
+
end
|
78
|
+
|
79
|
+
test_thread =
|
68
80
|
Thread.new do
|
69
81
|
# Execute the test code in a separate thread to avoid blocking
|
70
82
|
# the EventMachine loop.
|
71
83
|
begin
|
84
|
+
while (!EventMachine.reactor_running?)
|
85
|
+
# Wait impatiently.
|
86
|
+
end
|
87
|
+
|
72
88
|
yield
|
73
89
|
rescue Object => exception
|
74
90
|
ensure
|
75
91
|
begin
|
76
92
|
EventMachine.stop_event_loop
|
77
93
|
rescue Object
|
94
|
+
STDERR.puts("[#{exception.class}] #{exception}")
|
78
95
|
# Shutting down may trigger an exception from time to time
|
79
96
|
# if the engine itself has failed.
|
80
97
|
end
|
81
98
|
end
|
82
99
|
end
|
83
|
-
|
100
|
+
|
101
|
+
test_thread.join
|
102
|
+
|
103
|
+
begin
|
104
|
+
Timeout.timeout(1) do
|
105
|
+
engine_thread.join
|
106
|
+
end
|
107
|
+
rescue Timeout::Error
|
108
|
+
engine_thread.kill
|
109
|
+
|
110
|
+
fail 'Execution timed out'
|
111
|
+
end
|
84
112
|
|
85
113
|
if (exception)
|
86
114
|
raise exception
|
@@ -89,6 +117,7 @@ class MiniTest::Test
|
|
89
117
|
|
90
118
|
def assert_timeout(time, message = nil, &block)
|
91
119
|
Timeout::timeout(time, &block)
|
120
|
+
|
92
121
|
rescue Timeout::Error
|
93
122
|
flunk(message || 'assert_timeout timed out')
|
94
123
|
end
|
@@ -123,14 +152,4 @@ class MiniTest::Test
|
|
123
152
|
end
|
124
153
|
end
|
125
154
|
|
126
|
-
|
127
|
-
|
128
|
-
TestConfig = OpenStruct.new
|
129
|
-
|
130
|
-
config_file = File.expand_path("config.rb", File.dirname(__FILE__))
|
131
|
-
|
132
|
-
if (File.exist?(config_file))
|
133
|
-
require config_file
|
134
|
-
else
|
135
|
-
raise "No test/config.rb file found. Copy and modify test/config.example.rb"
|
136
|
-
end
|
155
|
+
require_relative 'config'
|
@@ -1,17 +1,15 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
|
3
3
|
class RemailerIMAPClientTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
STDERR.sync = true
|
6
|
-
end
|
7
|
-
|
8
4
|
def test_connect
|
5
|
+
skip
|
6
|
+
|
9
7
|
engine do
|
10
8
|
debug = { }
|
11
9
|
|
12
10
|
client = Remailer::IMAP::Client.open(
|
13
|
-
TestConfig.imap_server[:host],
|
14
|
-
debug:
|
11
|
+
TestConfig.options[:imap_server][:host],
|
12
|
+
debug: self.debug_channel,
|
15
13
|
connect: lambda { |success, host| connected_host = host }
|
16
14
|
)
|
17
15
|
|
@@ -37,7 +35,7 @@ class RemailerIMAPClientTest < MiniTest::Test
|
|
37
35
|
|
38
36
|
login_status = nil
|
39
37
|
|
40
|
-
client.login(TestConfig.smtp_server[:username], TestConfig.smtp_server[:password]) do |status, message|
|
38
|
+
client.login(TestConfig.options[:smtp_server][:username], TestConfig.options[:smtp_server][:password]) do |status, message|
|
41
39
|
login_status = status
|
42
40
|
end
|
43
41
|
|
@@ -1,5 +1,19 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
|
3
|
+
class RegexpInterpreter < Remailer::Interpreter
|
4
|
+
attr_reader :received
|
5
|
+
|
6
|
+
state :initialized do
|
7
|
+
interpret(/^HELO\s+/) do |line|
|
8
|
+
@received = [ :helo, line ]
|
9
|
+
end
|
10
|
+
|
11
|
+
interpret(/^MAIL FROM:<([^>]+)>/) do |line|
|
12
|
+
@received = [ :mail_from, line ]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
class ExampleDelegate
|
4
18
|
include TestTriggerHelper
|
5
19
|
|
@@ -46,20 +60,6 @@ class LineInterpreterSubclass < LineInterpreter
|
|
46
60
|
end
|
47
61
|
end
|
48
62
|
|
49
|
-
class RegexpInterpreter < Remailer::Interpreter
|
50
|
-
attr_reader :received
|
51
|
-
|
52
|
-
state :initialized do
|
53
|
-
interpret(/^HELO\s+/) do |line|
|
54
|
-
@received = [ :helo, line ]
|
55
|
-
end
|
56
|
-
|
57
|
-
interpret(/^MAIL FROM:<([^>]+)>/) do |line|
|
58
|
-
@received = [ :mail_from, line ]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
63
|
class ExampleInterpreter < Remailer::Interpreter
|
64
64
|
include TestTriggerHelper
|
65
65
|
|
@@ -107,13 +107,19 @@ end
|
|
107
107
|
|
108
108
|
class RemailerInterpreterTest < MiniTest::Test
|
109
109
|
def test_default_state
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
test_interpreter_class = Class.new(Remailer::Interpreter)
|
111
|
+
|
112
|
+
assert test_interpreter_class.states_empty?
|
113
|
+
|
114
|
+
assert_equal [ :initialized, :terminated ], test_interpreter_class.states_defined.collect { |s| s.to_s }.sort.collect { |s| s.to_sym }
|
115
|
+
assert_equal true, test_interpreter_class.state_defined?(:initialized)
|
116
|
+
assert_equal true, test_interpreter_class.state_defined?(:terminated)
|
117
|
+
assert_equal false, test_interpreter_class.state_defined?(:unknown)
|
118
|
+
|
119
|
+
assert_equal [ :initialized, :terminated ], test_interpreter_class.states_defined
|
120
|
+
|
121
|
+
interpreter = test_interpreter_class.new
|
114
122
|
|
115
|
-
interpreter = Remailer::Interpreter.new
|
116
|
-
|
117
123
|
assert_equal :initialized, interpreter.state
|
118
124
|
|
119
125
|
buffer = 'a'
|
@@ -124,11 +130,13 @@ class RemailerInterpreterTest < MiniTest::Test
|
|
124
130
|
end
|
125
131
|
|
126
132
|
def test_delegate
|
133
|
+
test_interpreter_class = Class.new(Remailer::Interpreter)
|
134
|
+
|
127
135
|
delegate = ExampleDelegate.new
|
128
136
|
|
129
137
|
assert delegate.triggered
|
130
138
|
|
131
|
-
interpreter =
|
139
|
+
interpreter = test_interpreter_class.new(delegate: delegate)
|
132
140
|
|
133
141
|
assert_equal nil, delegate.attribute
|
134
142
|
assert_equal false, delegate.triggered[:method_no_args]
|
@@ -7,8 +7,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
7
7
|
connected_host = nil
|
8
8
|
|
9
9
|
connection = Remailer::SMTP::Client.open(
|
10
|
-
TestConfig.
|
11
|
-
debug:
|
10
|
+
TestConfig.options[:public_smtp_server][:host],
|
11
|
+
debug: self.debug_channel,
|
12
12
|
connect: lambda { |success, host| connected_host = host }
|
13
13
|
)
|
14
14
|
|
@@ -27,11 +27,11 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
27
27
|
connection.closed?
|
28
28
|
end
|
29
29
|
|
30
|
-
assert_equal TestConfig.
|
30
|
+
assert_equal TestConfig.options[:public_smtp_server][:identifier], connected_host
|
31
31
|
|
32
32
|
assert_equal true, after_complete_trigger
|
33
33
|
|
34
|
-
assert_equal
|
34
|
+
assert_equal 35882577, connection.max_size
|
35
35
|
assert_equal :esmtp, connection.protocol
|
36
36
|
assert_equal true, connection.tls_support?
|
37
37
|
end
|
@@ -45,7 +45,7 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
45
45
|
|
46
46
|
connection = Remailer::SMTP::Client.open(
|
47
47
|
'example.com',
|
48
|
-
debug:
|
48
|
+
debug: self.debug_channel,
|
49
49
|
error: lambda { |code, message|
|
50
50
|
error_received = [ code, message ]
|
51
51
|
},
|
@@ -72,7 +72,7 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
72
72
|
|
73
73
|
connection = Remailer::SMTP::Client.open(
|
74
74
|
'invalid-example-domain--x.com',
|
75
|
-
debug:
|
75
|
+
debug: self.debug_channel,
|
76
76
|
error: lambda { |code, message|
|
77
77
|
error_received = [ code, message ]
|
78
78
|
},
|
@@ -92,11 +92,11 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
92
92
|
debug = { }
|
93
93
|
|
94
94
|
connection = Remailer::SMTP::Client.open(
|
95
|
-
TestConfig.
|
96
|
-
port: TestConfig.
|
97
|
-
debug:
|
98
|
-
username: TestConfig.
|
99
|
-
password: TestConfig.
|
95
|
+
TestConfig.options[:smtp_server][:host],
|
96
|
+
port: TestConfig.options[:smtp_server][:port] || Remailer::SMTP::Client::SMTP_PORT,
|
97
|
+
debug: self.debug_channel,
|
98
|
+
username: TestConfig.options[:smtp_server][:username],
|
99
|
+
password: TestConfig.options[:smtp_server][:password]
|
100
100
|
)
|
101
101
|
|
102
102
|
after_complete_trigger = false
|
@@ -113,11 +113,11 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
113
113
|
connection.closed?
|
114
114
|
end
|
115
115
|
|
116
|
-
assert_equal TestConfig.public_smtp_server[:identifier], connection.remote
|
116
|
+
assert_equal TestConfig.options[:public_smtp_server][:identifier], connection.remote
|
117
117
|
|
118
118
|
assert_equal true, after_complete_trigger
|
119
119
|
|
120
|
-
assert_equal
|
120
|
+
assert_equal 35882577, connection.max_size
|
121
121
|
assert_equal :esmtp, connection.protocol
|
122
122
|
assert_equal true, connection.tls_support?
|
123
123
|
end
|
@@ -128,11 +128,11 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
128
128
|
debug = { }
|
129
129
|
|
130
130
|
connection = Remailer::SMTP::Client.open(
|
131
|
-
TestConfig.
|
132
|
-
debug:
|
131
|
+
TestConfig.options[:public_smtp_server][:host],
|
132
|
+
debug: self.debug_channel,
|
133
133
|
proxy: {
|
134
134
|
proto: :socks5,
|
135
|
-
host: TestConfig.proxy_server
|
135
|
+
host: TestConfig.options[:proxy_server]
|
136
136
|
}
|
137
137
|
)
|
138
138
|
|
@@ -143,18 +143,18 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
143
143
|
after_complete_trigger = true
|
144
144
|
end
|
145
145
|
|
146
|
-
assert_equal :
|
146
|
+
assert_equal :initialized, connection.state
|
147
147
|
assert !connection.error?
|
148
148
|
|
149
149
|
assert_eventually(15) do
|
150
150
|
connection.closed?
|
151
151
|
end
|
152
152
|
|
153
|
-
assert_equal TestConfig.
|
153
|
+
assert_equal TestConfig.options[:public_smtp_server][:identifier], connection.remote
|
154
154
|
|
155
155
|
assert_equal true, after_complete_trigger
|
156
156
|
|
157
|
-
assert_equal
|
157
|
+
assert_equal 35882577, connection.max_size
|
158
158
|
assert_equal :esmtp, connection.protocol
|
159
159
|
assert_equal true, connection.tls_support?
|
160
160
|
end
|
@@ -163,8 +163,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
163
163
|
def test_connect_and_send_after_start
|
164
164
|
engine do
|
165
165
|
connection = Remailer::SMTP::Client.open(
|
166
|
-
TestConfig.
|
167
|
-
debug:
|
166
|
+
TestConfig.options[:public_smtp_server][:host],
|
167
|
+
debug: self.debug_channel
|
168
168
|
)
|
169
169
|
|
170
170
|
assert_equal :initialized, connection.state
|
@@ -177,8 +177,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
177
177
|
callback_received = false
|
178
178
|
|
179
179
|
connection.send_email(
|
180
|
-
|
181
|
-
|
180
|
+
TestConfig.options[:sender],
|
181
|
+
TestConfig.options[:recipient],
|
182
182
|
example_message
|
183
183
|
) do |c|
|
184
184
|
callback_received = true
|
@@ -196,8 +196,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
196
196
|
def test_connect_and_send_dotted_message
|
197
197
|
engine do
|
198
198
|
connection = Remailer::SMTP::Client.open(
|
199
|
-
TestConfig.
|
200
|
-
debug:
|
199
|
+
TestConfig.options[:public_smtp_server][:host],
|
200
|
+
debug: self.debug_channel
|
201
201
|
)
|
202
202
|
|
203
203
|
assert_equal :initialized, connection.state
|
@@ -205,8 +205,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
205
205
|
|
206
206
|
result_code = nil
|
207
207
|
connection.send_email(
|
208
|
-
|
209
|
-
|
208
|
+
TestConfig.options[:sender],
|
209
|
+
TestConfig.options[:recipient],
|
210
210
|
example_message + "\r\n\.\r\nHam sandwich.\r\n"
|
211
211
|
) do |c|
|
212
212
|
result_code = c
|
@@ -221,8 +221,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
221
221
|
def test_connect_and_send_multiple
|
222
222
|
engine do
|
223
223
|
connection = Remailer::SMTP::Client.open(
|
224
|
-
TestConfig.
|
225
|
-
debug:
|
224
|
+
TestConfig.options[:public_smtp_server][:host],
|
225
|
+
debug: self.debug_channel
|
226
226
|
)
|
227
227
|
|
228
228
|
assert_equal :initialized, connection.state
|
@@ -231,9 +231,12 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
231
231
|
result_code = [ ]
|
232
232
|
|
233
233
|
10.times do |n|
|
234
|
+
recipient_parts = TestConfig.options[:sender].split(/@/)
|
235
|
+
recipient_parts.insert(1, n)
|
236
|
+
|
234
237
|
connection.send_email(
|
235
|
-
|
236
|
-
|
238
|
+
TestConfig.options[:sender],
|
239
|
+
'%s+%d@%s' % recipient_parts,
|
237
240
|
example_message
|
238
241
|
) do |c|
|
239
242
|
result_code[n] = c
|
@@ -249,8 +252,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
249
252
|
def test_connect_and_long_send
|
250
253
|
engine do
|
251
254
|
connection = Remailer::SMTP::Client.open(
|
252
|
-
TestConfig.
|
253
|
-
debug:
|
255
|
+
TestConfig.options[:public_smtp_server][:host],
|
256
|
+
debug: self.debug_channel
|
254
257
|
)
|
255
258
|
|
256
259
|
assert_equal :initialized, connection.state
|
@@ -259,8 +262,8 @@ class RemailerSMTPClientTest < MiniTest::Test
|
|
259
262
|
result_code = nil
|
260
263
|
|
261
264
|
connection.send_email(
|
262
|
-
TestConfig.sender,
|
263
|
-
TestConfig.recipient,
|
265
|
+
TestConfig.options[:sender],
|
266
|
+
TestConfig.options[:recipient],
|
264
267
|
example_message + 'a' * 100000
|
265
268
|
) do |c|
|
266
269
|
callback_made = true
|
@@ -279,9 +282,9 @@ protected
|
|
279
282
|
def example_message
|
280
283
|
example = <<__END__
|
281
284
|
Date: Sat, 13 Nov 2010 02:25:24 +0000
|
282
|
-
From: #{TestConfig.sender}
|
283
|
-
To: Remailer Test <#{TestConfig.receiver}>
|
284
|
-
Message-Id: <hfLkcIByfjYoNIxCO7DMsxBTX9svsFHikIOfAiYy@#{TestConfig.sender.split(/@/).last}>
|
285
|
+
From: #{TestConfig.options[:sender]}
|
286
|
+
To: Remailer Test <#{TestConfig.options[:receiver]}>
|
287
|
+
Message-Id: <hfLkcIByfjYoNIxCO7DMsxBTX9svsFHikIOfAiYy@#{TestConfig.options[:sender].split(/@/).last}>
|
285
288
|
Subject: Example Subject
|
286
289
|
Mime-Version: 1.0
|
287
290
|
Content-Type: text/plain
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
|
3
3
|
class RemailerSMTPServerTest < MiniTest::Test
|
4
|
+
def random_server_port
|
5
|
+
@server_port ||= 9000 + rand(4096)
|
6
|
+
|
7
|
+
@server_port += 1
|
8
|
+
end
|
9
|
+
|
4
10
|
def test_bind
|
5
11
|
engine do
|
6
|
-
server_port =
|
12
|
+
server_port = random_server_port
|
7
13
|
|
8
14
|
server = Remailer::SMTP::Server.bind(nil, server_port)
|
9
15
|
|
@@ -13,7 +19,7 @@ class RemailerSMTPServerTest < MiniTest::Test
|
|
13
19
|
|
14
20
|
def test_connect
|
15
21
|
engine do
|
16
|
-
server_port =
|
22
|
+
server_port = random_server_port
|
17
23
|
|
18
24
|
remote_ip = nil
|
19
25
|
|
@@ -30,7 +36,7 @@ class RemailerSMTPServerTest < MiniTest::Test
|
|
30
36
|
client = Remailer::SMTP::Client.open(
|
31
37
|
'localhost',
|
32
38
|
port: server_port,
|
33
|
-
debug:
|
39
|
+
debug: self.debug_channel,
|
34
40
|
connect: lambda { |success, host| connected_host = host }
|
35
41
|
)
|
36
42
|
|
@@ -45,7 +51,7 @@ class RemailerSMTPServerTest < MiniTest::Test
|
|
45
51
|
|
46
52
|
def test_transaction
|
47
53
|
engine do
|
48
|
-
server_port =
|
54
|
+
server_port = random_server_port
|
49
55
|
|
50
56
|
transaction = nil
|
51
57
|
|
@@ -62,7 +68,7 @@ class RemailerSMTPServerTest < MiniTest::Test
|
|
62
68
|
client = Remailer::SMTP::Client.open(
|
63
69
|
'localhost',
|
64
70
|
port: server_port,
|
65
|
-
debug:
|
71
|
+
debug: self.debug_channel
|
66
72
|
)
|
67
73
|
|
68
74
|
sender = 'sender@example.com'.freeze
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Tadman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -88,7 +88,9 @@ files:
|
|
88
88
|
- lib/remailer/support.rb
|
89
89
|
- remailer.gemspec
|
90
90
|
- test/bin/exercise
|
91
|
-
- test/config.example.
|
91
|
+
- test/config.example.yml
|
92
|
+
- test/config.rb
|
93
|
+
- test/config.yml.enc
|
92
94
|
- test/helper.rb
|
93
95
|
- test/unit/remailer_imap_client_interpreter_test.rb
|
94
96
|
- test/unit/remailer_imap_client_test.rb
|
data/test/config.example.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
TestConfig.smtp_server = {
|
2
|
-
host: "smtp.example.com",
|
3
|
-
identifier: "smtp.example.com"
|
4
|
-
}
|
5
|
-
|
6
|
-
TestConfig.public_smtp_server = {
|
7
|
-
host: "smtp.gmail.com",
|
8
|
-
identifier: "mx.google.com",
|
9
|
-
username: "--your--username--gmail.com",
|
10
|
-
password: "--your--password--",
|
11
|
-
port: 587
|
12
|
-
}
|
13
|
-
|
14
|
-
TestConfig.proxy_server = "proxy.example.com"
|
15
|
-
|
16
|
-
TestConfig.recipient = "--your--email--"
|
17
|
-
TestConfig.sender = "--your--email--"
|