Class: Remailer::SMTP::Client::Interpreter

Inherits:
Interpreter
  • Object
show all
Includes:
Constants
Defined in:
lib/remailer/smtp/client/interpreter.rb

Constant Summary

Constants included from Constants

Constants::CRLF, Constants::IMAPS_PORT, Constants::LINE_REGEXP, Constants::SMTP_PORT, Constants::SOCKS5_PORT

Instance Attribute Summary

Attributes inherited from Interpreter

#delegate, #error, #state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Interpreter

config, create_parser_for_spec, default, default_interpreter, default_parser, #enter_state, #error?, #finished?, initial_state, initial_state=, #initialize, #interpret, on_error, on_error_handler, parse, #parse, #parser, #process, state, state_defined?, states, states_default, states_defined, states_empty?

Constructor Details

This class inherits a constructor from Remailer::Interpreter

Class Method Details

.base64(string) ⇒ Object

Encodes a string in Base64 as a single line



29
30
31
# File 'lib/remailer/smtp/client/interpreter.rb', line 29

def self.base64(string)
  [ string.to_s ].pack('m').gsub(/\n/, '')
end

.encode_authentication(username, password) ⇒ Object

Encodes the given user authentication paramters as a Base64-encoded string as defined by RFC4954



18
19
20
# File 'lib/remailer/smtp/client/interpreter.rb', line 18

def self.encode_authentication(username, password)
  base64("\0#{username}\0#{password}")
end

.encode_data(data) ⇒ Object

Encodes the given data for an RFC5321-compliant stream where lines with leading period chracters are escaped.



24
25
26
# File 'lib/remailer/smtp/client/interpreter.rb', line 24

def self.encode_data(data)
  data.gsub(/((?:\r\n|\n)\.)/m, '\\1.')
end

.split_reply(reply) ⇒ Object

Expands a standard SMTP reply into three parts: Numerical code, message and a boolean indicating if this reply is continued on a subsequent line.



12
13
14
# File 'lib/remailer/smtp/client/interpreter.rb', line 12

def self.split_reply(reply)
  reply.match(/^(\d+)([ \-])(.*)/) and [ $1.to_i, $3, $2 == '-' ? :continued : nil ].compact
end

Instance Method Details

#closeObject



361
362
363
364
365
# File 'lib/remailer/smtp/client/interpreter.rb', line 361

def close
  if (@state == :ready)
    enter_state(:quit)
  end
end

#handle_reply_continuation(reply_code, reply_message, continues) ⇒ Object



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/remailer/smtp/client/interpreter.rb', line 367

def handle_reply_continuation(reply_code, reply_message, continues)
  @reply_message ||= ''
  
  if (preamble = @reply_message.split(/\s/).first)
    reply_message.sub!(/^#{preamble}/, '')
  end
  
  @reply_message << reply_message.gsub(/\s+/, ' ')
  
  unless (continues)
    yield(reply_code, @reply_message)

    @reply_message = nil
  end
end

#labelObject

Instance Methods =====================================================



357
358
359
# File 'lib/remailer/smtp/client/interpreter.rb', line 357

def label
  'SMTP'
end

#will_interpret?(proc, args) ⇒ Boolean

Returns:

  • (Boolean)


383
384
385
386
387
388
389
# File 'lib/remailer/smtp/client/interpreter.rb', line 383

def will_interpret?(proc, args)
  # Can only interpret blocks if the last part of the message has been
  # received. The continue flag is argument index 1. This will only apply
  # to interpret blocks that do not receive arguments.

  (proc.arity == 0) ? !args[1] : true
end