remailer 0.3.0 → 0.3.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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/remailer/connection.rb
CHANGED
@@ -31,6 +31,7 @@ class Remailer::Connection < EventMachine::Connection
|
|
31
31
|
attr_accessor :pipelining, :tls_support
|
32
32
|
attr_accessor :timeout
|
33
33
|
attr_accessor :options
|
34
|
+
attr_reader :error, :error_message
|
34
35
|
|
35
36
|
# == Extensions ===========================================================
|
36
37
|
|
@@ -46,6 +47,8 @@ class Remailer::Connection < EventMachine::Connection
|
|
46
47
|
# * debug => Where to send debugging output (IO or Proc)
|
47
48
|
# * connect => Where to send a connection notification (IO or Proc)
|
48
49
|
# * error => Where to send errors (IO or Proc)
|
50
|
+
# * on_connect => Called upon successful connection (Proc)
|
51
|
+
# * on_error => Called upon connection error (Proc)
|
49
52
|
# A block can be supplied in which case it will stand in as the :connect
|
50
53
|
# option. The block will recieve a first argument that is the status of
|
51
54
|
# the connection, and an optional second that is a diagnostic message.
|
@@ -269,10 +272,11 @@ class Remailer::Connection < EventMachine::Connection
|
|
269
272
|
|
270
273
|
error_notification(:timeout, "Connection timed out")
|
271
274
|
debug_notification(:timeout, "Connection timed out")
|
272
|
-
|
275
|
+
message_callback(:timeout, "Connection timed out before send could complete")
|
273
276
|
|
274
277
|
unless (@connected)
|
275
278
|
connect_notification(false, "Connection timed out")
|
279
|
+
send_callback(:on_error)
|
276
280
|
end
|
277
281
|
|
278
282
|
close_connection
|
@@ -290,6 +294,10 @@ class Remailer::Connection < EventMachine::Connection
|
|
290
294
|
!!@closed
|
291
295
|
end
|
292
296
|
|
297
|
+
def error?
|
298
|
+
!!@error
|
299
|
+
end
|
300
|
+
|
293
301
|
def start_tls
|
294
302
|
debug_notification(:tls, "Started")
|
295
303
|
super
|
@@ -332,7 +340,7 @@ class Remailer::Connection < EventMachine::Connection
|
|
332
340
|
end
|
333
341
|
|
334
342
|
def after_message_sent(reply_code, reply_message)
|
335
|
-
|
343
|
+
message_callback(reply_code, reply_message)
|
336
344
|
|
337
345
|
@active_message = nil
|
338
346
|
end
|
@@ -356,9 +364,13 @@ class Remailer::Connection < EventMachine::Connection
|
|
356
364
|
|
357
365
|
def connect_notification(code, message = nil)
|
358
366
|
send_notification(:connect, code, message || self.remote)
|
367
|
+
send_callback(:on_success)
|
359
368
|
end
|
360
369
|
|
361
370
|
def error_notification(code, message)
|
371
|
+
@error = code
|
372
|
+
@error_message = message
|
373
|
+
|
362
374
|
send_notification(:error, code, message)
|
363
375
|
end
|
364
376
|
|
@@ -366,7 +378,7 @@ class Remailer::Connection < EventMachine::Connection
|
|
366
378
|
send_notification(:debug, code, message)
|
367
379
|
end
|
368
380
|
|
369
|
-
def
|
381
|
+
def message_callback(reply_code, reply_message)
|
370
382
|
if (callback = (@active_message and @active_message[:callback]))
|
371
383
|
# The callback is screened in advance when assigned to ensure that it
|
372
384
|
# has only 1 or 2 arguments. There should be no else here.
|
@@ -378,4 +390,15 @@ class Remailer::Connection < EventMachine::Connection
|
|
378
390
|
end
|
379
391
|
end
|
380
392
|
end
|
393
|
+
|
394
|
+
def send_callback(type)
|
395
|
+
if (callback = @options[type])
|
396
|
+
case (callback.arity)
|
397
|
+
when 1
|
398
|
+
callback.call(self)
|
399
|
+
else
|
400
|
+
callback.call
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
381
404
|
end
|
data/remailer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{remailer}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Scott Tadman"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{EventMachine capable SMTP engine}
|
14
14
|
s.email = %q{scott@twg.ca}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -2,6 +2,7 @@ require File.expand_path(File.join(*%w[ .. helper ]), File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
class SmtpDelegate
|
4
4
|
attr_accessor :options, :active_message
|
5
|
+
attr_accessor :tls_support
|
5
6
|
|
6
7
|
def initialize(options = { })
|
7
8
|
@sent = [ ]
|
@@ -32,6 +33,10 @@ class SmtpDelegate
|
|
32
33
|
!!@started_tls
|
33
34
|
end
|
34
35
|
|
36
|
+
def tls_support?
|
37
|
+
!!@tls_support
|
38
|
+
end
|
39
|
+
|
35
40
|
def close_connection
|
36
41
|
@closed = true
|
37
42
|
end
|
@@ -250,8 +255,12 @@ class RemailerConnectionSmtpInterpreterTest < Test::Unit::TestCase
|
|
250
255
|
def test_tls_connection_with_support
|
251
256
|
delegate = SmtpDelegate.new(:use_tls => true)
|
252
257
|
interpreter = Remailer::Connection::SmtpInterpreter.new(:delegate => delegate)
|
258
|
+
|
259
|
+
assert_equal true, delegate.use_tls?
|
260
|
+
assert_equal :initialized, interpreter.state
|
253
261
|
|
254
262
|
interpreter.process("220 mail.example.com ESMTP Exim 4.63\r\n")
|
263
|
+
assert_equal :ehlo, interpreter.state
|
255
264
|
assert_equal 'EHLO localhost.local', delegate.read
|
256
265
|
|
257
266
|
interpreter.process("250-mail.example.com Hello\r\n")
|
@@ -262,6 +271,8 @@ class RemailerConnectionSmtpInterpreterTest < Test::Unit::TestCase
|
|
262
271
|
interpreter.process("250-STARTTLS\r\n")
|
263
272
|
interpreter.process("250 HELP\r\n")
|
264
273
|
|
274
|
+
assert_equal true, delegate.tls_support?
|
275
|
+
|
265
276
|
assert_equal :starttls, interpreter.state
|
266
277
|
assert_equal 'STARTTLS', delegate.read
|
267
278
|
assert_equal false, delegate.started_tls?
|
@@ -40,6 +40,8 @@ class RemailerConnectionTest < Test::Unit::TestCase
|
|
40
40
|
def test_failed_connect_no_service
|
41
41
|
engine do
|
42
42
|
error_received = nil
|
43
|
+
on_error = false
|
44
|
+
on_connect = false
|
43
45
|
|
44
46
|
connection = Remailer::Connection.open(
|
45
47
|
'example.com',
|
@@ -47,6 +49,8 @@ class RemailerConnectionTest < Test::Unit::TestCase
|
|
47
49
|
:error => lambda { |code, message|
|
48
50
|
error_received = [ code, message ]
|
49
51
|
},
|
52
|
+
:on_connect => lambda { on_connect = true },
|
53
|
+
:on_error => lambda { on_error = true },
|
50
54
|
:timeout => 1
|
51
55
|
)
|
52
56
|
|
@@ -55,6 +59,10 @@ class RemailerConnectionTest < Test::Unit::TestCase
|
|
55
59
|
end
|
56
60
|
|
57
61
|
assert_equal :timeout, error_received[0]
|
62
|
+
assert_equal :timeout, connection.error
|
63
|
+
|
64
|
+
assert_equal false, on_connect
|
65
|
+
assert_equal true, on_error
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott Tadman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-13 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|