]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add milter header support to rspamc --mime output
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 15 Oct 2025 13:17:07 +0000 (14:17 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 15 Oct 2025 13:17:07 +0000 (14:17 +0100)
- 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

src/client/rspamc.cxx

index 7d20ac759ab8c7e1ed7b50e45831681e5d12398c..1d6c93593bd7e3a4b2744b2f175096b16a173572 100644 (file)
@@ -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 */