diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-09-05 17:34:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-05 17:34:35 +0100 |
commit | d11ccf98176c8768167451bf3a6f6ac0c74dfce7 (patch) | |
tree | b33e50fe952db960f6e15ba6df2fa4e2fd72e516 /src/plugins | |
parent | c5dccd9bcd47bf8615f7472b81c7ffa76013a5de (diff) | |
parent | 04f29e7a97569cbb92aff4742bea9d5159d36b6a (diff) | |
download | rspamd-d11ccf98176c8768167451bf3a6f6ac0c74dfce7.tar.gz rspamd-d11ccf98176c8768167451bf3a6f6ac0c74dfce7.zip |
Merge pull request #929 from fatalbanana/forged
[Feature] Relax FORGED_RECIPIENTS: allow senders to BCC themselves
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/lua/forged_recipients.lua | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua index 4c52295b9..87743edf8 100644 --- a/src/plugins/lua/forged_recipients.lua +++ b/src/plugins/lua/forged_recipients.lua @@ -22,44 +22,51 @@ local symbol_rcpt = 'FORGED_RECIPIENTS' local symbol_sender = 'FORGED_SENDER' local function check_forged_headers(task) + local auser = task:get_user() local smtp_rcpt = task:get_recipients(1) + local smtp_from = task:get_from(1) local res = false local score = 1.0 - if smtp_rcpt then - local mime_rcpt = task:get_recipients(2) - local count = 0 - if mime_rcpt then - count = #mime_rcpt - end - if count > 0 and count < #smtp_rcpt then - task:insert_result(symbol_rcpt, 1) - elseif count > 0 then - -- Find pair for each smtp recipient recipient in To or Cc headers - for _,sr in ipairs(smtp_rcpt) do - if mime_rcpt then - for _,mr in ipairs(mime_rcpt) do - if mr['addr'] and sr['addr'] and - string.lower(mr['addr']) == string.lower(sr['addr']) then - res = true - break - elseif mr['user'] and sr['user'] and - string.lower(mr['user']) == string.lower(sr['user']) then - -- If we have the same username but for another domain, then - -- lower the overall score - score = score / 2 - end - end - end - if not res then - task:insert_result(symbol_rcpt, score) - break - end + if not smtp_rcpt then return end + if #smtp_rcpt == 0 then return end + local mime_rcpt = task:get_recipients(2) + if not mime_rcpt then + return + elseif #mime_rcpt == 0 then + task:insert_result(symbol_rcpt, score) + return + end + -- Find pair for each smtp recipient recipient in To or Cc headers + for _,sr in ipairs(smtp_rcpt) do + res = false + for _,mr in ipairs(mime_rcpt) do + if mr['addr'] and sr['addr'] and + string.lower(mr['addr']) == string.lower(sr['addr']) then + res = true + break + elseif auser and auser == sr['addr'] then + -- allow user to BCC themselves + res = true + break + elseif smtp_from and smtp_from[1] and smtp_from[1]['addr'] and + smtp_from[1]['addr'] == sr['addr'] then + -- allow sender to BCC themselves + res = true + break + elseif mr['user'] and sr['user'] and + string.lower(mr['user']) == string.lower(sr['user']) then + -- If we have the same username but for another domain, then + -- lower the overall score + score = score / 2 end end + if not res then + task:insert_result(symbol_rcpt, score) + break + end end -- Check sender - local smtp_from = task:get_from(1) if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then local mime_from = task:get_from(2) if not mime_from or not mime_from[1] or |