remailer 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.6
@@ -27,6 +27,7 @@ class Remailer::Connection < EventMachine::Connection
27
27
 
28
28
  # == Properties ===========================================================
29
29
 
30
+ attr_accessor :active_message
30
31
  attr_accessor :remote, :max_size, :protocol, :hostname
31
32
  attr_accessor :pipelining, :tls_support, :auth_support
32
33
  attr_accessor :timeout
@@ -51,6 +52,7 @@ class Remailer::Connection < EventMachine::Connection
51
52
  # * error => Where to send errors (IO or Proc)
52
53
  # * on_connect => Called upon successful connection (Proc)
53
54
  # * on_error => Called upon connection error (Proc)
55
+ # * on_disconnect => Called when connection is closed (Proc)
54
56
  # A block can be supplied in which case it will stand in as the :connect
55
57
  # option. The block will recieve a first argument that is the status of
56
58
  # the connection, and an optional second that is a diagnostic message.
@@ -130,6 +132,7 @@ class Remailer::Connection < EventMachine::Connection
130
132
  STDERR.puts "#{e.class}: #{e}"
131
133
  end
132
134
 
135
+ # Returns true if the connection requires TLS support, or false otherwise.
133
136
  def use_tls?
134
137
  !!@options[:use_tls]
135
138
  end
@@ -195,12 +198,6 @@ class Remailer::Connection < EventMachine::Connection
195
198
  end
196
199
  end
197
200
 
198
- # Returns the details of the active message being sent, or nil if no message
199
- # is being sent.
200
- def active_message
201
- @active_message
202
- end
203
-
204
201
  # Reassigns the timeout which is specified in seconds. Values equal to
205
202
  # or less than zero are ignored and a default is used instead.
206
203
  def timeout=(value)
@@ -218,12 +215,14 @@ class Remailer::Connection < EventMachine::Connection
218
215
  # a connection closed event.
219
216
  def unbind
220
217
  @interpreter = nil
221
-
218
+
222
219
  if (@active_message)
223
220
  if (callback = @active_message[:callback])
224
221
  callback.call(nil)
225
222
  end
226
223
  end
224
+
225
+ send_callback(:on_disconnect)
227
226
  end
228
227
 
229
228
  # This implements the EventMachine::Connection#receive_data method that
@@ -244,15 +243,25 @@ class Remailer::Connection < EventMachine::Connection
244
243
  end
245
244
 
246
245
  def post_init
247
- EventMachine.add_periodic_timer(1) do
246
+ @timer = EventMachine.add_periodic_timer(1) do
248
247
  check_for_timeouts!
249
248
  end
250
249
  end
251
250
 
251
+ #
252
+ def detach
253
+ @timer.cancel
254
+ super
255
+ end
256
+
257
+ # Returns the current state of the active interpreter, or nil if no state
258
+ # is assigned.
252
259
  def state
253
260
  @interpreter and @interpreter.state
254
261
  end
255
262
 
263
+ # Sends a single line to the remote host with the appropriate CR+LF
264
+ # delmiter at the end.
256
265
  def send_line(line = '')
257
266
  reset_timeout!
258
267
 
@@ -274,13 +283,18 @@ class Remailer::Connection < EventMachine::Connection
274
283
  nil
275
284
  end
276
285
 
286
+ # Resets the timeout time. Returns the time at which a timeout will occur.
277
287
  def reset_timeout!
278
288
  @timeout_at = Time.now + @timeout
279
289
  end
280
290
 
291
+ # Checks for a timeout condition, and if one is detected, will close the
292
+ # connection and send appropriate callbacks.
281
293
  def check_for_timeouts!
282
294
  return if (!@timeout_at or Time.now < @timeout_at)
283
295
 
296
+ @timeout_at = nil
297
+
284
298
  error_notification(:timeout, "Connection timed out")
285
299
  debug_notification(:timeout, "Connection timed out")
286
300
  message_callback(:timeout, "Connection timed out before send could complete")
@@ -293,42 +307,54 @@ class Remailer::Connection < EventMachine::Connection
293
307
  close_connection
294
308
  end
295
309
 
310
+ # Returns true if pipelining support has been detected on the connection,
311
+ # false otherwise.
296
312
  def pipelining?
297
313
  !!@pipelining
298
314
  end
299
315
 
316
+ # Returns true if pipelining support has been detected on the connection,
317
+ # false otherwise.
300
318
  def tls_support?
301
319
  !!@tls_support
302
320
  end
303
321
 
322
+ # Returns true if the connection has been closed, false otherwise.
304
323
  def closed?
305
324
  !!@closed
306
325
  end
307
326
 
327
+ # Returns true if an error has occurred, false otherwise.
308
328
  def error?
309
329
  !!@error
310
330
  end
311
-
331
+
332
+ # EventMachine: Enables TLS support on the connection.
312
333
  def start_tls
313
334
  debug_notification(:tls, "Started")
314
335
  super
315
336
  end
316
-
337
+
338
+ # EventMachine: Closes down the connection.
317
339
  def close_connection
340
+ send_callback(:on_disconnect)
318
341
  debug_notification(:closed, "Connection closed")
319
342
  super
320
343
  @closed = true
321
344
  end
322
345
  alias_method :close, :close_connection
323
346
 
347
+ # Switches to use the SOCKS5 interpreter for all subsequent communication
324
348
  def use_socks5_interpreter!
325
349
  @interpreter = Remailer::Connection::Socks5Interpreter.new(:delegate => self)
326
350
  end
327
351
 
352
+ # Switches to use the SMTP interpreter for all subsequent communication
328
353
  def use_smtp_interpreter!
329
354
  @interpreter = Remailer::Connection::SmtpInterpreter.new(:delegate => self)
330
355
  end
331
356
 
357
+ # Callback receiver for when the proxy connection has been completed.
332
358
  def after_proxy_connected
333
359
  use_smtp_interpreter!
334
360
  end
@@ -161,7 +161,7 @@ class Remailer::Connection::SmtpInterpreter < Remailer::Interpreter
161
161
 
162
162
  state :mail_from do
163
163
  enter do
164
- delegate.send_line("MAIL FROM:#{delegate.active_message[:from]}")
164
+ delegate.send_line("MAIL FROM:<#{delegate.active_message[:from]}>")
165
165
  end
166
166
 
167
167
  interpret(250) do
@@ -171,7 +171,7 @@ class Remailer::Connection::SmtpInterpreter < Remailer::Interpreter
171
171
 
172
172
  state :rcpt_to do
173
173
  enter do
174
- delegate.send_line("RCPT TO:#{delegate.active_message[:to]}")
174
+ delegate.send_line("RCPT TO:<#{delegate.active_message[:to]}>")
175
175
  end
176
176
 
177
177
  interpret(250) do
@@ -253,7 +253,7 @@ class Remailer::Connection::SmtpInterpreter < Remailer::Interpreter
253
253
  end
254
254
 
255
255
  on_error do |reply_code, reply_message|
256
- delegate.send_callback(reply_code, reply_message)
256
+ delegate.message_callback(reply_code, reply_message)
257
257
  delegate.debug_notification(:error, "[#{@state}] #{reply_code} #{reply_message}")
258
258
  delegate.error_notification(reply_code, reply_message)
259
259
 
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.4"
8
+ s.version = "0.3.6"
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-16}
12
+ s.date = %q{2010-12-17}
13
13
  s.description = %q{EventMachine capable SMTP engine}
14
14
  s.email = %q{scott@twg.ca}
15
15
  s.extra_rdoc_files = [
@@ -192,13 +192,13 @@ class RemailerConnectionSmtpInterpreterTest < Test::Unit::TestCase
192
192
 
193
193
  assert_equal :mail_from, interpreter.state
194
194
 
195
- assert_equal 'MAIL FROM:from@example.com', delegate.read
195
+ assert_equal 'MAIL FROM:<from@example.com>', delegate.read
196
196
 
197
197
  interpreter.process("250 OK\r\n")
198
198
 
199
199
  assert_equal :rcpt_to, interpreter.state
200
200
 
201
- assert_equal 'RCPT TO:to@example.com', delegate.read
201
+ assert_equal 'RCPT TO:<to@example.com>', delegate.read
202
202
 
203
203
  interpreter.process("250 Accepted\r\n")
204
204
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 6
9
+ version: 0.3.6
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-16 00:00:00 -05:00
17
+ date: 2010-12-17 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20