From: Vsevolod Stakhov Date: Tue, 3 May 2016 09:06:55 +0000 (+0100) Subject: [Feature] Add task:get_rawbody method X-Git-Tag: 1.3.0~574 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9ea7aeacc8df7d90b2a1f7737a6053529ea5281;p=thirdparty%2Frspamd.git [Feature] Add task:get_rawbody method --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 49fda36561..1f03837640 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -146,9 +146,17 @@ LUA_FUNCTION_DEF (task, has_urls); /*** * @method task:get_content() * Get raw content for the specified task - * @return {string} the data contained in the task + * @return {text} the data contained in the task */ LUA_FUNCTION_DEF (task, get_content); + +/*** + * @method task:get_content() + * Get raw body for the specified task + * @return {text} the data contained in the task + */ +LUA_FUNCTION_DEF (task, get_rawbody); + /*** * @method task:get_emails() * Get all email addresses found in a message. @@ -595,6 +603,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, has_urls), LUA_INTERFACE_DEF (task, get_urls), LUA_INTERFACE_DEF (task, get_content), + LUA_INTERFACE_DEF (task, get_rawbody), LUA_INTERFACE_DEF (task, get_emails), LUA_INTERFACE_DEF (task, get_text_parts), LUA_INTERFACE_DEF (task, get_parts), @@ -1052,6 +1061,35 @@ lua_task_get_content (lua_State * L) return 1; } +static gint +lua_task_get_rawbody (lua_State * L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + struct rspamd_lua_text *t; + + if (task) { + t = lua_newuserdata (L, sizeof (*t)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + + if (task->raw_headers_content.len > 0) { + g_assert (task->raw_headers_content.len <= task->msg.len); + t->start = task->msg.begin + task->raw_headers_content.len; + t->len = task->msg.len - task->raw_headers_content.len; + } + else { + t->len = task->msg.len; + t->start = task->msg.begin; + } + + t->own = FALSE; + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_task_get_emails (lua_State * L) {