mirror of
https://github.com/mailscope/kumomta.git
synced 2026-09-12 05:22:13 +00:00
Let's give the templates more human readable names so that the error messaging naturally has more context.
46 lines
1.3 KiB
Lua
46 lines
1.3 KiB
Lua
local kumo = require 'kumo'
|
|
local utils = require 'policy-extras.policy_utils'
|
|
|
|
local ok, msg_or_err = pcall(kumo.api.inject.build_v1, {
|
|
envelope_sender = 'no-reply@example.com',
|
|
recipients = {
|
|
{ email = 'user@example.com', name = 'John Smith' },
|
|
},
|
|
content = {
|
|
text_body = 'Hello {{ First Name }},\nThis is the second line',
|
|
},
|
|
})
|
|
|
|
assert(not ok)
|
|
msg_or_err = tostring(msg_or_err)
|
|
assert(
|
|
utils.starts_with(
|
|
msg_or_err,
|
|
"failed parsing field 'content.text_body' as template: syntax error: unexpected identifier, expected end of variable block (in template 'text_body.txt' line 1: 'Hello {{ First Name }},')\n"
|
|
),
|
|
msg_or_err
|
|
)
|
|
|
|
local ok, msg_or_err = pcall(kumo.api.inject.build_v1, {
|
|
envelope_sender = 'no-reply@example.com',
|
|
recipients = {
|
|
{ email = 'user@example.com', name = 'John Smith' },
|
|
},
|
|
content = {
|
|
text_body = 'Hello {{ Name }},\nThis is the second line',
|
|
headers = {
|
|
['X-Woot'] = '{{ First Name }}',
|
|
},
|
|
},
|
|
})
|
|
|
|
assert(not ok)
|
|
msg_or_err = tostring(msg_or_err)
|
|
assert(
|
|
utils.starts_with(
|
|
msg_or_err,
|
|
"failed parsing field headers['X-Woot'] as template: syntax error: unexpected identifier, expected end of variable block (in template 'headers[X-Woot]' line 1: '{{ First Name }}')\n"
|
|
),
|
|
msg_or_err
|
|
)
|