diff options
-rw-r--r-- | conf/modules.d/elastic.conf | 26 | ||||
-rw-r--r-- | lualib/plugins/dmarc.lua | 20 | ||||
-rw-r--r-- | src/plugins/lua/milter_headers.lua | 9 |
3 files changed, 29 insertions, 26 deletions
diff --git a/conf/modules.d/elastic.conf b/conf/modules.d/elastic.conf index f815bc61d..804a00dd7 100644 --- a/conf/modules.d/elastic.conf +++ b/conf/modules.d/elastic.conf @@ -10,7 +10,7 @@ # See https://rspamd.com/doc/faq.html#what-are-the-locald-and-overrided-directories # for details # -# Module documentation can be found at https://rspamd.com/doc/modules/elastic.html +# Module documentation can be found at https://rspamd.com/doc/modules/elastic.html elastic { enabled = false; @@ -26,15 +26,15 @@ elastic { version = { autodetect_enabled = true; autodetect_max_fail = 30; - # override works only if autodetect is disabled + # Override works only if autodetect is disabled override = { name = "opensearch"; version = "2.17"; } }; limits = { - max_rows = 500; # max logs in one bulk req to elastic and first reason to flush buffer to elastic - max_interval = 60; # seconds, if first log in buffer older then interval - flush buffer + max_rows = 500; # Max logs in one bulk request to Elastic and the first reason to flush buffer to Elastic + max_interval = 60; # Seconds; if the first log in the buffer is older than this interval, flush the buffer max_fail = 10; }; index_template = { @@ -44,17 +44,17 @@ elastic { pattern = "%Y.%m.%d"; shards_count = 3; replicas_count = 1; - refresh_interval = 5; # seconds + refresh_interval = 5; # Seconds dynamic_keyword_ignore_above = 256; - headers_count_ignore_above = 5; # record only N first same named headers, add "ignored above..." if reached, set 0 to disable limit - headers_text_ignore_above = 2048; # strip specific header value and add "..." to the end; set 0 to disable limit + headers_count_ignore_above = 5; # Record only the first N same-named headers, add "ignored above..." if the limit is reached; set 0 to disable the limit + headers_text_ignore_above = 2048; # Strip specific header value and add "..." to the end; set 0 to disable the limit symbols_nested = false; - empty_value = "unknown"; # empty numbers, ips and ipnets are not customizable they will be always 0, :: and ::/128 respectively + empty_value = "unknown"; # Empty numbers, IPs and IP nets are not customizable; they will always be 0, :: and ::/128 respectively }; index_policy = { enabled = true; managed = true; - name = "rspamd"; # if you want use custom lifecycle policy, change name and set managed = false + name = "rspamd"; # To use a custom lifecycle policy, change the name and set managed = false hot = { index_priority = 100; }; @@ -62,13 +62,13 @@ elastic { enabled = true; after = "2d"; index_priority = 50; - migrate = true; # only supported with elastic distro, will not have impact elsewhere + migrate = true; # Supported only with Elastic distro; has no impact elsewhere read_only = true; change_replicas = false; replicas_count = 1; shrink = false; shards_count = 1; - max_gb_per_shard = 0; # zero - disabled by default, if enabled - shards_count is ignored + max_gb_per_shard = 0; # Zero - disabled by default, if enabled - shards_count is ignored force_merge = false; segments_count = 1; }; @@ -76,7 +76,7 @@ elastic { enabled = true; after = "14d"; index_priority = 0; - migrate = true; # only supported with elastic distro, will not have impact elsewhere + migrate = true; # Supported only with Elastic distro; has no impact elsewhere read_only = true; change_replicas = false; replicas_count = 1; @@ -93,7 +93,7 @@ elastic { "Date"; "User-Agent"; ]; - # extra headers to collect, f.e.: + # Extra headers to collect, e.g.: # "Precedence"; # "List-Id"; extra_collect_headers = []; diff --git a/lualib/plugins/dmarc.lua b/lualib/plugins/dmarc.lua index 720c76e16..f69016b74 100644 --- a/lualib/plugins/dmarc.lua +++ b/lualib/plugins/dmarc.lua @@ -194,14 +194,17 @@ exports.gen_munging_callback = function(munging_opts, settings) via_name = string.format('%s via %s', from.name, via_user) end - local hdr_encoded = rspamd_util.fold_header('From', - rspamd_util.mime_header_encode(string.format('%s <%s>', - via_name, via_addr)), task:get_newlines_type()) - local orig_from_encoded = rspamd_util.fold_header('X-Original-From', - rspamd_util.mime_header_encode(string.format('%s <%s>', - from.name or '', from.addr)), task:get_newlines_type()) + local encoded_via_name = rspamd_util.mime_header_encode(via_name) + local via_from_folded = rspamd_util.fold_header('From', + string.format('%s <%s>', encoded_via_name, via_addr), + task:get_newlines_type()) + local encoded_orig_name = rspamd_util.mime_header_encode(from.name or '') + local orig_from_folded = rspamd_util.fold_header('X-Original-From', + string.format('%s <%s>', encoded_orig_name, from.addr), + task:get_newlines_type()) local add_hdrs = { - ['From'] = { order = 1, value = hdr_encoded }, + ['From'] = { order = 1, value = via_from_folded }, + ['X-Original-From'] = { order = 0, value = orig_from_folded }, } local remove_hdrs = { ['From'] = 0 } @@ -223,13 +226,12 @@ exports.gen_munging_callback = function(munging_opts, settings) add_hdrs['Reply-To'] = { order = 0, value = nreply } - add_hdrs['X-Original-From'] = { order = 0, value = orig_from_encoded } lua_mime.modify_headers(task, { remove = remove_hdrs, add = add_hdrs }) lua_util.debugm(N, task, 'munged DMARC header for %s: %s -> %s', - from.domain, hdr_encoded, from.addr) + from.domain, via_from_folded, from.addr) rspamd_logger.infox(task, 'munged DMARC header for %s', from.addr) task:insert_result('DMARC_MUNGED', 1.0, from.addr) end diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua index 58a227fec..2daeeed78 100644 --- a/src/plugins/lua/milter_headers.lua +++ b/src/plugins/lua/milter_headers.lua @@ -213,16 +213,17 @@ local function milter_headers(task) if not add[hname] then add[hname] = {} end + local folded = lua_util.fold_header(task, hname, value, stop_chars) if rspamd_config:is_mime_utf8() then - if not rspamd_util.is_valid_utf8(value) then - value = rspamd_util.mime_header_encode(value) + if not rspamd_util.is_valid_utf8(folded) then + folded = rspamd_util.mime_header_encode(folded) end else - value = rspamd_util.mime_header_encode(value) + folded = rspamd_util.mime_header_encode(folded) end table.insert(add[hname], { order = (order or settings.default_headers_order or -1), - value = lua_util.fold_header(task, hname, value, stop_chars) + value = folded }) end |