diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2016-04-28 10:46:15 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2016-04-28 10:46:15 +0300 |
commit | 70c01c990ab4f82a1c7ff82f4c3f2df804de20a6 (patch) | |
tree | 3174d31cb80b12e91d545cc71e86b7e7121ab523 /rules/misc.lua | |
parent | f79fdbdd27f29991c9d6d1ff6ba1232cef1f3c61 (diff) | |
download | rspamd-70c01c990ab4f82a1c7ff82f4c3f2df804de20a6.tar.gz rspamd-70c01c990ab4f82a1c7ff82f4c3f2df804de20a6.zip |
[Minor] Improve subject rules
Make scores depend on subject length
Also resolves #548
Diffstat (limited to 'rules/misc.lua')
-rw-r--r-- | rules/misc.lua | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/rules/misc.lua b/rules/misc.lua index 7bfe73551..d071369c8 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -31,6 +31,36 @@ local r_font_color = '/font color=[\\"\']?\\#FFFFFF[\\"\']?/iP' reconf['R_WHITE_ON_WHITE'] = string.format('(!(%s) & (%s))', r_bgcolor, r_font_color) reconf['R_FLASH_REDIR_IMGSHACK'] = '/^(?:http:\\/\\/)?img\\d{1,5}\\.imageshack\\.us\\/\\S+\\.swf/U' +-- Local functions +local function insert_linear(task, a, x, symbol) + local f = a * x + task:insert_result(symbol, ( f < 1 ) and f or 1, tostring(x)) +end + +-- Subject issues +local function subject(task) + local sbj = task:get_header('Subject') + + if sbj then + local stripped_subject = subject_re:search(sbj, false, true) + if stripped_subject and stripped_subject[1] and stripped_subject[1][2] then + sbj = stripped_subject[1][2] + end + + local l = util.strlen_utf8(sbj) + if l > 200 then + insert_linear(task, 1/400, l, 'LONG_SUBJ') + end + if util.is_uppercase(sbj) then + insert_linear(task, 1/40, l, 'SUBJ_ALL_CAPS') + end + end + + return false +end + +rspamd_config:register_symbols(subject, 1.0, 'SUBJ', 'LONG_SUBJ', 'SUBJ_ALL_CAPS'); + -- Different text parts rspamd_config.R_PARTS_DIFFER = function(task) local distance = task:get_mempool():get_variable('parts_distance', 'double') @@ -106,42 +136,6 @@ rspamd_config.R_SUSPICIOUS_URL = function(task) return false end -rspamd_config.SUBJ_ALL_CAPS = { - callback = function(task) - local sbj = task:get_header('Subject') - - if sbj then - local stripped_subject = subject_re:search(sbj, false, true) - if stripped_subject and stripped_subject[1] and stripped_subject[1][2] then - sbj = stripped_subject[1][2] - end - - if util.is_uppercase(sbj) then - return true - end - end - - return false - end, - score = 3.0, - group = 'header', - description = 'All capital letters in subject' -} - -rspamd_config.LONG_SUBJ = { - callback = function(task) - local sbj = task:get_header('Subject') - if sbj and util.strlen_utf8(sbj) > 200 then - return true - end - return false - end, - - score = 3.0, - group = 'header', - description = 'Subject is too long' -} - rspamd_config.BROKEN_HEADERS = { callback = function(task) if task:has_flag('broken_headers') then |