]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Propagate colors in HTML
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 13:35:53 +0000 (14:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 15:06:22 +0000 (16:06 +0100)
src/libserver/html.c

index e20fbadcef946f059e3b877a59c950223d6d9370..ce388cf4921c02fa773c2c1fa5f13f49927163f8 100644 (file)
@@ -1572,9 +1572,11 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag,
                struct html_content *hc)
 {
        struct html_tag_component *comp;
-       struct html_block *bl;
+       struct html_block *bl, *bl_parent;
        rspamd_ftok_t fstr;
        GList *cur;
+       GNode *parent;
+       struct html_tag *parent_tag;
 
        cur = tag->params->head;
        bl = rspamd_mempool_alloc0 (pool, sizeof (*bl));
@@ -1616,6 +1618,37 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag,
                cur = g_list_next (cur);
        }
 
+       if (!bl->background_color.valid) {
+               /* Try to propagate background color from parent nodes */
+               for (parent = tag->parent; parent != NULL; parent = parent->parent) {
+                       parent_tag = parent->data;
+
+                       if (parent && (parent_tag->flags & FL_BLOCK) && parent_tag->extra) {
+                               bl_parent = parent_tag->extra;
+
+                               if (bl_parent->background_color.valid) {
+                                       memcpy (&bl->background_color, &bl_parent->background_color,
+                                                       sizeof (bl->background_color));
+                               }
+                       }
+               }
+       }
+       if (!bl->font_color.valid) {
+               /* Try to propagate background color from parent nodes */
+               for (parent = tag->parent; parent != NULL; parent = parent->parent) {
+                       parent_tag = parent->data;
+
+                       if (parent && (parent_tag->flags & FL_BLOCK) && parent_tag->extra) {
+                               bl_parent = parent_tag->extra;
+
+                               if (bl_parent->font_color.valid) {
+                                       memcpy (&bl->font_color, &bl_parent->font_color,
+                                                       sizeof (bl->font_color));
+                               }
+                       }
+               }
+       }
+
        if (hc->blocks == NULL) {
                hc->blocks = g_ptr_array_sized_new (64);
                rspamd_mempool_add_destructor (pool, rspamd_ptr_array_free_hard,
@@ -1687,6 +1720,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
        hc->bgcolor.d.comp.r = 255;
        hc->bgcolor.d.comp.g = 255;
        hc->bgcolor.d.comp.b = 255;
+       hc->bgcolor.valid = TRUE;
 
        dest = g_byte_array_sized_new (in->len / 3 * 2);