commit d5c9770: [Minor] Lua_mimepart: Return raw content for visually empty html parts

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Feb 4 15:49:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-04 15:43:25 +0000
URL: https://github.com/rspamd/rspamd/commit/d5c97700dfea628844e0e67eb4769fd4288473c6 (HEAD -> master)

[Minor] Lua_mimepart: Return raw content for visually empty html parts

---
 src/lua/lua_mimepart.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 50cdaa7b7..b66ad4215 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -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;


More information about the Commits mailing list