]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add task:get_rawbody method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 3 May 2016 09:06:55 +0000 (10:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 3 May 2016 09:06:55 +0000 (10:06 +0100)
src/lua/lua_task.c

index 49fda365618e35fef6b623dc64c2fc6769cbd50a..1f038376401406ff27f285268ed4a1a30b25b484 100644 (file)
@@ -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)
 {