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

updated example to drop mail

James Hillyerd
2023-11-11 11:37:19 -08:00
parent 24389a8668
commit f72f4dc2cd

@@ -39,15 +39,17 @@ end
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
local logger = require("logger")
-- Original mailbox name on left, new on right.
-- `false` causes mail for that box to be discarded.
local mailbox_mapping = {
["swaks"] = "test",
["james-test"] = "test",
["alternate"] = false,
}
function inbucket.before.message_stored(msg)
@@ -60,17 +62,22 @@ function inbucket.before.message_stored(msg)
local new_box = mailbox_mapping[orig_box]
if new_box then
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
else
-- No match, continue using the original value for this mailbox.
new_mailboxes[index] = orig_box
new_mailboxes[#new_mailboxes+1] = orig_box
end
end
if made_changes then
-- 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
return msg
end