-
Notifications
You must be signed in to change notification settings - Fork 0
/
smtp_serv.rb
44 lines (40 loc) · 1022 Bytes
/
smtp_serv.rb
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44
require 'gserver'
Thread.abort_on_exception = true
$logfile = "/home/shelvacu/emails"
if !File.exist?($logfile)
File.open($logfile,'wt'){}
end
$f = File.open($logfile,'at')
END{$f.close}
class SMTPServer < GServer
def initialize(port=12345,*opts)
super(port,*opts)
end
def serve(io)
$f.puts
$f.puts "-----------------------New thingy-----------------"
$f.puts
io.puts "220 localhost Simple Mail Transfer Agent Service Ready"
while io.open?
msg = io.gets
$f.puts msg.chomp
if msg.start_with?("HELO")
io.puts "250 localhost"
elsif msg.start_with?("DATA")
io.puts "354 Start mail input; end with <CRLF>.<CRLF>"
while (msg = io.gets.chomp) != "."
$f.puts msg.chomp
end
io.puts "250 OK"
elsif msg.start_with?("QUIT")
io.puts "221 localhost Service closing transmission channel"
io.close
else
io.puts "250 OK"
end
end
end
end
serv = SMTPServer.new
serv.start
#serv.join