From: Vsevolod Stakhov Date: Tue, 1 Nov 2016 15:30:14 +0000 (+0000) Subject: [Feature] Track visibility of HTML elements X-Git-Tag: 1.4.0~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a820f15c13ead1dc2675c42296bcf80bb424098;p=thirdparty%2Frspamd.git [Feature] Track visibility of HTML elements --- diff --git a/rules/html.lua b/rules/html.lua index 67f45168eb..a5f861b2de 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -187,7 +187,7 @@ rspamd_config.R_WHITE_ON_WHITE = { hc:foreach_tag({'font', 'span', 'div', 'p'}, function(tag, len) local bl = tag:get_extra() if bl then - if bl['bgcolor'] and bl['color'] then + if bl['bgcolor'] and bl['color'] and bl['visible'] then local color = bl['color'] local bgcolor = bl['bgcolor'] diff --git a/src/libserver/html.c b/src/libserver/html.c index d294639886..d36b8d6db6 100644 --- a/src/libserver/html.c +++ b/src/libserver/html.c @@ -1558,6 +1558,13 @@ rspamd_html_process_style (rspamd_mempool_t *pool, struct html_block *bl, rspamd_html_process_color (c, p - c, &bl->background_color); msg_debug_html ("got bgcolor: %xd", bl->background_color.d.val); } + else if (klen == 7 && g_ascii_strncasecmp (key, "display", 7) == 0) { + if (p - c >= 4 && rspamd_substring_search_caseless (c, p - c, + "none", 4) != -1) { + bl->visible = FALSE; + msg_debug_html ("tag is not visible"); + } + } } key = NULL; @@ -1597,6 +1604,7 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag, cur = tag->params->head; bl = rspamd_mempool_alloc0 (pool, sizeof (*bl)); bl->tag = tag; + bl->visible = TRUE; while (cur) { comp = cur->data; @@ -2111,7 +2119,14 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc, } else if (!(cur_tag->flags & FL_CLOSING) && (cur_tag->flags & FL_BLOCK)) { + struct html_block *bl; + rspamd_html_process_block_tag (pool, cur_tag, hc); + bl = cur_tag->extra; + + if (bl && !bl->visible) { + state = content_ignore; + } } } else { diff --git a/src/libserver/html.h b/src/libserver/html.h index 2185941912..5216ad767d 100644 --- a/src/libserver/html.h +++ b/src/libserver/html.h @@ -75,6 +75,7 @@ struct html_block { struct html_color background_color; struct html_tag_component style; guint font_size; + gboolean visible; gchar *class; }; diff --git a/src/lua/lua_html.c b/src/lua/lua_html.c index 1766d8f2f3..b680dae4eb 100644 --- a/src/lua/lua_html.c +++ b/src/lua/lua_html.c @@ -318,7 +318,7 @@ lua_html_push_block (lua_State *L, struct html_block *bl) struct rspamd_lua_text *t; struct html_tag **ptag; - lua_createtable (L, 0, 4); + lua_createtable (L, 0, 5); if (bl->tag) { lua_pushstring (L, "tag"); @@ -359,6 +359,10 @@ lua_html_push_block (lua_State *L, struct html_block *bl) t->flags = 0; lua_settable (L, -3); } + + lua_pushstring (L, "visible"); + lua_pushboolean (L, bl->visible); + lua_settable (L, -3); } static gint