]> source.dussan.org Git - rspamd.git/commitdiff
Allow to get mime part from text part in lua.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Apr 2015 14:55:59 +0000 (15:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Apr 2015 14:55:59 +0000 (15:55 +0100)
src/lua/lua_mimepart.c

index f1012811ae0f6c03c40d1d681ef12d87c685add0..354dd3824f767a3b1394cda9268f10fa532c17f3 100644 (file)
@@ -97,6 +97,12 @@ LUA_FUNCTION_DEF (textpart, get_fuzzy);
  * @return {string} short abbreviation (such as `ru`) for the script's language
  */
 LUA_FUNCTION_DEF (textpart, get_language);
+/***
+ * @method text_part:get_mimepart()
+ * Returns the mime part object corresponding to this text part
+ * @return {mimepart} mimepart object
+ */
+LUA_FUNCTION_DEF (textpart, get_mimepart);
 /***
  * @method text_part:compare_distance(other)
  * Calculates the difference to another text part.  This function is intended to work with
@@ -117,6 +123,7 @@ static const struct luaL_reg textpartlib_m[] = {
        LUA_INTERFACE_DEF (textpart, is_html),
        LUA_INTERFACE_DEF (textpart, get_fuzzy),
        LUA_INTERFACE_DEF (textpart, get_language),
+       LUA_INTERFACE_DEF (textpart, get_mimepart),
        LUA_INTERFACE_DEF (textpart, compare_distance),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
@@ -380,6 +387,26 @@ lua_textpart_get_language (lua_State * L)
        return 1;
 }
 
+static gint
+lua_textpart_get_mimepart (lua_State * L)
+{
+       struct mime_text_part *part = lua_check_textpart (L);
+       struct mime_part **pmime;
+
+       if (part != NULL) {
+               if (part->mime_part != NULL) {
+                       pmime = lua_newuserdata (L, sizeof (struct mime_part *));
+                       rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
+                       *pmime = part->mime_part;
+
+                       return 1;
+               }
+       }
+
+       lua_pushnil (L);
+       return 1;
+}
+
 static gint
 lua_textpart_compare_distance (lua_State * L)
 {