From: Andrew Lewis Date: Tue, 30 Jan 2018 22:56:57 +0000 (+0200) Subject: [Minor] Small fixes for rspamadm corpus_test X-Git-Tag: 1.7.0~207 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=724a0b6e7cfdf9652e3f04bebad58a8ec617b174;p=thirdparty%2Frspamd.git [Minor] Small fixes for rspamadm corpus_test --- diff --git a/lualib/rspamadm/corpus_test.lua b/lualib/rspamadm/corpus_test.lua index fa296a0b49..eb93d586c6 100644 --- a/lualib/rspamadm/corpus_test.lua +++ b/lualib/rspamadm/corpus_test.lua @@ -1,3 +1,4 @@ +local rspamd_logger = require "rspamd_logger" local ucl = require "ucl" local lua_util = require "lua_util" @@ -41,13 +42,17 @@ local function encoded_json_to_log(result) local is_good, err = parser:parse_string(result) if not is_good then - print(err) - os.exit() + io.stderr:write(rspamd_logger.slog("Parser error: %1\n", err)) + return nil end result = parser:get_object() filtered_result.score = result.score + if not result.action then + io.stderr:write(rspamd_logger.slog("Bad JSON: %1\n", result)) + return nil + end local action = result.action:gsub("%s+", "_") filtered_result.action = action @@ -72,8 +77,10 @@ local function scan_results_to_logs(results, actual_email_type) for _, result in pairs(results) do result = encoded_json_to_log(result) - result['type'] = actual_email_type - table.insert(logs, result) + if result then + result['type'] = actual_email_type + table.insert(logs, result) + end end return logs @@ -106,7 +113,7 @@ return function (_, res) if spam_directory then io.write("Scanning spam corpus...\n") - local spam_results = scan_email(connections, spam_directory) + local spam_results = scan_email(connections, spam_directory, res.timeout) spam_results = scan_results_to_logs(spam_results, SPAM) no_of_spam = #spam_results @@ -124,4 +131,4 @@ return function (_, res) io.write(string.format("No of ham: %d\n", no_of_ham)) io.write(string.format("No of spam: %d\n", no_of_spam)) -end \ No newline at end of file +end