]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Spamassassin: Preserve 'pcre_only' flag when dealing with regexp replacements
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Nov 2020 20:07:57 +0000 (20:07 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Nov 2020 20:07:57 +0000 (20:07 +0000)
src/lua/lua_config.c
src/plugins/lua/spamassassin.lua

index f3dc414db3522d0c1a006a686cd01e0cd89bf571..83665450030bfded5f3836b67a53293eddd7eb68 100644 (file)
@@ -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);
                }
        }
index 691930bb125110d1b9e658ce2098190c38843e00..2b0e5e44ec337154391eeb777572f979a29eaf13 100644 (file)
@@ -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