blob: 4cb0e9d58276a3ccd850572aece4e2cd723a2d8f [file] [log] [blame]
PiBa-NLc3949d42018-12-23 21:06:31 +01001
2local vtc_port1 = 0
3local mailsreceived = 0
4local mailconnectionsmade = 0
5local healthcheckcounter = 0
6
PiBa-NLc3949d42018-12-23 21:06:31 +01007function RecieveAndCheck(applet, expect)
8 data = applet:getline()
9 if data:sub(1,expect:len()) ~= expect then
10 core.Info("Expected: "..expect.." but got:"..data:sub(1,expect:len()))
11 applet:send("Expected: "..expect.." but got:"..data.."\r\n")
12 return false
13 end
14 return true
15end
16
17core.register_service("mailservice", "tcp", function(applet)
18 core.Info("############# Mailservice Called #############")
19 mailconnectionsmade = mailconnectionsmade + 1
20 applet:send("220 Welcome\r\n")
21 local data
22
Christopher Faulet52912572022-06-08 11:57:52 +020023 if RecieveAndCheck(applet, "HELO") == false then
24 applet:set_var("txn.result", "ERROR (step: HELO)")
25 return
PiBa-NLc3949d42018-12-23 21:06:31 +010026 end
27 applet:send("250 OK\r\n")
28 if RecieveAndCheck(applet, "MAIL FROM:") == false then
Christopher Faulet52912572022-06-08 11:57:52 +020029 applet:set_var("txn.result", "ERROR (step: MAIL FROM)")
30 return
PiBa-NLc3949d42018-12-23 21:06:31 +010031 end
32 applet:send("250 OK\r\n")
33 if RecieveAndCheck(applet, "RCPT TO:") == false then
Christopher Faulet52912572022-06-08 11:57:52 +020034 applet:set_var("txn.result", "ERROR (step: RCPT TO)")
35 return
PiBa-NLc3949d42018-12-23 21:06:31 +010036 end
37 applet:send("250 OK\r\n")
38 if RecieveAndCheck(applet, "DATA") == false then
Christopher Faulet52912572022-06-08 11:57:52 +020039 applet:set_var("txn.result", "ERROR (step: DATA)")
40 return
PiBa-NLc3949d42018-12-23 21:06:31 +010041 end
42 applet:send("354 OK\r\n")
43 core.Info("#### Send your mailbody")
44 local endofmail = false
45 local subject = ""
46 while endofmail ~= true do
47 data = applet:getline() -- BODY CONTENT
48 --core.Info(data)
49 if data:sub(1, 9) == "Subject: " then
Christopher Faulet52912572022-06-08 11:57:52 +020050 subject = data
PiBa-NLc3949d42018-12-23 21:06:31 +010051 end
52 if (data == "\r\n") then
53 data = applet:getline() -- BODY CONTENT
54 core.Info(data)
55 if (data == ".\r\n") then
56 endofmail = true
57 end
58 end
59 end
Ilya Shipitsin77e3b4a2020-03-10 12:06:11 +050060 core.Info("#### Body received OK")
PiBa-NLc3949d42018-12-23 21:06:31 +010061 applet:send("250 OK\r\n")
62
63 if RecieveAndCheck(applet, "QUIT") == false then
Christopher Faulet52912572022-06-08 11:57:52 +020064 applet:set_var("txn.result", "ERROR (step: QUIT)")
65 return
PiBa-NLc3949d42018-12-23 21:06:31 +010066 end
67 applet:send("221 Mail queued for delivery to /dev/null \r\n")
68 core.Info("Mail queued for delivery to /dev/null subject: "..subject)
Christopher Faulet52912572022-06-08 11:57:52 +020069 applet:set_var("txn.result", "SUCCESS")
PiBa-NLc3949d42018-12-23 21:06:31 +010070end)