Skip to content

Instantly share code, notes, and snippets.

@vstakhov
Created September 30, 2019 12:08
Show Gist options
  • Save vstakhov/970388beab336fdb49c0b9ed340b953e to your computer and use it in GitHub Desktop.
Save vstakhov/970388beab336fdb49c0b9ed340b953e to your computer and use it in GitHub Desktop.
local u = require "lua_util"
local m = require "lua_magic"
local l = require "rspamd_logger"
local text = require "rspamd_text"
local rspamd_task = require "rspamd_task"
local rspamd_util = require "rspamd_util"
local function load_task(opts, fname)
if not fname then
fname = '-'
end
local f = io.open(fname, "r"):read("*a")
f = [[From: <>
Content-Type: application/octet-stream
]] .. f
local res,task = rspamd_task.load_from_string(f, rspamd_config)
if not res then
assert(false, string.format('cannot read message from %s: %s', fname,
task))
end
if not task:process_message() then
assert(false, string.format('cannot read message from %s: %s', fname,
'failed to parse'))
end
return task
end
task = load_task(nil, arg[1])
local part = task:get_parts()[1]
local t1 = rspamd_util.get_ticks()
local det = m.detect_mime_part(part, task)
local t2 = rspamd_util.get_ticks()
l.errx('detected: %s; %s msec', det, (t2 - t1) * 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment