]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Dkim_signing: Allow to sign via milter_headers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Jan 2020 18:57:40 +0000 (18:57 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Jan 2020 18:57:40 +0000 (18:57 +0000)
src/plugins/lua/dkim_signing.lua

index 283aa50513e8406ab17a5bb1a3be0930bac66a70..24dbd20d60502aa68dc43d82480ce4ab0cb69c7e 100644 (file)
@@ -44,13 +44,30 @@ local settings = {
   use_esld = true,
   use_redis = false,
   key_prefix = 'dkim_keys', -- default hash name
+  use_milter_headers = false, -- use milter headers instead of `dkim_signature`
 }
 
 local N = 'dkim_signing'
 local redis_params
 local sign_func = rspamd_plugins.dkim.sign
 
+local function insert_sign_results(task, ret, hdr)
+  if settings.use_milter_headers then
+    task:set_milter_reply({
+      add_headers = {
+        ['DKIM-Signature'] = {order = 1, value = hdr},
+      }
+    })
+  end
+  if ret then
+    task:insert_result(settings.symbol, 1.0)
+  end
+end
+
 local function do_sign(task, p)
+  if settings.use_milter_headers then
+    p.no_cache = true -- Disable caching in rspamd_mempool
+  end
   if settings.check_pubkey then
     local resolve_name = p.selector .. "._domainkey." .. p.domain
     task:get_resolver():resolve_txt({
@@ -69,18 +86,14 @@ local function do_sign(task, p)
               p.domain, p.selector, err)
         end
 
-        local sret, _ = sign_func(task, p)
-        if sret then
-          task:insert_result(settings.symbol, 1.0)
-        end
+        local sret, hdr = sign_func(task, p)
+        insert_sign_results(task, sret, hdr)
       end,
       forced = true
     })
   else
-    local sret, _ = sign_func(task, p)
-    if sret then
-      task:insert_result(settings.symbol, 1.0)
-    end
+    local sret, hdr = sign_func(task, p)
+    insert_sign_results(task, sret, hdr)
   end
 end