]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to insert multiple headers from milter headers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 May 2018 16:48:59 +0000 (17:48 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 May 2018 16:48:59 +0000 (17:48 +0100)
src/plugins/lua/milter_headers.lua

index a1d34f92d317889f3ba7e33175510d8ab8a844af..d693e8f7f8d8603587a2de7c172177159d93efbd 100644 (file)
@@ -180,13 +180,39 @@ local function milter_headers(task)
 
   local function add_header(name, value, stop_chars, order)
     if order then
-      add[settings.routines[name].header] = {
-        order = order,
-        value = lua_util.fold_header(task, name, value, stop_chars)
-      }
+      if not add[settings.routines[name].header] then
+        add[settings.routines[name].header] = {
+          order = order,
+          value = lua_util.fold_header(task, name, value, stop_chars)
+        }
+      else
+        if not add[settings.routines[name].header][1] then
+          -- Convert to a table
+          add[settings.routines[name].header] = {
+            [1] = add[settings.routines[name].header]
+          }
+        end
+
+        table.insert(add[settings.routines[name].header], {
+          order = order,
+          value = lua_util.fold_header(task, name, value, stop_chars)
+        })
+      end
     else
-      add[settings.routines[name].header] = lua_util.fold_header(task, name,
-              value, stop_chars)
+      if not add[settings.routines[name].header] then
+        add[settings.routines[name].header] = lua_util.fold_header(task, name,
+            value, stop_chars)
+      else
+        if not add[settings.routines[name].header][1] then
+          -- Convert to a table
+          add[settings.routines[name].header] = {
+            [1] = add[settings.routines[name].header]
+          }
+        end
+
+        table.insert(add[settings.routines[name].header],
+            lua_util.fold_header(task, name, value, stop_chars))
+      end
     end
   end