~aleteoryx/nex.nelua

ref: b12592a5d5e562781216e7e3e33d0baca47042f1 nex.nelua/nps.nelua -rw-r--r-- 871 bytes
b12592a5Aleteoryx configurable connection cap 17 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)