]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix parsing of background color
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 13:15:51 +0000 (14:15 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 15:06:22 +0000 (16:06 +0100)
src/libserver/html.c
src/libserver/html.h
src/lua/lua_html.c

index d39816f873fbf48563cc1d47185cb0f101948d66..e20fbadcef946f059e3b877a59c950223d6d9370 100644 (file)
@@ -880,6 +880,11 @@ rspamd_html_parse_tag_component (rspamd_mempool_t *pool,
                                NEW_COMPONENT (RSPAMD_HTML_COMPONENT_CLASS);
                        }
                }
+               else if (len == 7) {
+                       if (g_ascii_strncasecmp (begin, "bgcolor", len) == 0) {
+                               NEW_COMPONENT (RSPAMD_HTML_COMPONENT_BGCOLOR);
+                       }
+               }
        }
 
        return ret;
@@ -1584,6 +1589,17 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag,
                        rspamd_html_process_color (comp->start, comp->len, &bl->font_color);
                        msg_debug_pool ("got color: %xd", bl->font_color.d.val);
                }
+               else if (comp->type == RSPAMD_HTML_COMPONENT_BGCOLOR && comp->len > 0) {
+                       fstr.begin = (gchar *)comp->start;
+                       fstr.len = comp->len;
+                       rspamd_html_process_color (comp->start, comp->len, &bl->background_color);
+                       msg_debug_pool ("got color: %xd", bl->font_color.d.val);
+
+                       if (tag->id == Tag_BODY) {
+                               /* Set global background color */
+                               memcpy (&hc->bgcolor, &bl->background_color, sizeof (hc->bgcolor));
+                       }
+               }
                else if (comp->type == RSPAMD_HTML_COMPONENT_STYLE && comp->len > 0) {
                        bl->style.len = comp->len;
                        bl->style.start =  comp->start;
@@ -1666,6 +1682,12 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
 
        hc->tags_seen = rspamd_mempool_alloc0 (pool, NBYTES (G_N_ELEMENTS (tag_defs)));
 
+       /* Set white background color by default */
+       hc->bgcolor.d.comp.alpha = 0;
+       hc->bgcolor.d.comp.r = 255;
+       hc->bgcolor.d.comp.g = 255;
+       hc->bgcolor.d.comp.b = 255;
+
        dest = g_byte_array_sized_new (in->len / 3 * 2);
 
        p = in->data;
index 35af8f05cc90370f258b2ff10b436367ce596119..218594191269d6df5aae831b725553e097da6de8 100644 (file)
@@ -28,6 +28,7 @@ enum html_component_type {
        RSPAMD_HTML_COMPONENT_NAME = 0,
        RSPAMD_HTML_COMPONENT_HREF,
        RSPAMD_HTML_COMPONENT_COLOR,
+       RSPAMD_HTML_COMPONENT_BGCOLOR,
        RSPAMD_HTML_COMPONENT_STYLE,
        RSPAMD_HTML_COMPONENT_CLASS,
        RSPAMD_HTML_COMPONENT_WIDTH,
@@ -105,6 +106,7 @@ struct rspamd_task;
 struct html_content {
        GNode *html_tags;
        gint flags;
+       struct html_color bgcolor;
        guchar *tags_seen;
        GPtrArray *images;
        GPtrArray *blocks;
index 5e9b8df2b611702ee89e5964ebc39864b513a7fa..fe5a409d7a0eb6b106d03a767a17de694ff79ca3 100644 (file)
@@ -346,7 +346,7 @@ lua_html_get_blocks (lua_State *L)
                                        lua_settable (L, -3);
                                }
                                if (bl->background_color.valid) {
-                                       lua_pushstring (L, "color");
+                                       lua_pushstring (L, "bgcolor");
                                        lua_newtable (L);
                                        lua_pushnumber (L, bl->background_color.d.comp.r);
                                        lua_rawseti (L, -2, 1);