Mercurial Hosting > mailer
view src/send.json.luan @ 4:fb6cda61cf9d default tip
mikraite links
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 24 Aug 2024 21:40:12 -0600 |
parents | bd4802730bab |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local new_error = Luan.new_error or error() local stringify = Luan.stringify or error() local Parsers = require "luan:Parsers.luan" local json_parse = Parsers.json_parse or error() local json_string = Parsers.json_string or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local Mail = require "luan:mail/Mail.luan" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "send.json" local function user_error(msg) local e = new_error(msg) e.error = { okay = false error = msg } e.throw() end return function() Io.stdout = Http.response.text_writer() try local server = Http.request.parameters.server or user_error "parameter 'server' missing" local mail = Http.request.parameters.mail or user_error "parameter 'mail' missing" try server = json_parse(server) catch e user_error "invalid JSON in 'server'" end try mail = json_parse(mail) catch e user_error "invalid JSON in 'mail'" end try Mail.sender(server).send(mail) catch e logger.warn(e..stringify(server).."\n"..stringify(mail)) user_error(e.get_message()) end %><%=json_string{okay=true}%><% catch e if e.error ~= nil then %><%=json_string(e.error)%><% return end e.throw() end end