update mail.lua

This commit is contained in:
doesnm 2024-01-26 20:29:19 +01:00
parent 74dc85da83
commit 50aaeca4af

View file

@ -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