From: Vsevolod Stakhov Date: Fri, 5 Aug 2016 13:15:51 +0000 (+0100) Subject: [Fix] Fix parsing of background color X-Git-Tag: 1.3.2~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d7acbc3402f81c0e97e6b1ba67fc3c031b660f0d;p=rspamd.git [Fix] Fix parsing of background color --- diff --git a/src/libserver/html.c b/src/libserver/html.c index d39816f87..e20fbadce 100644 --- a/src/libserver/html.c +++ b/src/libserver/html.c @@ -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; diff --git a/src/libserver/html.h b/src/libserver/html.h index 35af8f05c..218594191 100644 --- a/src/libserver/html.h +++ b/src/libserver/html.h @@ -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; diff --git a/src/lua/lua_html.c b/src/lua/lua_html.c index 5e9b8df2b..fe5a409d7 100644 --- a/src/lua/lua_html.c +++ b/src/lua/lua_html.c @@ -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);