## pragmas.abort = 'exit'
local socket = require 'socket'
require 'vector'
require 'io'
require 'arg'
if #arg ~= 1 then
print("Usage: nps.nelua <ADDRESS>")
print("ADDRESS may be one of:")
print(" `<ipv4 addr>:<port>'")
print(" `{<ipv6 addr>}:<port>'")
end
socket.listen_tcp(arg[1], 1024, function()
local target = socket.recv_line():gsub("\r", "")
local lines: vector(string)
local line = socket.recv_line()
while line:gsub("\r", "") ~= "." do
lines:push(line)
line = socket.recv_line()
end
local ok, matches
if (do ok, matches = target:match("^mail/(.+)$"); in ok end) then
io.writef("Mail for %s:\n", matches[1])
for i=0,<#lines do
print("Mail:", lines[i])
end
else
socket.send("Unknown target: ")
socket.send_line(target)
socket.send_line("If you're testing this out, try editing nps.nelua!")
end
socket.end_conn()
end)