]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Track visibility of HTML elements
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 15:30:14 +0000 (15:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 15:30:14 +0000 (15:30 +0000)
rules/html.lua
src/libserver/html.c
src/libserver/html.h
src/lua/lua_html.c

index 67f45168eb11c19c988ac8134a3b021c2c6d7045..a5f861b2de54db0ebe7ee12f8bf9d07724d440e6 100644 (file)
@@ -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']
index d2946398866a8c9904640a52846fc31c8b89b878..d36b8d6db6c3eb52ba76b895d8ec631e6cef7a51 100644 (file)
@@ -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 {
index 218594191269d6df5aae831b725553e097da6de8..5216ad767d07ae6fe6bbb2f9b8d631ba4e72da06 100644 (file)
@@ -75,6 +75,7 @@ struct html_block {
        struct html_color background_color;
        struct html_tag_component style;
        guint font_size;
+       gboolean visible;
        gchar *class;
 };
 
index 1766d8f2f37c3e100c3fd06620add02079dfe00c..b680dae4ebd9018f49ca933c3457a722431c6785 100644 (file)
@@ -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