1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

Updated Lua Examples (markdown)

James Hillyerd
2023-02-28 13:29:14 -08:00
parent cf739cd919
commit 71c598c2cc

@@ -2,7 +2,7 @@ By default Inbucket will load `inbucket.lua`, but you may use the `INBUCKET_LUA_
## Event trigger: after message stored
Prints metadata of stored messages to STDOUT.
Prints metadata of stored messages to STDOUT:
```lua
function inbucket.after.message_stored(msg)
@@ -22,7 +22,7 @@ function inbucket.after.message_stored(msg)
end
```
Makes a JSON encoded POST to a web service.
Makes a JSON encoded POST to a web service:
```lua
local http = require("http")
@@ -41,4 +41,26 @@ function inbucket.after.message_stored(msg)
body = request,
}))
end
```
Writes data to temporary file and runs external shell command:
```lua
function inbucket.after.message_stored(msg)
local content = string.format("%q,%q", msg.from, msg.subject)
-- Write POST data to temporary file.
local fnam = os.tmpname()
local f = assert(io.open(fnam, "w+"))
assert(f:write(content))
f:close()
local cmd = string.format("cat %q", fnam)
print(string.format("\n### running %s ###", cmd))
local status = os.execute(cmd)
if status ~= 0 then
error("command failed: " .. cmd)
end
print("\n")
end
```