Files
kumomta/crates/message/test_recipient_list.lua
Wez Furlong db5ebb88a7 message: expose recipient list to lua api
message:recipient() may now return an array style table
holding the recipient list, if there is more than a single
recipient on the message.

Since this can be somewhat ambiguous/frustrating to work with,
there is now also a message:recipient_list() that will always
return an array style table, even if it holds just a single
element.

The included helpers have been updated to use `message:recipient_list`.

message:set_recipient() will now optionally accept an array
style table holding the recipient list to be set.
2025-10-07 07:52:58 +01:00

16 lines
493 B
Lua

local kumo = require 'kumo'
local utils = require 'policy-extras.policy_utils'
local msg =
kumo.make_message('sender@example.com', 'recip@example.com', 'woot')
utils.assert_eq(tostring(msg:recipient()), 'recip@example.com')
msg:set_recipient { 'a@example.com' }
utils.assert_eq(tostring(msg:recipient()), 'a@example.com')
msg:set_recipient { 'a@example.com', 'b@example.com' }
utils.assert_eq(
utils.dumps(msg:recipient()),
'{\n [1] = "a@example.com",\n [2] = "b@example.com"\n}'
)