class Minbox::Client
Constants
- COMMANDS
- UNSUPPORTED
Attributes
logger[R]
server[R]
socket[R]
Public Class Methods
new(server, socket, logger)
click to toggle source
# File lib/minbox/client.rb, line 108 def initialize(server, socket, logger) @server = server @logger = logger @socket = socket end
Public Instance Methods
authenticate(username, password)
click to toggle source
# File lib/minbox/client.rb, line 153 def authenticate(username, password) logger.debug("#{username}:#{password}") return write '535 Authenticated failed - protocol error' unless username && password write '235 2.7.0 Authentication successful' end
close()
click to toggle source
# File lib/minbox/client.rb, line 144 def close socket&.close @socket = nil end
connected?()
click to toggle source
# File lib/minbox/client.rb, line 149 def connected? @socket end
handle(&block)
click to toggle source
# File lib/minbox/client.rb, line 114 def handle(&block) write "220 #{server.host} ESMTP" while connected? && (line = read) command = COMMANDS.fetch(line, UNSUPPORTED) command.run(self, line, &block) end close rescue Errno::ECONNRESET, Errno::EPIPE => error logger.error(error) close end
read()
click to toggle source
# File lib/minbox/client.rb, line 138 def read line = socket.gets logger.debug("C: #{line.inspect}") line end
secure_socket!()
click to toggle source
# File lib/minbox/client.rb, line 126 def secure_socket! socket = OpenSSL::SSL::SSLSocket.new(@socket, server.ssl_context) socket.sync_close = true @socket = socket.accept end
write(message)
click to toggle source
# File lib/minbox/client.rb, line 132 def write(message) message = "#{message}\r\n" logger.debug("S: #{message.inspect}") socket.puts message end