diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-19 17:13:33 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-19 17:13:33 +0100 |
commit | e1c695b059428b6daa385ced5bfda2c9cdf98a75 (patch) | |
tree | a3057c48073661dfdb7a48854629515ad988bb75 /rules/http_headers.lua | |
parent | fb713b23a2cb8acb40b37e14b87c58d9c0bf2a88 (diff) | |
download | rspamd-e1c695b059428b6daa385ced5bfda2c9cdf98a75.tar.gz rspamd-e1c695b059428b6daa385ced5bfda2c9cdf98a75.zip |
Fix parsing of headers
Diffstat (limited to 'rules/http_headers.lua')
-rw-r--r-- | rules/http_headers.lua | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/rules/http_headers.lua b/rules/http_headers.lua index 9a7ff3b09..41f3c95cf 100644 --- a/rules/http_headers.lua +++ b/rules/http_headers.lua @@ -34,18 +34,20 @@ rspamd_config:add_condition("R_DKIM_ALLOW", function(task) if hdr then local parser = ucl.parser() local res, err = parser:parse_string(tostring(hdr)) - if not res or type(res) ~= 'table' then + if not res then logger.infox(task, "cannot parse DKIM header: %1", err) return true end - if res['result'] then - if res['result'] == 'pass' or res['result'] == 'allow' then - task:insert_result('R_DKIM_ALLOW', 1.0) - elseif res['result'] == 'fail' or res['result'] == 'reject' then - task:insert_result('R_DKIM_REJECT', 1.0) - elseif res['result'] == 'tempfail' or res['result'] == 'softfail' then - task:insert_result('R_DKIM_TEMPFAIL', 1.0) + local obj = parser:get_object() + + if obj['result'] then + if obj['result'] == 'pass' or obj['result'] == 'allow' then + task:insert_result('R_DKIM_ALLOW', 1.0, 'http header') + elseif obj['result'] == 'fail' or obj['result'] == 'reject' then + task:insert_result('R_DKIM_REJECT', 1.0, 'http header') + elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then + task:insert_result('R_DKIM_TEMPFAIL', 1.0, 'http header') end return false @@ -62,20 +64,22 @@ rspamd_config:add_condition("R_SPF_ALLOW", function(task) if hdr then local parser = ucl.parser() local res, err = parser:parse_string(tostring(hdr)) - if not res or type(res) ~= 'table' then + if not res then logger.infox(task, "cannot parse SPF header: %1", err) return true end - if res['result'] then - if res['result'] == 'pass' or res['result'] == 'allow' then - task:insert_result('R_SPF_ALLOW', 1.0) - elseif res['result'] == 'fail' or res['result'] == 'reject' then - task:insert_result('R_SPF_FAIL', 1.0) - elseif res['result'] == 'neutral' then - task:insert_result('R_SPF_NEUTRAL', 1.0) - elseif res['result'] == 'tempfail' or res['result'] == 'softfail' then - task:insert_result('R_SPF_TEMPFAIL', 1.0) + local obj = parser:get_object() + + if obj['result'] then + if obj['result'] == 'pass' or obj['result'] == 'allow' then + task:insert_result('R_SPF_ALLOW', 1.0, 'http header') + elseif obj['result'] == 'fail' or obj['result'] == 'reject' then + task:insert_result('R_SPF_FAIL', 1.0, 'http header') + elseif obj['result'] == 'neutral' then + task:insert_result('R_SPF_NEUTRAL', 1.0, 'http header') + elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then + task:insert_result('R_SPF_TEMPFAIL', 1.0, 'http header') end return false @@ -91,20 +95,22 @@ rspamd_config:add_condition("DMARC_POLICY_ALLOW", function(task) if hdr then local parser = ucl.parser() local res, err = parser:parse_string(tostring(hdr)) - if not res or type(res) ~= 'table' then + if not res then logger.infox(task, "cannot parse DMARC header: %1", err) return true end - if res['result'] then - if res['result'] == 'pass' or res['result'] == 'allow' then - task:insert_result('DMARC_POLICY_ALLOW', 1.0) - elseif res['result'] == 'fail' or res['result'] == 'reject' then - task:insert_result('DMARC_POLICY_REJECT', 1.0) - elseif res['result'] == 'quarantine' then - task:insert_result('DMARC_POLICY_QUARANTINE', 1.0) - elseif res['result'] == 'tempfail' or res['result'] == 'softfail' then - task:insert_result('DMARC_POLICY_SOFTFAIL', 1.0) + local obj = parser:get_object() + + if obj['result'] then + if obj['result'] == 'pass' or obj['result'] == 'allow' then + task:insert_result('DMARC_POLICY_ALLOW', 1.0, 'http header') + elseif obj['result'] == 'fail' or obj['result'] == 'reject' then + task:insert_result('DMARC_POLICY_REJECT', 1.0, 'http header') + elseif obj['result'] == 'quarantine' then + task:insert_result('DMARC_POLICY_QUARANTINE', 1.0, 'http header') + elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then + task:insert_result('DMARC_POLICY_SOFTFAIL', 1.0, 'http header') end return false |