From 50aaeca4af1b090e37dcb42d9d576e6a3ae107b6 Mon Sep 17 00:00:00 2001 From: doesnm Date: Fri, 26 Jan 2024 20:29:19 +0100 Subject: [PATCH] update mail.lua --- mail.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mail.lua b/mail.lua index 6651386..6f630dd 100644 --- a/mail.lua +++ b/mail.lua @@ -53,8 +53,12 @@ end from = nil to = nil +dir = nil data = false dataBuf = "" + +boxes = table.slice(arg,1)[1] + print("220 doesnm.cc Simple Mail Transfer Service Ready") while true do @@ -96,7 +100,20 @@ while true do else if string.starts(line[2],"TO:") then to = table.concat(table.slice(mysplit(table.concat(line," "),":"),2)) + +boxes = table.slice(arg,1) +for i=1,#boxes do +boxes[i] = mysplit(boxes[i],":") +if to:find(boxes[i][1]) then +dir = boxes[i][2] +break +end +end +if dir == nil then + print("550 mail adress not found and server don't support forwarding") +else print("250 OK") +end else print("502 Unrecognized command") end @@ -107,10 +124,14 @@ to = table.concat(table.slice(mysplit(table.concat(line," "),":"),2)) elseif line[1] == "." and data == true then if not validate(dataBuf,from,to) then print("250 NOTOK") data = false else - out = io.open("/var/mail/root","a") + + name = os.time() .. "." .. _G["posix.unistd"].getpid() .. "." .. os.execute("hostname") + ptf = dir .. "/tmp/" .. name + out = io.open(ptf,"w") out:write("From " .. from .." ".. os.date("%a %b %d %H:%M:%S %Y") .. "\n") out:write(dataBuf) out:close() + os.rename(ptf,dir .. "/new/" .. name) print("250 OK") data = false end