From f72f4dc2cdd890b8e58fc72999824a1ae3a48481 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sat, 11 Nov 2023 11:37:19 -0800 Subject: [PATCH] updated example to drop mail --- Lua-Examples.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Lua-Examples.md b/Lua-Examples.md index bae9889..80460fb 100644 --- a/Lua-Examples.md +++ b/Lua-Examples.md @@ -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