From d8c5060dc65e3baf7b3b94dece4251a457449aa8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 11 Apr 2016 15:05:18 +0100 Subject: [PATCH] [Fix] Properly handle MIME headers in SA plugin --- src/lua/lua_config.c | 6 +++-- src/plugins/lua/spamassassin.lua | 42 +++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 6f994da53..7d6392818 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1617,8 +1617,10 @@ lua_config_register_regexp (lua_State *L) else { type = rspamd_re_cache_type_from_string (type_str); - if ((type == RSPAMD_RE_HEADER || type == RSPAMD_RE_RAWHEADER) - && header_str == NULL) { + if ((type == RSPAMD_RE_HEADER || + type == RSPAMD_RE_RAWHEADER || + type == RSPAMD_RE_MIMEHEADER) && + header_str == NULL) { msg_err_config ( "header argument is mandatory for header/rawheader regexps"); } diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index 8ab37cf7e..a73b56d06 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -724,8 +724,9 @@ local function process_sa_conf(f) end if words[1] == 'mimeheader' then - cur_rule['ordinary'] = false cur_rule['mime'] = true + else + cur_rule['mime'] = false end if cur_rule['re'] and cur_rule['symbol'] and @@ -735,27 +736,46 @@ local function process_sa_conf(f) if cur_rule['header'] and cur_rule['ordinary'] then for i,h in ipairs(cur_rule['header']) do if type(h) == 'string' then - rspamd_config:register_regexp({ - re = cur_rule['re'], - type = 'header', - header = h, - pcre_only = is_pcre_only(cur_rule['symbol']), - }) - else - if h['raw'] then + if cur_rule['mime'] then rspamd_config:register_regexp({ re = cur_rule['re'], - type = 'rawheader', - header = h['header'], + type = 'mimeheader', + header = h, pcre_only = is_pcre_only(cur_rule['symbol']), }) else rspamd_config:register_regexp({ re = cur_rule['re'], type = 'header', + header = h, + pcre_only = is_pcre_only(cur_rule['symbol']), + }) + end + else + h['mime'] = cur_rule[mime] + if cur_rule['mime'] then + rspamd_config:register_regexp({ + re = cur_rule['re'], + type = 'mimeheader', header = h['header'], pcre_only = is_pcre_only(cur_rule['symbol']), }) + else + if h['raw'] then + rspamd_config:register_regexp({ + re = cur_rule['re'], + type = 'rawheader', + header = h['header'], + pcre_only = is_pcre_only(cur_rule['symbol']), + }) + else + rspamd_config:register_regexp({ + re = cur_rule['re'], + type = 'header', + header = h['header'], + pcre_only = is_pcre_only(cur_rule['symbol']), + }) + end end end end -- 2.39.5