]> source.dussan.org Git - rspamd.git/commitdiff
Add textpart:get_raw_length method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 15:11:25 +0000 (16:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 15:11:25 +0000 (16:11 +0100)
src/lua/lua_mimepart.c

index d14af08a2bf773d0254db7a2d62d36e27ab91326..2cf7ef3551b9b597ede86f18ebae8f657acf5306 100644 (file)
@@ -67,6 +67,12 @@ LUA_FUNCTION_DEF (textpart, get_content);
  * @return {integer} length of part in **bytes**
  */
 LUA_FUNCTION_DEF (textpart, get_length);
+/***
+ * @method mime_part:get_raw_length()
+ * Get length of the **raw** content of the part (e.g. HTML with tags unstripped)
+ * @return {integer} length of part in **bytes**
+ */
+LUA_FUNCTION_DEF (textpart, get_raw_length);
 /***
  * @method mime_part:get_lines_count()
  * Get lines number in the part
@@ -108,6 +114,7 @@ static const struct luaL_reg textpartlib_m[] = {
        LUA_INTERFACE_DEF (textpart, is_utf),
        LUA_INTERFACE_DEF (textpart, get_content),
        LUA_INTERFACE_DEF (textpart, get_length),
+       LUA_INTERFACE_DEF (textpart, get_raw_length),
        LUA_INTERFACE_DEF (textpart, get_lines_count),
        LUA_INTERFACE_DEF (textpart, is_empty),
        LUA_INTERFACE_DEF (textpart, is_html),
@@ -282,7 +289,7 @@ lua_textpart_get_length (lua_State * L)
                return 1;
        }
 
-       if (IS_PART_EMPTY (part)) {
+       if (IS_PART_EMPTY (part) || part->content == NULL) {
                lua_pushnumber (L, 0);
        }
        else {
@@ -292,6 +299,26 @@ lua_textpart_get_length (lua_State * L)
        return 1;
 }
 
+static gint
+lua_textpart_get_raw_length (lua_State * L)
+{
+       struct mime_text_part *part = lua_check_textpart (L);
+
+       if (part == NULL) {
+               lua_pushnil (L);
+               return 1;
+       }
+
+       if (IS_PART_EMPTY (part) || part->orig == NULL) {
+               lua_pushnumber (L, 0);
+       }
+       else {
+               lua_pushnumber (L, part->orig->len);
+       }
+
+       return 1;
+}
+
 static gint
 lua_textpart_get_lines_count (lua_State * L)
 {