]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Improve AR header folding
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Mar 2018 10:52:32 +0000 (11:52 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Mar 2018 10:52:32 +0000 (11:52 +0100)
Issue: #2111

src/plugins/lua/arc.lua
src/plugins/lua/milter_headers.lua

index acf590d4bc740558af8f16be81aa31106a5e9985..0feae321997a0cf1985e6bab18f8486803eed246 100644 (file)
@@ -345,17 +345,12 @@ rspamd_config:register_dependency('ARC_CALLBACK', symbols['spf_allow_symbol'])
 rspamd_config:register_dependency('ARC_CALLBACK', symbols['dkim_allow_symbol'])
 
 local function arc_sign_seal(task, params, header)
-  local fold_type = "crlf"
   local arc_sigs = task:cache_get('arc-sigs')
   local arc_seals = task:cache_get('arc-seals')
   local arc_auth_results = task:get_header_full('ARC-Authentication-Results') or {}
   local cur_auth_results = auth_results.gen_auth_results(task) or ''
   local privkey
 
-  if task:has_flag("milter") then
-    fold_type = "lf"
-  end
-
   if params.rawkey then
     privkey = rspamd_rsa_privkey.load_pem(params.rawkey)
   elseif params.key then
@@ -394,13 +389,13 @@ local function arc_sign_seal(task, params, header)
     end
   end
 
-  header = rspamd_util.fold_header(
+  header = lua_util.fold_header(task,
     'ARC-Message-Signature',
-    header, fold_type)
+    header)
 
-  cur_auth_results = rspamd_util.fold_header(
+  cur_auth_results = lua_util.fold_header(task,
     'ARC-Authentication-Results',
-    cur_auth_results, fold_type)
+    cur_auth_results, ';')
 
   cur_auth_results = string.format('i=%d; %s', cur_idx, cur_auth_results)
   local s = dkim_canonicalize('ARC-Authentication-Results',
@@ -425,9 +420,9 @@ local function arc_sign_seal(task, params, header)
     add_headers = {
       ['ARC-Authentication-Results'] = cur_auth_results,
       ['ARC-Message-Signature'] = header,
-      ['ARC-Seal'] = rspamd_util.fold_header(
+      ['ARC-Seal'] = lua_util.fold_header(task,
         'ARC-Seal',
-        cur_arc_seal, fold_type),
+        cur_arc_seal),
     }
   })
   task:insert_result(settings.sign_symbol, 1.0, string.format('i=%d', cur_idx))
index 8998fb83432e6b2a66fb77b0d7b7a9924c65870e..0eb92ff274ebaf616857d075682a6dbd45cc9341 100644 (file)
@@ -24,6 +24,7 @@ end
 local logger = require "rspamd_logger"
 local util = require "rspamd_util"
 local N = 'milter_headers'
+local lua_util = require "lua_util"
 local E = {}
 
 local HOSTNAME = util.get_hostname()
@@ -49,6 +50,7 @@ local settings = {
     ['x-spamd-result'] = {
       header = 'X-Spamd-Result',
       remove = 1,
+      stop_chars = ' '
     },
     ['x-rspamd-server'] = {
       header = 'X-Rspamd-Server',
@@ -116,6 +118,7 @@ local settings = {
         quarantine = 'DMARC_POLICY_QUARANTINE',
       },
       add_smtp_user = true,
+      stop_chars = ';',
     },
     ['stat-signature'] = {
       header = 'X-Stat-Signature',
@@ -151,6 +154,7 @@ local function milter_headers(task)
       return found
     end
 
+
     if settings.extended_headers_rcpt and match_extended_headers_rcpt() then
       return false
     end
@@ -170,6 +174,18 @@ local function milter_headers(task)
 
   local routines, common, add, remove = {}, {}, {}, {}
 
+  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)
+      }
+    else
+      add[settings.routines[name].header] = lua_util.fold_header(task, name,
+              value, stop_chars)
+    end
+  end
+
   routines['x-spamd-result'] = function()
     if skip_wanted('x-spamd-result') then return end
     if not common.symbols then
@@ -195,7 +211,7 @@ local function milter_headers(task)
         ' ', s.name, '(', string.format('%.2f', s.score), ')[', table.concat(s.options, ','), ']',
       }))
     end
-    add[settings.routines['x-spamd-result'].header] = table.concat(buf, '\n\t')
+    add_header('x-spamd-result', table.concat(buf, '; '), ';')
   end
 
   routines['x-rspamd-queue-id'] = function()
@@ -328,7 +344,7 @@ local function milter_headers(task)
       end
     end
     if #virii > 0 then
-      add[settings.routines['x-virus'].header] = table.concat(virii, ',')
+      add_header('x-virus', table.concat(virii, ','))
     end
   end
 
@@ -353,7 +369,7 @@ local function milter_headers(task)
     if settings.routines['x-spam-status'].remove then
       remove[settings.routines['x-spam-status'].header] = settings.routines['x-spam-status'].remove
     end
-    add[settings.routines['x-spam-status'].header] = spamstatus
+    add_header('x-spam-status', spamstatus)
   end
 
   routines['authentication-results'] = function()
@@ -369,10 +385,7 @@ local function milter_headers(task)
       settings.routines['authentication-results'])
 
     if res then
-      add[settings.routines['authentication-results'].header] = {
-        value = res,
-        order = 0
-      }
+      add_header('authentication-results', res, ';', 0)
     end
   end