Skip to content

Instantly share code, notes, and snippets.

@c-rosenberg
Last active February 6, 2024 16:03
Show Gist options
  • Save c-rosenberg/d1fb220936772bd5d860449bde820ec1 to your computer and use it in GitHub Desktop.
Save c-rosenberg/d1fb220936772bd5d860449bde820ec1 to your computer and use it in GitHub Desktop.
Rspamd Lua - match spam with alliteration in from display name, subject and 3 body words
-- Match Spam with alliteration in from display name, subject and 3 body words
-- e.g.
-- MIME From: "Schloemer" <axmyyxb@salebig.pro.ac>
-- Subject: Schutjer
-- Body: Seetaram Sesay Sheker
rspamd_config:register_symbol{
type = 'callback', -- or virtual, callback, prefilter or postfilter
name = 'SPAM_ALLITERATION',
score = 0.0, -- Metric score
callback = function(task)
local symbol = "SPAM_ALLITERATION"
local from_dn = (((task:get_from('mime') or E)[1] or E).name or "")
local from_dn_1 = from_dn:sub(1,1)
local subject = task:get_subject() or ""
local subject_1 = subject:sub(1,1)
local parts = task:get_text_parts() or E
if from_dn:match("^%a+$") and subject:match("^%a+$")
and from_dn_1 == subject_1
then
local aliteration = true
for _,p in ipairs(parts) do
if not p:is_html() then
local word_c = p:get_words_count(p)
if word_c == 3 then
local words = p:get_words('raw')
for _, w in ipairs(words) do
if w:sub(1,1) ~= from_dn_1 then
aliteration = false
end
end
end
end
end
if aliteration then
task:insert_result(symbol, 1.0, from_dn_1)
return true
end
end
return false
end,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment