commit e215f89: [Minor] Try to fix has_fake_html rule

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jul 19 09:35:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-19 10:31:36 +0100
URL: https://github.com/rspamd/rspamd/commit/e215f89e7cbbbeaeb5d0ed7bbd0631ea3a6a6d70 (HEAD -> master)

[Minor] Try to fix has_fake_html rule

---
 src/libmime/mime_expressions.c |  2 +-
 src/libserver/html/html.cxx    | 12 ++++++++++++
 src/libserver/html/html.h      |  7 +++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c
index 477b1dc5d..06b590f51 100644
--- a/src/libmime/mime_expressions.c
+++ b/src/libmime/mime_expressions.c
@@ -1609,7 +1609,7 @@ rspamd_has_fake_html (struct rspamd_task * task, GArray * args, void *unused)
 	gboolean res = FALSE;
 
 	PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, text_parts), i, p) {
-		if (IS_TEXT_PART_HTML (p) && (p->html == NULL)) {
+		if (IS_TEXT_PART_HTML (p) && (rspamd_html_get_tags_count(p->html) < 2)) {
 			res = TRUE;
 		}
 
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index 332229b50..beec91fac 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -2097,4 +2097,16 @@ rspamd_html_get_parsed_content(void *html_content, rspamd_ftok_t *dest)
 	dest->len = hc->parsed.size();
 
 	return true;
+}
+
+gsize
+rspamd_html_get_tags_count(void *html_content)
+{
+	auto *hc = rspamd::html::html_content::from_ptr(html_content);
+
+	if (!hc) {
+		return 0;
+	}
+
+	return hc->all_tags.size();
 }
\ No newline at end of file
diff --git a/src/libserver/html/html.h b/src/libserver/html/html.h
index cc8039c22..8b690499e 100644
--- a/src/libserver/html/html.h
+++ b/src/libserver/html/html.h
@@ -121,6 +121,13 @@ struct html_image* rspamd_html_find_embedded_image(void *html_content,
  */
 bool rspamd_html_get_parsed_content(void *html_content, rspamd_ftok_t *dest);
 
+/**
+ * Returns number of tags in the html content
+ * @param html_content
+ * @return
+ */
+gsize rspamd_html_get_tags_count(void *html_content);
+
 
 #ifdef  __cplusplus
 }


More information about the Commits mailing list