Class: Minbox::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/minbox/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, socket, logger) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
# File 'lib/minbox/client.rb', line 5

def initialize(server, socket, logger)
  @server = server
  @logger = logger
  @socket = socket
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/minbox/client.rb', line 3

def logger
  @logger
end

#serverObject (readonly)

Returns the value of attribute server.



3
4
5
# File 'lib/minbox/client.rb', line 3

def server
  @server
end

#socketObject (readonly)

Returns the value of attribute socket.



3
4
5
# File 'lib/minbox/client.rb', line 3

def socket
  @socket
end

Instance Method Details

#handle(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/minbox/client.rb', line 11

def handle(&block)
  write "220 #{server.host} ESMTP"
  while connected? && (line = read)
    case line
    when /^EHLO/i then ehlo(line)
    when /^HELO/i then helo(line)
    when /^MAIL FROM/i then mail_from(line)
    when /^RCPT TO/i then rcpt_to(line)
    when /^DATA/i then data(line, &block)
    when /^QUIT/i then quit
    when /^STARTTLS/i then start_tls
    when /^RSET/i then reset
    when /^NOOP/i then noop
    when /^AUTH PLAIN/i then auth_plain(line)
    when /^AUTH LOGIN/i then (line)
    else
      logger.error(line)
      write '502 Invalid/unsupported command'
    end
  end
  close
rescue Errno::ECONNRESET, Errno::EPIPE => error
  logger.error(error)
  close
end