Class: Remailer::SMTP::Client::Interpreter
- Inherits:
-
Interpreter
- Object
- Interpreter
- Remailer::SMTP::Client::Interpreter
- 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
Class Method Summary collapse
-
.base64(string) ⇒ Object
Encodes a string in Base64 as a single line.
-
.encode_authentication(username, password) ⇒ Object
Encodes the given user authentication paramters as a Base64-encoded string as defined by RFC4954.
-
.encode_data(data) ⇒ Object
Encodes the given data for an RFC5321-compliant stream where lines with leading period chracters are escaped.
-
.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.
Instance Method Summary collapse
- #close ⇒ Object
- #handle_reply_continuation(reply_code, reply_message, continues) ⇒ Object
-
#label ⇒ Object
Instance Methods =====================================================.
- #will_interpret?(proc, args) ⇒ Boolean
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
32 33 34 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 32 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
21 22 23 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 21 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.
27 28 29 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 27 def self.encode_data(data) data.gsub(/\r?\n/, "\r\n").gsub(/\r\n\./, "\r\n..") 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.
15 16 17 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 15 def self.split_reply(reply) reply.match(/^(\d+)([ \-])(.*)/) and [ $1.to_i, $3, $2 == '-' ? :continued : nil ].compact end |
Instance Method Details
#close ⇒ Object
434 435 436 437 438 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 434 def close if (@state == :ready) enter_state(:quit) end end |
#handle_reply_continuation(reply_code, reply_message, continues) ⇒ Object
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 440 def handle_reply_continuation(reply_code, , continues) @reply_message ||= '' if (preamble = @reply_message.split(/\s/).first) .sub!(/^#{preamble}/, '') end @reply_message << .gsub(/\s+/, ' ') unless (continues) yield(reply_code, @reply_message) @reply_message = nil end end |
#label ⇒ Object
Instance Methods =====================================================
430 431 432 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 430 def label 'SMTP' end |
#will_interpret?(proc, args) ⇒ Boolean
456 457 458 459 460 461 462 |
# File 'lib/remailer/smtp/client/interpreter.rb', line 456 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 |