PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 1 | |
| 2 | local vtc_port1 = 0 |
| 3 | local mailsreceived = 0 |
| 4 | local mailconnectionsmade = 0 |
| 5 | local healthcheckcounter = 0 |
| 6 | |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 7 | function 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 |
| 15 | end |
| 16 | |
| 17 | core.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 Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 23 | if RecieveAndCheck(applet, "HELO") == false then |
| 24 | applet:set_var("txn.result", "ERROR (step: HELO)") |
| 25 | return |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 26 | end |
| 27 | applet:send("250 OK\r\n") |
| 28 | if RecieveAndCheck(applet, "MAIL FROM:") == false then |
Christopher Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 29 | applet:set_var("txn.result", "ERROR (step: MAIL FROM)") |
| 30 | return |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 31 | end |
| 32 | applet:send("250 OK\r\n") |
| 33 | if RecieveAndCheck(applet, "RCPT TO:") == false then |
Christopher Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 34 | applet:set_var("txn.result", "ERROR (step: RCPT TO)") |
| 35 | return |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 36 | end |
| 37 | applet:send("250 OK\r\n") |
| 38 | if RecieveAndCheck(applet, "DATA") == false then |
Christopher Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 39 | applet:set_var("txn.result", "ERROR (step: DATA)") |
| 40 | return |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 41 | 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 Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 50 | subject = data |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 51 | 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 Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 60 | core.Info("#### Body received OK") |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 61 | applet:send("250 OK\r\n") |
| 62 | |
| 63 | if RecieveAndCheck(applet, "QUIT") == false then |
Christopher Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 64 | applet:set_var("txn.result", "ERROR (step: QUIT)") |
| 65 | return |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 66 | 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 Faulet | 5291257 | 2022-06-08 11:57:52 +0200 | [diff] [blame] | 69 | applet:set_var("txn.result", "SUCCESS") |
PiBa-NL | c3949d4 | 2018-12-23 21:06:31 +0100 | [diff] [blame] | 70 | end) |