From: Vsevolod Stakhov Date: Wed, 15 Oct 2025 13:17:07 +0000 (+0100) Subject: [Feature] Add milter header support to rspamc --mime output X-Git-Tag: 3.14.0~74^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c0ea1c71d66f5971932943f4769813a54afb758;p=thirdparty%2Frspamd.git [Feature] Add milter header support to rspamc --mime output - Process milter.add_headers from JSON response in --mime mode - Supports both single string and array values for headers - Enables ARC headers (and other milter-added headers) to appear in modified message output - Removes outdated TODO comment about milter header support --- diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx index 7d20ac759a..1d6c93593b 100644 --- a/src/client/rspamc.cxx +++ b/src/client/rspamc.cxx @@ -1851,9 +1851,6 @@ rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, fmt::format_to(std::back_inserter(added_headers), "X-Spam-Scan-Time: {:.3}{}", time, line_end); - /* - * TODO: add milter_headers support here - */ if (is_spam) { fmt::format_to(std::back_inserter(added_headers), "X-Spam: yes{}", line_end); } @@ -1911,6 +1908,30 @@ rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, } } + /* Process milter.add_headers */ + const auto *milter = ucl_object_lookup(result, "milter"); + if (milter) { + const auto *add_headers = ucl_object_lookup(milter, "add_headers"); + if (add_headers && ucl_object_type(add_headers) == UCL_OBJECT) { + it = nullptr; + while ((cur = ucl_object_iterate(add_headers, &it, true)) != nullptr) { + const char *header_name = ucl_object_key(cur); + if (ucl_object_type(cur) == UCL_STRING) { + fmt::format_to(std::back_inserter(added_headers), "{}: {}{}", + header_name, ucl_object_tostring(cur), line_end); + } + else if (ucl_object_type(cur) == UCL_ARRAY) { + ucl_object_iter_t header_it = nullptr; + const ucl_object_t *header_value; + while ((header_value = ucl_object_iterate(cur, &header_it, true)) != nullptr) { + fmt::format_to(std::back_inserter(added_headers), "{}: {}{}", + header_name, ucl_object_tostring(header_value), line_end); + } + } + } + } + } + if (json || ucl_reply || compact) { unsigned char *json_header; /* We also append json data as a specific header */