Class: Mailpot::Smtp

Inherits:
EventMachine::Protocols::SmtpServer
  • Object
show all
Defined in:
lib/mailpot/smtp.rb

Instance Method Summary collapse

Instance Method Details

#current_messageObject



6
7
8
# File 'lib/mailpot/smtp.rb', line 6

def current_message
 @current_message ||= {}
end

#get_server_domainObject



25
26
27
# File 'lib/mailpot/smtp.rb', line 25

def get_server_domain
 Mailpot::Configuration.domain
end

#get_server_greetingObject



15
16
17
18
19
20
21
22
23
# File 'lib/mailpot/smtp.rb', line 15

def get_server_greeting
 yml = Mailpot::Configuration.key_data
 host = get_server_domain
 t = DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
 banner = yml['banner']
 banner = banner.gsub('{host}', host)
 banner = banner.gsub('{date}', t)
 return banner
end

#receive_data_chunk(lines) ⇒ Object



39
40
41
42
43
# File 'lib/mailpot/smtp.rb', line 39

def receive_data_chunk(lines)
 current_message[:source] ||= ""
 current_message[:source] += lines.join("\n")
 true
end

#receive_messageObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mailpot/smtp.rb', line 45

def receive_message
 port, ip = Socket.unpack_sockaddr_in(get_peername)
 current_message[:ip] = ip
 current_message[:port] = port
 Mailpot::Mail.add_message current_message
 puts "==> SMTP: Received message from '#{current_message[:sender]}' (#{current_message[:source].length} bytes)"
 true
rescue
 puts "*** Error receiving message: #{current_message.inspect}"
 puts "    Exception: #{$!}"
 puts "    Backtrace:"
 $!.backtrace.each do |line|
  puts "      #{line}"
 end
 puts "    Please submit this as an issue at https://github.com/mjezorek/Mailpot/issues"
 false
ensure
 @current_message = nil
end

#receive_recipient(recipient) ⇒ Object



33
34
35
36
37
# File 'lib/mailpot/smtp.rb', line 33

def receive_recipient(recipient)
 current_message[:recipients] ||= []
 current_message[:recipients] << recipient
 true
end

#receive_resetObject



10
11
12
13
# File 'lib/mailpot/smtp.rb', line 10

def receive_reset
 @current_message = nil
 true
end

#receive_sender(sender) ⇒ Object



29
30
31
# File 'lib/mailpot/smtp.rb', line 29

def receive_sender(sender)
 current_message[:sender] = sender
end