]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Lua_mimepart: Return raw content for visually empty html parts
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Feb 2019 15:43:25 +0000 (15:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Feb 2019 15:43:25 +0000 (15:43 +0000)
src/lua/lua_mimepart.c

index 50cdaa7b79d1438c4db1ffa3b1bf43961ca2c55a..b66ad4215a37dc55b0becea9e1040f6dffb53276 100644 (file)
@@ -617,7 +617,7 @@ lua_textpart_get_content (lua_State * L)
        gsize len;
        const gchar *start, *type = NULL;
 
-       if (part == NULL || IS_PART_EMPTY (part)) {
+       if (part == NULL) {
                lua_pushnil (L);
                return 1;
        }
@@ -626,30 +626,56 @@ lua_textpart_get_content (lua_State * L)
                type = lua_tostring (L, 2);
        }
 
-       t = lua_newuserdata (L, sizeof (*t));
-       rspamd_lua_setclass (L, "rspamd{text}", -1);
-
        if (!type) {
+               if (IS_PART_EMPTY (part)) {
+                       lua_pushnil (L);
+                       return 1;
+               }
                start = part->utf_content->data;
                len = part->utf_content->len;
        }
        else if (strcmp (type, "content") == 0) {
+               if (IS_PART_EMPTY (part)) {
+                       lua_pushnil (L);
+                       return 1;
+               }
+
                start = part->utf_content->data;
                len = part->utf_content->len;
        }
        else if (strcmp (type, "content_oneline") == 0) {
+               if (IS_PART_EMPTY (part)) {
+                       lua_pushnil (L);
+                       return 1;
+               }
+
                start = part->utf_stripped_content->data;
                len = part->utf_stripped_content->len;
        }
        else if (strcmp (type, "raw_parsed") == 0) {
+               if (part->parsed.len == 0) {
+                       lua_pushnil (L);
+                       return 1;
+               }
+
                start = part->parsed.begin;
                len = part->parsed.len;
        }
        else if (strcmp (type, "raw_utf") == 0) {
+               if (part->utf_raw_content == NULL || part->utf_raw_content->len == 0) {
+                       lua_pushnil (L);
+                       return 1;
+               }
+
                start = part->utf_raw_content->data;
                len = part->utf_raw_content->len;
        }
        else if (strcmp (type, "raw") == 0) {
+               if (part->raw.len == 0) {
+                       lua_pushnil (L);
+                       return 1;
+               }
+
                start = part->raw.begin;
                len = part->raw.len;
        }
@@ -657,6 +683,9 @@ lua_textpart_get_content (lua_State * L)
                return luaL_error (L, "invalid content type: %s", type);
        }
 
+       t = lua_newuserdata (L, sizeof (*t));
+       rspamd_lua_setclass (L, "rspamd{text}", -1);
+
        t->start = start;
        t->len = len;
        t->flags = 0;