Skip to content

Commit

Permalink
mt2exm: add --repeat option
Browse files Browse the repository at this point in the history
  • Loading branch information
jengelh committed Oct 22, 2023
1 parent e8e33d6 commit 9b350a0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tools/mt2exm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static gi_folder_map_t g_folder_map;
static gi_name_map g_src_name_map;
static propididmap_t g_thru_name_map;
static uint8_t g_splice;
static unsigned int g_oexcl = 1, g_anchor_folder;
static unsigned int g_oexcl = 1, g_anchor_folder, g_repeat_iter = 1;
static unsigned int g_do_delivery, g_skip_notif, g_skip_rules, g_twostep;

static void cb_anchor_folder(const HXoptcb *cb)
Expand Down Expand Up @@ -74,6 +74,7 @@ static constexpr HXoption g_options_table[] = {
{nullptr, 't', HXTYPE_NONE, &g_show_tree, nullptr, nullptr, 0, "Show tree-based analysis of the archive"},
{nullptr, 'u', HXTYPE_STRING, &g_username, nullptr, nullptr, 0, "Username of store to import to", "EMAILADDR"},
{nullptr, 'x', HXTYPE_VAL, &g_oexcl, nullptr, nullptr, 0, "Disable O_EXCL like behavior for non-spliced folders"},
{"repeat", 0, HXTYPE_UINT, &g_repeat_iter, {}, {}, 0, "For testing purposes, import each message N times", "N"},
{"skip-notif", 0, HXTYPE_NONE, &g_skip_notif, nullptr, nullptr, 0, "Skip emission of notifications (if -D)"},
{"skip-rules", 0, HXTYPE_NONE, &g_skip_rules, nullptr, nullptr, 0, "Skip execution of rules (if -D)"},
{"twostep", '2', HXTYPE_NONE, &g_twostep, nullptr, nullptr, 0, "TWOSTEP rule executor (implies -D; development)"},
Expand Down Expand Up @@ -347,16 +348,31 @@ static int exm_message(const ob_desc &obd, MESSAGE_CONTENT &ctnt)
tlog("adjusted properties:\n");
gi_dump_msgctnt(0, ctnt);
}
if (!g_do_delivery)
return exm_create_msg(folder_it->second.fid_to, &ctnt);
if (!g_do_delivery) {
for (auto i = 0U; i < g_repeat_iter; ++i) {
if (i > 0 && i % 1024 == 0)
fprintf(stderr, "mt2exm repeat %u/%u\n", i, g_repeat_iter);
auto ret = exm_create_msg(folder_it->second.fid_to, &ctnt);
if (ret != EXIT_SUCCESS)
return ret;
}
return EXIT_SUCCESS;
}
unsigned int mode = 0;
if (!g_skip_rules)
mode |= DELIVERY_DO_RULES;
if (!g_skip_notif)
mode |= DELIVERY_DO_NOTIF;
if (g_twostep)
mode |= DELIVERY_TWOSTEP;
return exm_deliver_msg(g_username, &ctnt, mode);
for (auto i = 0U; i < g_repeat_iter; ++i) {
if (i > 0 && i % 1024 == 0)
fprintf(stderr, "mt2exm repeat %u/%u\n", i, g_repeat_iter);
auto ret = exm_deliver_msg(g_username, &ctnt, mode);
if (ret != EXIT_SUCCESS)
return ret;
}
return EXIT_SUCCESS;
}

static int exm_packet(const void *buf, size_t bufsize)
Expand Down

0 comments on commit 9b350a0

Please sign in to comment.