From e215f89e7cbbbeaeb5d0ed7bbd0631ea3a6a6d70 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 19 Jul 2021 10:31:36 +0100 Subject: [PATCH] [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 } -- 2.39.5