mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
updated example to drop mail
@@ -39,15 +39,17 @@ end
|
|||||||
|
|
||||||
This event fires after Inbucket has accepted a message, but before it has been stored.
|
This event fires after Inbucket has accepted a message, but before it has been stored.
|
||||||
|
|
||||||
Changes the destination mailbox to `test` for two specific recipients.
|
Changes the destination mailbox to `test` from `swaks`, and does not store mail for
|
||||||
|
`alternate`.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local logger = require("logger")
|
local logger = require("logger")
|
||||||
|
|
||||||
-- Original mailbox name on left, new on right.
|
-- Original mailbox name on left, new on right.
|
||||||
|
-- `false` causes mail for that box to be discarded.
|
||||||
local mailbox_mapping = {
|
local mailbox_mapping = {
|
||||||
["swaks"] = "test",
|
["swaks"] = "test",
|
||||||
["james-test"] = "test",
|
["alternate"] = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
function inbucket.before.message_stored(msg)
|
function inbucket.before.message_stored(msg)
|
||||||
@@ -60,17 +62,22 @@ function inbucket.before.message_stored(msg)
|
|||||||
local new_box = mailbox_mapping[orig_box]
|
local new_box = mailbox_mapping[orig_box]
|
||||||
if new_box then
|
if new_box then
|
||||||
logger.info(string.format("Mapping mailbox %q to %q", orig_box, new_box), {})
|
logger.info(string.format("Mapping mailbox %q to %q", orig_box, new_box), {})
|
||||||
new_mailboxes[index] = new_box
|
new_mailboxes[#new_mailboxes+1] = new_box
|
||||||
|
made_changes = true
|
||||||
|
elseif new_box == false then
|
||||||
|
logger.info(string.format("Discarding mail for %q", orig_box), {})
|
||||||
made_changes = true
|
made_changes = true
|
||||||
else
|
else
|
||||||
-- No match, continue using the original value for this mailbox.
|
-- No match, continue using the original value for this mailbox.
|
||||||
new_mailboxes[index] = orig_box
|
new_mailboxes[#new_mailboxes+1] = orig_box
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if made_changes then
|
if made_changes then
|
||||||
-- Recipient mailbox list was changed, return updated msg.
|
-- Recipient mailbox list was changed, return updated msg.
|
||||||
logger.info(string.format("New mailboxes: %s", table.concat(new_mailboxes, ", ")), {})
|
logger.info(
|
||||||
|
string.format("New mailboxes: %s", table.concat(new_mailboxes, ", ")),
|
||||||
|
{count = #new_mailboxes})
|
||||||
msg.mailboxes = new_mailboxes
|
msg.mailboxes = new_mailboxes
|
||||||
return msg
|
return msg
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user