From: Vsevolod Stakhov Date: Thu, 19 Sep 2019 11:07:03 +0000 (+0100) Subject: [Fix] Fix embedded images linking logic X-Git-Tag: 2.0~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90fb3cc2868a3ee4d5995aefb71fb6d66b450edf;p=rspamd.git [Fix] Fix embedded images linking logic --- diff --git a/rules/html.lua b/rules/html.lua index fb32e9179..9e582a731 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -101,7 +101,6 @@ rspamd_config.R_EMPTY_IMAGE = { if p:is_html() then -- if the current part is html part local hc = p:get_html() -- we get HTML context local len = p:get_length() -- and part's length - if hc and len < 50 then -- if we have a part that has less than 50 bytes of text local images = hc:get_images() -- then we check for HTML images diff --git a/src/libmime/images.c b/src/libmime/images.c index cb59bc88e..073776359 100644 --- a/src/libmime/images.c +++ b/src/libmime/images.c @@ -596,14 +596,8 @@ rspamd_maybe_process_image (rspamd_mempool_t *pool, static void process_image (struct rspamd_task *task, struct rspamd_mime_part *part) { - struct rspamd_mime_header *rh; - struct rspamd_mime_text_part *tp; - struct html_image *himg; - const gchar *cid, *html_cid; - guint cid_len, i, j; struct rspamd_image *img; - img = rspamd_maybe_process_image (task->task_pool, &part->parsed_data); if (img != NULL) { @@ -619,7 +613,45 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) part->flags |= RSPAMD_MIME_PART_IMAGE; part->specific.img = img; + } +} + +const gchar * +rspamd_image_type_str (enum rspamd_image_type type) +{ + switch (type) { + case IMAGE_TYPE_PNG: + return "PNG"; + break; + case IMAGE_TYPE_JPG: + return "JPEG"; + break; + case IMAGE_TYPE_GIF: + return "GIF"; + break; + case IMAGE_TYPE_BMP: + return "BMP"; + break; + default: + break; + } + return "unknown"; +} + +static void +rspamd_image_process_part (struct rspamd_task *task, struct rspamd_mime_part *part) +{ + struct rspamd_mime_header *rh; + struct rspamd_mime_text_part *tp; + struct html_image *himg; + const gchar *cid, *html_cid; + guint cid_len, i, j; + struct rspamd_image *img; + + img = (struct rspamd_image *)part->specific.img; + + if (img) { /* Check Content-Id */ rh = rspamd_message_get_header_from_hash (part->raw_headers, "Content-Id"); @@ -638,15 +670,14 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) cid_len --; } - PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, text_parts), i, tp) { if (IS_PART_HTML (tp) && tp->html != NULL && - tp->html->images != NULL) { + tp->html->images != NULL) { for (j = 0; j < tp->html->images->len; j ++) { himg = g_ptr_array_index (tp->html->images, j); if ((himg->flags & RSPAMD_HTML_FLAG_IMAGE_EMBEDDED) && - himg->src) { + himg->src) { html_cid = himg->src; if (strncmp (html_cid, "cid:", 4) == 0) { @@ -654,7 +685,7 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) } if (strlen (html_cid) == cid_len && - memcmp (html_cid, cid, cid_len) == 0) { + memcmp (html_cid, cid, cid_len) == 0) { img->html_image = himg; himg->embedded_image = img; @@ -664,6 +695,7 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) if (himg->height == 0) { himg->height = img->height; } + if (himg->width == 0) { himg->width = img->width; } @@ -672,32 +704,20 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) } } } - } - } } } -const gchar * -rspamd_image_type_str (enum rspamd_image_type type) +void +rspamd_images_link (struct rspamd_task *task) { - switch (type) { - case IMAGE_TYPE_PNG: - return "PNG"; - break; - case IMAGE_TYPE_JPG: - return "JPEG"; - break; - case IMAGE_TYPE_GIF: - return "GIF"; - break; - case IMAGE_TYPE_BMP: - return "BMP"; - break; - default: - break; - } + struct rspamd_mime_part *part; + guint i; - return "unknown"; -} + PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) { + if (part->flags & RSPAMD_MIME_PART_IMAGE) { + rspamd_image_process_part (task, part); + } + } +} \ No newline at end of file diff --git a/src/libmime/images.h b/src/libmime/images.h index bf1175b2a..964a1b35a 100644 --- a/src/libmime/images.h +++ b/src/libmime/images.h @@ -39,6 +39,11 @@ struct rspamd_image { */ void rspamd_images_process (struct rspamd_task *task); +/* + * Link embedded images to the HTML parts + */ +void rspamd_images_link (struct rspamd_task *task); + /** * Processes image in raw data * @param task diff --git a/src/libmime/message.c b/src/libmime/message.c index 0f260d726..cb95945fe 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1570,6 +1570,7 @@ rspamd_message_process (struct rspamd_task *task) } } + rspamd_images_link (task); rspamd_tokenize_meta_words (task); }