From 08a71f0108cbd92c750924f91d3522364b30e66a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 23 Nov 2020 20:07:57 +0000 Subject: [PATCH] [Fix] Spamassassin: Preserve 'pcre_only' flag when dealing with regexp replacements --- src/lua/lua_config.c | 16 +++++++++++++--- src/plugins/lua/spamassassin.lua | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index f3dc414db3..8366545003 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3072,20 +3072,30 @@ lua_config_replace_regexp (lua_State *L) LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config (L, 1); struct rspamd_lua_regexp *old_re = NULL, *new_re = NULL; + gboolean pcre_only = FALSE; GError *err = NULL; if (cfg != NULL) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, - "*old_re=U{regexp};*new_re=U{regexp}", - &old_re, &new_re)) { - msg_err_config ("cannot get parameters list: %e", err); + "*old_re=U{regexp};*new_re=U{regexp};pcre_only=B", + &old_re, &new_re, &pcre_only)) { + gint ret = luaL_error (L, "cannot get parameters list: %s", + err ? err->message : "invalid arguments"); if (err) { g_error_free (err); } + + return ret; } else { + + if (pcre_only) { + rspamd_regexp_set_flags (new_re->re, + rspamd_regexp_get_flags (new_re->re) | RSPAMD_REGEXP_FLAG_PCRE_ONLY); + } + rspamd_re_cache_replace (cfg->re_cache, old_re->re, new_re->re); } } diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index 691930bb12..2b0e5e44ec 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -1240,7 +1240,8 @@ local function post_process() lua_util.debugm(N, rspamd_config, 'replace %1 -> %2', r, nexpr) rspamd_config:replace_regexp({ old_re = rule['re'], - new_re = nre + new_re = nre, + pcre_only = is_pcre_only(rule['symbol']), }) rule['re'] = nre rule['re_expr'] = nexpr -- 2.47.3