comparison src/send.json.luan @ 0:bd4802730bab

its working
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 18 May 2023 21:20:59 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bd4802730bab
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local new_error = Luan.new_error or error()
4 local stringify = Luan.stringify or error()
5 local Parsers = require "luan:Parsers.luan"
6 local json_parse = Parsers.json_parse or error()
7 local json_string = Parsers.json_string or error()
8 local Io = require "luan:Io.luan"
9 local Http = require "luan:http/Http.luan"
10 local Mail = require "luan:mail/Mail.luan"
11 local Logging = require "luan:logging/Logging.luan"
12 local logger = Logging.logger "send.json"
13
14
15 local function user_error(msg)
16 local e = new_error(msg)
17 e.error = {
18 okay = false
19 error = msg
20 }
21 e.throw()
22 end
23
24 return function()
25 Io.stdout = Http.response.text_writer()
26 try
27 local server = Http.request.parameters.server or user_error "parameter 'server' missing"
28 local mail = Http.request.parameters.mail or user_error "parameter 'mail' missing"
29 try
30 server = json_parse(server)
31 catch e
32 user_error "invalid JSON in 'server'"
33 end
34 try
35 mail = json_parse(mail)
36 catch e
37 user_error "invalid JSON in 'mail'"
38 end
39 try
40 Mail.sender(server).send(mail)
41 catch e
42 logger.warn(e..stringify(server).."\n"..stringify(mail))
43 user_error(e.get_message())
44 end
45 %><%=json_string{okay=true}%><%
46 catch e
47 if e.error ~= nil then
48 %><%=json_string(e.error)%><%
49 return
50 end
51 e.throw()
52 end
53 end