]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Append header to the ordered list of headers if it does not exist
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 25 Nov 2023 12:42:59 +0000 (12:42 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 25 Nov 2023 12:42:59 +0000 (12:42 +0000)
src/libmime/mime_headers.c
src/libmime/mime_headers.h
src/lua/lua_task.c

index e0cf42e0a781bd3f5eafc61e905f25078274a4c7..2b6b2acc02e4b36dff92a2a15949fcce184f8dff 100644 (file)
@@ -1028,7 +1028,8 @@ rspamd_message_headers_new(void)
 void rspamd_message_set_modified_header(struct rspamd_task *task,
                                                                                struct rspamd_mime_headers_table *hdrs,
                                                                                const gchar *hdr_name,
-                                                                               const ucl_object_t *obj)
+                                                                               const ucl_object_t *obj,
+                                                                               struct rspamd_mime_header **order_ptr)
 {
        khiter_t k;
        khash_t(rspamd_mime_headers_htb) *htb = &hdrs->htb;
@@ -1048,6 +1049,10 @@ void rspamd_message_set_modified_header(struct rspamd_task *task,
                        k = kh_put(rspamd_mime_headers_htb, htb, hdr_elt->name, &r);
 
                        kh_value(htb, k) = hdr_elt;
+
+                       if (order_ptr) {
+                               DL_APPEND(*order_ptr, hdr_elt);
+                       }
                }
                else {
                        hdr_elt = kh_value(htb, k);
index 7e3cf8420037e46557612682b3d2ad253cf5d6a3..ffa863e8bb2ad87ab12b4e02b9e312b489628805 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -143,7 +143,8 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs,
 void rspamd_message_set_modified_header(struct rspamd_task *task,
                                                                                struct rspamd_mime_headers_table *hdrs,
                                                                                const gchar *hdr_name,
-                                                                               const ucl_object_t *obj);
+                                                                               const ucl_object_t *obj,
+                                                                               struct rspamd_mime_header **order_ptr);
 
 /**
  * Cleans up hash table of the headers
index fe6e498c9ee942ab0eb1930d3c1c604cc1906b96..7278602081363b5e4b512637a76d20668e9269f8 100644 (file)
@@ -6750,7 +6750,10 @@ lua_task_modify_header(lua_State *L)
                        ucl_object_t *mods = ucl_object_lua_import(L, 3);
 
                        rspamd_message_set_modified_header(task,
-                                                                                          MESSAGE_FIELD_CHECK(task, raw_headers), hname, mods);
+                                                                                          MESSAGE_FIELD(task, raw_headers),
+                                                                                          hname,
+                                                                                          mods,
+                                                                                          &(MESSAGE_FIELD(task, headers_order)));
                        ucl_object_unref(mods);
 
                        lua_pushboolean(L, true);