commit 388dd3f: [Fix] Improve part:is_attachment logic

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jul 15 14:56:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-07-15 15:51:22 +0100
URL: https://github.com/rspamd/rspamd/commit/388dd3f53f65474c73cdeea675ce9569692da371 (HEAD -> master)

[Fix] Improve part:is_attachment logic

---
 src/lua/lua_mimepart.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index e183b6ae6..9748cfde3 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -1764,22 +1764,27 @@ lua_mimepart_is_attachment (lua_State * L)
 		return luaL_error (L, "invalid arguments");
 	}
 
-	if (part->part_type != RSPAMD_MIME_PART_IMAGE) {
-		if (part->cd && part->cd->type == RSPAMD_CT_ATTACHMENT) {
-			lua_pushboolean (L, true);
-		}
-		else {
-			if (part->cd && part->cd->filename.len > 0) {
-				/* We still have filename and it is not an image */
+	if (part->cd && part->cd->type == RSPAMD_CT_ATTACHMENT) {
+		lua_pushboolean (L, true);
+	}
+	else {
+		/* if has_name and not (image and Content-ID_header_present) */
+		if (part->cd && part->cd->filename.len > 0) {
+			if (part->part_type != RSPAMD_MIME_PART_IMAGE &&
+				rspamd_message_get_header_from_hash (part->raw_headers,
+						"Content-Id") == NULL) {
+				/* Filename is presented but no content id and not image */
 				lua_pushboolean (L, true);
 			}
 			else {
+				/* Image or an embeded object */
 				lua_pushboolean (L, false);
 			}
 		}
-	}
-	else {
-		lua_pushboolean (L, false);
+		else {
+			/* No filename */
+			lua_pushboolean (L, false);
+		}
 	}
 
 	return 1;


More information about the Commits mailing list