]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Milter headers: X-Spamd-Result header if X-Virus ran first
authorAndrew Lewis <nerf@judo.za.org>
Thu, 28 Sep 2017 14:36:01 +0000 (16:36 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 17 Oct 2017 22:26:15 +0000 (00:26 +0200)
 - Fixes: #1851
 - Reported by: @iflyhigh
 - MFH: rspamd-1.6

src/plugins/lua/milter_headers.lua

index d193e29aaa6819b1217981fad8b1512484f46a5c..a60eeb7edef82b6e7c2ad70aca23fd64050127b4 100644 (file)
@@ -165,7 +165,11 @@ local function milter_headers(task)
     if skip_wanted('x-spamd-result') then return end
     if not common.symbols then
       common.symbols = task:get_symbols_all()
+    end
+    if not common['metric_score'] then
       common['metric_score'] = task:get_metric_score('default')
+    end
+    if not common['metric_action'] then
       common['metric_action'] = task:get_metric_action('default')
     end
     if settings.routines['x-spamd-result'].remove then
@@ -288,26 +292,26 @@ local function milter_headers(task)
 
   routines['x-virus'] = function()
     if skip_wanted('x-virus') then return end
-    if not common.symbols then
-      common.symbols = {}
+    if not common.symbols_hash then
+      if not common.symbols then
+        common.symbols = task:get_symbols_all()
+      end
+      local h = {}
+      for _, s in ipairs(common.symbols) do
+        h[s.name] = s
+      end
+      common.symbols_hash = h
     end
     if settings.routines['x-virus'].remove then
       remove[settings.routines['x-virus'].header] = settings.routines['x-virus'].remove
     end
     local virii = {}
     for _, sym in ipairs(settings.routines['x-virus'].symbols) do
-      if not (common.symbols[sym] == false) then
-        local s = task:get_symbol(sym)
-        if not s then
-          common.symbols[sym] = false
-        else
-          common.symbols[sym] = s
-          if (((s or E)[1] or E).options or E)[1] then
-            table.insert(virii, s[1].options[1])
-          else
-            table.insert(virii, 'unknown')
-          end
-        end
+      local s = common.symbols_hash[sym]
+      if ((s or E).options or E)[1] then
+        table.insert(virii, table.concat(s.options, ','))
+      elseif s then
+        table.insert(virii, 'unknown')
       end
     end
     if #virii > 0 then