mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-19 10:58:17 +00:00
f53ed1aeae
Ordinarily, the logic that calls the requeue_message event is responsible for increasing the number of attempts, computing the revised due time, and processing message expiration. When using XFER to move a message to another node, we capture the scheduling state at the point that the xfer was initiated. If we do this inside the requeue_message event callback then we will capture the scheduling information *prior* to the normal adjustments that would happen later. This commit adds kumo.xfer.xfer_in_requeue to handle this case; you pass through the scheduling information parameters that were added to the requeue_message event in the prior commit, and it will compute any revised scheduling for the message before wrapping the message up in the XFER encapsulation and moving the message to the xfer queue. This adjusted process ignores message expiration, so if the message is on its last retry it will be xfer'd to the target host which then might choose to perform the expiration. We can't handle the expiration in the context of `requeue_message` because the event handler doesn't own the message and has no way to signal that it has reached the end of its life. Folks doing xfer in requeue_message will generally be moving the message well in advance of it being expired, so this minor limitation is not expected to be a practical problem.
91 lines
2.4 KiB
Lua
91 lines
2.4 KiB
Lua
local kumo = require 'kumo'
|
|
package.path = '../../assets/?.lua;' .. package.path
|
|
|
|
local TEST_DIR = os.getenv 'KUMOD_TEST_DIR'
|
|
local BACKUP_HOST = 'http://127.0.0.1:' .. os.getenv 'KUMOD_HTTP_SINK_PORT'
|
|
local SINK_PORT = tonumber(os.getenv 'KUMOD_SMTP_SINK_PORT')
|
|
|
|
kumo.on('init', function()
|
|
kumo.configure_accounting_db_path(TEST_DIR .. '/accounting.db')
|
|
kumo.start_esmtp_listener {
|
|
listen = '127.0.0.1:0',
|
|
relay_hosts = { '0.0.0.0/0' },
|
|
}
|
|
|
|
kumo.start_http_listener {
|
|
listen = '127.0.0.1:0',
|
|
}
|
|
|
|
kumo.configure_local_logs {
|
|
log_dir = TEST_DIR .. '/logs',
|
|
max_segment_duration = '1s',
|
|
}
|
|
|
|
kumo.define_spool {
|
|
name = 'data',
|
|
path = TEST_DIR .. '/data-spool',
|
|
}
|
|
|
|
kumo.define_spool {
|
|
name = 'meta',
|
|
path = TEST_DIR .. '/meta-spool',
|
|
}
|
|
end)
|
|
|
|
kumo.on(
|
|
'requeue_message',
|
|
function(msg, smtp_response, insert_context, increment_attempts, delay)
|
|
print(
|
|
string.format(
|
|
'requeue_message called inc=%s ctx=%s delay=%s',
|
|
increment_attempts,
|
|
kumo.serde.json_encode(insert_context),
|
|
delay
|
|
)
|
|
)
|
|
kumo.xfer.xfer_in_requeue(
|
|
msg,
|
|
BACKUP_HOST,
|
|
insert_context,
|
|
increment_attempts,
|
|
delay,
|
|
'reroute to backup infra'
|
|
)
|
|
end
|
|
)
|
|
|
|
kumo.on('get_queue_config', function(domain, tenant, campaign, routing_domain)
|
|
local protocol = {
|
|
-- Redirect traffic to the sink
|
|
smtp = {
|
|
mx_list = { 'localhost:' .. SINK_PORT },
|
|
},
|
|
}
|
|
|
|
return kumo.make_queue_config {
|
|
protocol = protocol,
|
|
-- Use a short interval because the xfer will increment the attempts
|
|
-- and respect the delay from the transfail and we don't want to wait 20 minutes
|
|
-- in the test
|
|
max_retry_interval = '5s',
|
|
retry_interval = '5s',
|
|
}
|
|
end)
|
|
|
|
kumo.on('get_egress_path_config', function(domain, source_name, _site_name)
|
|
-- Allow sending to a sink
|
|
local params = {
|
|
enable_tls = 'OpportunisticInsecure',
|
|
prohibited_hosts = {},
|
|
-- Skip IPv6 addresses that come back for eg: localhost.
|
|
-- For the most part the integration tests don't care about this,
|
|
-- but the disconnect_XXX tests do make some assertions on the
|
|
-- ordering, and in particular, disconnect_terminate_ok will be
|
|
-- unhappy if the second address in its MX plan is unroutable IPv6.
|
|
skip_hosts = { '::/0' },
|
|
}
|
|
kumo.log_warn('get_egress_path_config *******************', domain)
|
|
|
|
return kumo.make_egress_path(params)
|
|
end)
|