Class: Received::Connection

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/received/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, backend) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
# File 'lib/received/connection.rb', line 7

def initialize(server, backend)
  @server, @backend = server, backend
  @proto = LMTP.new(self)
end

Instance Method Details

#loggerObject



54
55
56
# File 'lib/received/connection.rb', line 54

def logger
  Received.logger
end

#mail_received(mail) ⇒ Boolean

Callback, called by protocol handler

Parameters:

  • mail (Hash)

Returns:

  • (Boolean)

    saving succeeded

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/received/connection.rb', line 38

def mail_received(mail)
  begin
    if insert_id = @backend.store(mail)
      logger.info "stored mail from: #{mail[:from]} (#{insert_id})"
      return true
    else
      logger.error "saving of mail from #{mail[:from]} failed"
    end
    false
  rescue Exception => e
    logger.error "saving of mail from #{mail[:from]} failed with: #{e.message}"
    logger.error e.backtrace.join("\n")
    false
  end
end

#post_initObject



12
13
14
15
# File 'lib/received/connection.rb', line 12

def post_init
  logger.debug "new connection"
  @proto.start!
end

#receive_data(data) ⇒ Object



17
18
19
20
# File 'lib/received/connection.rb', line 17

def receive_data(data)
  logger.debug {"receiving data: #{data.inspect}"}
  @proto.on_data(data)
end

#send_data(data) ⇒ Object



22
23
24
25
# File 'lib/received/connection.rb', line 22

def send_data(data)
  logger.debug {"sending data: #{data.inspect}"}
  super
end

#unbindObject

Client disconnected



28
29
30
31
# File 'lib/received/connection.rb', line 28

def unbind
  logger.debug "connection closed"
  @server.remove_connection(self)
end