Skip to content

Instantly share code, notes, and snippets.

@vstakhov
Created August 28, 2015 13:41
Show Gist options
  • Save vstakhov/8a01f90aa17676c18f76 to your computer and use it in GitHub Desktop.
Save vstakhov/8a01f90aa17676c18f76 to your computer and use it in GitHub Desktop.
rspamd_config.R_EMPTY_IMAGE = {
callback = function(task)
local tp = task:get_text_parts() -- get text parts in a message
for _,p in ipairs(tp) do -- iterate over text parts array using `ipairs`
if p:is_html() then -- if the current part is html part
local hc = p:get_html() -- we get HTML context
local len = p:get_length() -- and part's length
if len < 50 then -- if we have a part that has less than 50 bytes of text
local images = hc:get_images() -- then we check for HTML images
if images then -- if there are images
for _,i in ipairs(images) do -- then iterate over images in the part
if i['height'] + i['width'] >= 400 then -- if we have a large image
return true -- add symbol
end
end
end
end
end
end
end,
score = 3.0, -- default score
condition = function(task) -- condition for the rule
if task:get_header('Subject') then
return true
end
return false
end,
description = 'No text parts and a large image',
}
-- Regular expression rule example
config['regexp']['RE_TEST'] = {
re = '/test/P',
score = 2.0,
condition = function(task)
if task:get_header('Subject') then
return true
end
return false
end,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment