Class: Malm::SMTPServer

Inherits:
GServer
  • Object
show all
Defined in:
lib/malm/smtp_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mail_logObject

Returns the value of attribute mail_log.



7
8
9
# File 'lib/malm/smtp_server.rb', line 7

def mail_log
  @mail_log
end

#message_dbObject

Returns the value of attribute message_db.



8
9
10
# File 'lib/malm/smtp_server.rb', line 8

def message_db
  @message_db
end

Instance Method Details

#db_insert(message) ⇒ Object



29
30
31
32
33
34
# File 'lib/malm/smtp_server.rb', line 29

def db_insert(message)    
  message_data = {:subject => message.subject, :from => message.mail_from, :to => message.rcpt_to, :body => message.email_body}

  @mail_log_fd.puts(message_data.inspect) if @mail_log_fd
  @message_db.create(message_data) if @message_db
end

#serve(io) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/malm/smtp_server.rb', line 10

def serve(io)
  message = Message.new
  io.print message.process_line[:output]
  loop do
    data = io.gets
    response = message.process_line(data)
    io.print response[:output] if response[:output]
    break if response[:done]
    break if io.closed?
  end
  begin
    io.close
    db_insert(message)
  rescue => e
    log "something screwed up..."
    log e.backtrace
  end
end