mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-19 02:27:03 +00:00
Updated Lua Examples (markdown)
@@ -2,7 +2,7 @@ By default Inbucket will load `inbucket.lua`, but you may use the `INBUCKET_LUA_
|
|||||||
|
|
||||||
## Event trigger: after message stored
|
## Event trigger: after message stored
|
||||||
|
|
||||||
Prints metadata of stored messages to STDOUT.
|
Prints metadata of stored messages to STDOUT:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
function inbucket.after.message_stored(msg)
|
function inbucket.after.message_stored(msg)
|
||||||
@@ -22,7 +22,7 @@ function inbucket.after.message_stored(msg)
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Makes a JSON encoded POST to a web service.
|
Makes a JSON encoded POST to a web service:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local http = require("http")
|
local http = require("http")
|
||||||
@@ -41,4 +41,26 @@ function inbucket.after.message_stored(msg)
|
|||||||
body = request,
|
body = request,
|
||||||
}))
|
}))
|
||||||
end
|
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
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user