]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add text_part:get_html() method.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 14:23:44 +0000 (15:23 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 14:23:44 +0000 (15:23 +0100)
src/lua/lua_mimepart.c

index 323ebfd320b1489c2bd8a2a0b348dbe9f008bfda..d14af08a2bf773d0254db7a2d62d36e27ab91326 100644 (file)
@@ -85,6 +85,12 @@ LUA_FUNCTION_DEF (textpart, is_empty);
  * @return {bool} whether a part is HTML part
  */
 LUA_FUNCTION_DEF (textpart, is_html);
+/***
+ * @method text_part:get_html()
+ * Returns html content of the specified part
+ * @return {html} html content
+ */
+LUA_FUNCTION_DEF (textpart, get_html);
 /***
  * @method text_part:get_language()
  * Returns the code of the most used unicode script in the text part. Does not work with raw parts
@@ -105,6 +111,7 @@ static const struct luaL_reg textpartlib_m[] = {
        LUA_INTERFACE_DEF (textpart, get_lines_count),
        LUA_INTERFACE_DEF (textpart, is_empty),
        LUA_INTERFACE_DEF (textpart, is_html),
+       LUA_INTERFACE_DEF (textpart, get_html),
        LUA_INTERFACE_DEF (textpart, get_language),
        LUA_INTERFACE_DEF (textpart, get_mimepart),
        {"__tostring", rspamd_lua_class_tostring},
@@ -335,6 +342,23 @@ lua_textpart_is_html (lua_State * L)
        return 1;
 }
 
+static gint
+lua_textpart_get_html (lua_State * L)
+{
+       struct mime_text_part *part = lua_check_textpart (L);
+       struct html_content **phc;
+
+       if (part == NULL || part->html == NULL) {
+               lua_pushnil (L);
+       }
+       else {
+               phc = lua_newuserdata (L, sizeof (*phc));
+               rspamd_lua_setclass (L, "rspamd{html}", -1);
+               *phc = part->html;
+       }
+
+       return 1;
+}
 
 static gint
 lua_textpart_get_language (lua_State * L)