From: Vsevolod Stakhov Date: Mon, 24 Apr 2017 16:06:55 +0000 (+0100) Subject: [Fix] Fix R_BAD_CTE_7BIT rule X-Git-Tag: 1.5.7~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6e39e0135096b319548572c42dca50992e1cda83;p=rspamd.git [Fix] Fix R_BAD_CTE_7BIT rule Issue: #1590 --- diff --git a/rules/misc.lua b/rules/misc.lua index 422edfcc3..20505828b 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -590,3 +590,23 @@ rspamd_config.INFO_TO_INFO_LU = { description = 'info@ From/To address with List-Unsubscribe headers', score = 2.0 } + +-- Detects bad content-transfer-encoding for text parts + +rspamd_config.R_BAD_CTE_7BIT = { + callback = function(task) + local tp = task:get_text_parts() or {} + + for _,p in ipairs(tp) do + local cte = p:get_mimepart():get_cte() or '' + if cte ~= '8bit' and p:has_8bit_raw() then + return true,1.0,cte + end + end + + return false + end, + score = 4.0, + description = 'Detects bad content-transfer-encoding for text parts', + group = 'header' +} \ No newline at end of file diff --git a/rules/regexp/headers.lua b/rules/regexp/headers.lua index 0258ab42e..12a2b6249 100644 --- a/rules/regexp/headers.lua +++ b/rules/regexp/headers.lua @@ -57,20 +57,6 @@ rspamd_config.MISSING_SUBJECT = { end } --- Detects bad content-transfer-encoding for text parts --- For text parts (text/plain and text/html mainly) -local r_ctype_text = 'content_type_is_type(text)' --- Content transfer encoding is 7bit -local r_cte_7bit = 'compare_transfer_encoding(7bit)' --- And body contains 8bit characters -local r_body_8bit = '/[^\\x01-\\x7f]/Qr' -reconf['R_BAD_CTE_7BIT'] = { - re = string.format('(%s) & (%s) & (%s)', r_ctype_text, r_cte_7bit, r_body_8bit), - score = 2.0, - description = 'Detects bad content-transfer-encoding for text parts', - group = 'header' -} - -- Detects missing To header reconf['MISSING_TO'] = { re = '!raw_header_exists(To)', diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index ae79880b2..d83125044 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -47,18 +47,18 @@ end LUA_FUNCTION_DEF (textpart, is_utf); /*** - * @method text_part:is_8bit_raw() + * @method text_part:has_8bit_raw() * Return TRUE if a part has raw 8bit characters * @return {boolean} true if a part has raw 8bit characters */ -LUA_FUNCTION_DEF (textpart, is_8bit_raw); +LUA_FUNCTION_DEF (textpart, has_8bit_raw); /*** - * @method text_part:is_8bit() + * @method text_part:has_8bit() * Return TRUE if a part has raw 8bit characters * @return {boolean} true if a part has encoded 8bit characters */ -LUA_FUNCTION_DEF (textpart, is_8bit); +LUA_FUNCTION_DEF (textpart, has_8bit); /*** * @method text_part:get_content([type]) @@ -146,8 +146,8 @@ LUA_FUNCTION_DEF (textpart, get_mimepart); static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, is_utf), - LUA_INTERFACE_DEF (textpart, is_8bit_raw), - LUA_INTERFACE_DEF (textpart, is_8bit), + LUA_INTERFACE_DEF (textpart, has_8bit_raw), + LUA_INTERFACE_DEF (textpart, has_8bit), LUA_INTERFACE_DEF (textpart, get_content), LUA_INTERFACE_DEF (textpart, get_raw_content), LUA_INTERFACE_DEF (textpart, get_content_oneline), @@ -395,7 +395,7 @@ lua_textpart_is_utf (lua_State * L) static gint -lua_textpart_is_8bit_raw (lua_State * L) +lua_textpart_has_8bit_raw (lua_State * L) { struct rspamd_mime_text_part *part = lua_check_textpart (L); @@ -415,7 +415,7 @@ lua_textpart_is_8bit_raw (lua_State * L) } static gint -lua_textpart_is_8bit (lua_State * L) +lua_textpart_has_8bit (lua_State * L) { struct rspamd_mime_text_part *part = lua_check_textpart (L);