From 0cb2840c4bc897e6b60435a3dc785dd461b07787 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 11 Mar 2017 13:27:17 +0000 Subject: [PATCH] [Minor] Use modern syntax in rules registration --- rules/headers_checks.lua | 188 ++++++++++++++++++++++++++++++--------- rules/misc.lua | 40 ++++----- 2 files changed, 167 insertions(+), 61 deletions(-) diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index 765643c72..fc041c57d 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -419,8 +419,10 @@ rspamd_config.FAKE_REPLY = { score = 1.0 } -local check_from_id = rspamd_config:register_callback_symbol('CHECK_FROM', 1.0, - function(task) +local check_from_id = rspamd_config:register_symbol{ + name = 'CHECK_FROM', + type = 'callback', + callback = function(task) local envfrom = task:get_from(1) local from = task:get_from(2) if (from and from[1] and not from[1].name) then @@ -464,29 +466,85 @@ local check_from_id = rspamd_config:register_callback_symbol('CHECK_FROM', 1.0, task:insert_result('TO_DOM_EQ_FROM_DOM', 1.0) end end -) +} + +rspamd_config:register_symbol{ + name = 'FROM_NO_DN', + score = 0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From header does not have a display name', +} +rspamd_config:register_symbol{ + name = 'FROM_DN_EQ_ADDR', + score = 1.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From header display name is the same as the address', +} +rspamd_config:register_symbol{ + name = 'FROM_HAS_DN', + score = 0.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From header has a display name', +} +rspamd_config:register_symbol{ + name = 'FROM_NAME_EXCESS_SPACE', + score = 1.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From header display name contains excess whitespace', +} +rspamd_config:register_symbol{ + name = 'FROM_NAME_HAS_TITLE', + score = 1.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From header display name has a title (Mr/Mrs/Dr)', +} +rspamd_config:register_symbol{ + name = 'FROM_EQ_ENVFROM', + score = 0.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From address is the same as the envelope', +} +rspamd_config:register_symbol{ + name = 'FROM_NEQ_ENVFROM', + score = 0.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'From address is different to the envelope', +} +rspamd_config:register_symbol{ + name = 'TO_EQ_FROM', + score = 0.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'To address matches the From address', +} +rspamd_config:register_symbol{ + name = 'TO_DOM_EQ_FROM_DOM', + score = 0.0, + group = 'header', + parent = check_from_id, + type = 'virtual', + description = 'To domain is the same as the From domain', +} -rspamd_config:register_virtual_symbol('FROM_NO_DN', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_NO_DN', 0, 'From header does not have a display name') -rspamd_config:register_virtual_symbol('FROM_DN_EQ_ADDR', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_DN_EQ_ADDR', 1.0, 'From header display name is the same as the address') -rspamd_config:register_virtual_symbol('FROM_HAS_DN', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_HAS_DN', 0, 'From header has a display name') -rspamd_config:register_virtual_symbol('FROM_NAME_EXCESS_SPACE', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_NAME_EXCESS_SPACE', 1.0, 'From header display name contains excess whitespace') -rspamd_config:register_virtual_symbol('FROM_NAME_HAS_TITLE', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_NAME_HAS_TITLE', 1.0, 'From header display name has a title (Mr/Mrs/Dr)') -rspamd_config:register_virtual_symbol('FROM_EQ_ENVFROM', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_EQ_ENVFROM', 0, 'From address is the same as the envelope') -rspamd_config:register_virtual_symbol('FROM_NEQ_ENVFROM', 1.0, check_from_id) -rspamd_config:set_metric_symbol('FROM_NEQ_ENVFROM', 0, 'From address is different to the envelope') -rspamd_config:register_virtual_symbol('TO_EQ_FROM', 1.0, check_from_id) -rspamd_config:set_metric_symbol('TO_EQ_FROM', 0, 'To address matches the From address') -rspamd_config:register_virtual_symbol('TO_DOM_EQ_FROM_DOM', 1.0, check_from_id) -rspamd_config:set_metric_symbol('TO_DOM_EQ_FROM_DOM', 0, 'To domain is the same as the From domain') - -local check_to_cc_id = rspamd_config:register_callback_symbol('CHECK_TO_CC', 1.0, - function(task) +local check_to_cc_id = rspamd_config:register_symbol{ + name = 'CHECK_TO_CC', + type = 'callback', + callback = function(task) local rcpts = task:get_recipients(1) local to = task:get_recipients(2) local to_match_envrcpt = 0 @@ -542,21 +600,69 @@ local check_to_cc_id = rspamd_config:register_callback_symbol('CHECK_TO_CC', 1.0 task:insert_result('TO_MATCH_ENVRCPT_SOME', 1.0) end end -) +} -rspamd_config:register_virtual_symbol('TO_DN_RECIPIENTS', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_RECIPIENTS', 2.0, 'To header display name is "Recipients"') -rspamd_config:register_virtual_symbol('TO_DN_NONE', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_NONE', 0, 'None of the recipients have display names') -rspamd_config:register_virtual_symbol('TO_DN_ALL', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_ALL', 0, 'All of the recipients have display names') -rspamd_config:register_virtual_symbol('TO_DN_SOME', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_SOME', 0, 'Some of the recipients have display names') -rspamd_config:register_virtual_symbol('TO_DN_EQ_ADDR_ALL', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_EQ_ADDR_ALL', 0, 'All of the recipients have display names that are the same as their address') -rspamd_config:register_virtual_symbol('TO_DN_EQ_ADDR_SOME', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_DN_EQ_ADDR_SOME', 0, 'Some of the recipients have display names that are the same as their address') -rspamd_config:register_virtual_symbol('TO_MATCH_ENVRCPT_ALL', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_MATCH_ENVRCPT_ALL', 0, 'All of the recipients match the envelope') -rspamd_config:register_virtual_symbol('TO_MATCH_ENVRCPT_SOME', 1.0, check_to_cc_id) -rspamd_config:set_metric_symbol('TO_MATCH_ENVRCPT_SOME', 0, 'Some of the recipients match the envelope') \ No newline at end of file +rspamd_config:register_symbol{ + name = 'TO_DN_RECIPIENTS', + score = 2.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'To header display name is "Recipients"', +} +rspamd_config:register_symbol{ + name = 'TO_DN_NONE', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'None of the recipients have display names', +} +rspamd_config:register_symbol{ + name = 'TO_DN_ALL', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'All the recipients have display names', +} +rspamd_config:register_symbol{ + name = 'TO_DN_SOME', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'Some of the recipients have display names', +} +rspamd_config:register_symbol{ + name = 'TO_DN_EQ_ADDR_ALL', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'All of the recipients have display names that are the same as their address', +} +rspamd_config:register_symbol{ + name = 'TO_DN_EQ_ADDR_SOME', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'Some of the recipients have display names that are the same as their address', +} +rspamd_config:register_symbol{ + name = 'TO_MATCH_ENVRCPT_ALL', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'All of the recipients match the envelope', +} +rspamd_config:register_symbol{ + name = 'TO_MATCH_ENVRCPT_SOME', + score = 0.0, + group = 'header', + parent = check_to_cc_id, + type = 'virtual', + description = 'Some of the recipients match the envelope', +} diff --git a/rules/misc.lua b/rules/misc.lua index 30a3d57ba..59c8ec4a7 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -191,26 +191,26 @@ rspamd_config.ENVFROM_VERP = { } rspamd_config.RCVD_TLS_ALL = { - callback = function (task) - local rcvds = task:get_header_full('Received') - if not rcvds then return false end - local count = 0 - local encrypted = 0 - for _, rcvd in ipairs(rcvds) do - count = count + 1 - local r = rcvd['decoded']:lower() - local with = r:match('%swith%s+(e?smtps?a?)') - if with and with:match('esmtps') then - encrypted = encrypted + 1 - end - end - if (count > 0 and count == encrypted) then - return true - end - end, - score = 0.0, - description = "All hops used encrypted transports", - group = "encryption" + callback = function (task) + local rcvds = task:get_header_full('Received') + if not rcvds then return false end + local count = 0 + local encrypted = 0 + for _, rcvd in ipairs(rcvds) do + count = count + 1 + local r = rcvd['decoded']:lower() + local with = r:match('%swith%s+(e?smtps?a?)') + if with and with:match('esmtps') then + encrypted = encrypted + 1 + end + end + if (count > 0 and count == encrypted) then + return true + end + end, + score = 0.0, + description = "All hops used encrypted transports", + group = "encryption" } rspamd_config.RCVD_HELO_USER = { -- 2.39.5