2018-12-23 20:06:31 +00:00
|
|
|
|
|
|
|
local vtc_port1 = 0
|
|
|
|
local mailsreceived = 0
|
|
|
|
local mailconnectionsmade = 0
|
|
|
|
local healthcheckcounter = 0
|
|
|
|
|
|
|
|
function RecieveAndCheck(applet, expect)
|
|
|
|
data = applet:getline()
|
|
|
|
if data:sub(1,expect:len()) ~= expect then
|
|
|
|
core.Info("Expected: "..expect.." but got:"..data:sub(1,expect:len()))
|
|
|
|
applet:send("Expected: "..expect.." but got:"..data.."\r\n")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
core.register_service("mailservice", "tcp", function(applet)
|
|
|
|
core.Info("############# Mailservice Called #############")
|
|
|
|
mailconnectionsmade = mailconnectionsmade + 1
|
|
|
|
applet:send("220 Welcome\r\n")
|
|
|
|
local data
|
|
|
|
|
2022-06-08 09:57:52 +00:00
|
|
|
if RecieveAndCheck(applet, "HELO") == false then
|
|
|
|
applet:set_var("txn.result", "ERROR (step: HELO)")
|
|
|
|
return
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
applet:send("250 OK\r\n")
|
|
|
|
if RecieveAndCheck(applet, "MAIL FROM:") == false then
|
2022-06-08 09:57:52 +00:00
|
|
|
applet:set_var("txn.result", "ERROR (step: MAIL FROM)")
|
|
|
|
return
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
applet:send("250 OK\r\n")
|
|
|
|
if RecieveAndCheck(applet, "RCPT TO:") == false then
|
2022-06-08 09:57:52 +00:00
|
|
|
applet:set_var("txn.result", "ERROR (step: RCPT TO)")
|
|
|
|
return
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
applet:send("250 OK\r\n")
|
|
|
|
if RecieveAndCheck(applet, "DATA") == false then
|
2022-06-08 09:57:52 +00:00
|
|
|
applet:set_var("txn.result", "ERROR (step: DATA)")
|
|
|
|
return
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
applet:send("354 OK\r\n")
|
|
|
|
core.Info("#### Send your mailbody")
|
|
|
|
local endofmail = false
|
|
|
|
local subject = ""
|
|
|
|
while endofmail ~= true do
|
|
|
|
data = applet:getline() -- BODY CONTENT
|
|
|
|
--core.Info(data)
|
|
|
|
if data:sub(1, 9) == "Subject: " then
|
2022-06-08 09:57:52 +00:00
|
|
|
subject = data
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
if (data == "\r\n") then
|
|
|
|
data = applet:getline() -- BODY CONTENT
|
|
|
|
core.Info(data)
|
|
|
|
if (data == ".\r\n") then
|
|
|
|
endofmail = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-10 07:06:11 +00:00
|
|
|
core.Info("#### Body received OK")
|
2018-12-23 20:06:31 +00:00
|
|
|
applet:send("250 OK\r\n")
|
|
|
|
|
|
|
|
if RecieveAndCheck(applet, "QUIT") == false then
|
2022-06-08 09:57:52 +00:00
|
|
|
applet:set_var("txn.result", "ERROR (step: QUIT)")
|
|
|
|
return
|
2018-12-23 20:06:31 +00:00
|
|
|
end
|
|
|
|
applet:send("221 Mail queued for delivery to /dev/null \r\n")
|
|
|
|
core.Info("Mail queued for delivery to /dev/null subject: "..subject)
|
2022-06-08 09:57:52 +00:00
|
|
|
applet:set_var("txn.result", "SUCCESS")
|
2018-12-23 20:06:31 +00:00
|
|
|
end)
|