diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-23 13:40:43 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-23 13:40:43 +0100 |
commit | 6667595b57b5b1383f568b06c410d135d831b983 (patch) | |
tree | 2bb7b7e5c7878d8a81ad55a2c7ff1b7aa2101e5e | |
parent | c5580a4ac9b8eeb44b80c0fbed78f5ecb541687e (diff) | |
download | rspamd-6667595b57b5b1383f568b06c410d135d831b983.tar.gz rspamd-6667595b57b5b1383f568b06c410d135d831b983.zip |
Find linked images from HTML parts.
-rw-r--r-- | src/libmime/images.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/libmime/images.c b/src/libmime/images.c index 682a3f7f6..d60ecf2a0 100644 --- a/src/libmime/images.c +++ b/src/libmime/images.c @@ -25,6 +25,7 @@ #include "images.h" #include "main.h" #include "message.h" +#include "html.h" static const guint8 png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; static const guint8 jpg_sig1[] = {0xff, 0xd8}; @@ -199,8 +200,14 @@ process_bmp_image (struct rspamd_task *task, GByteArray *data) static void process_image (struct rspamd_task *task, struct mime_part *part) { - enum known_image_types type; + enum rspamd_image_type type; struct rspamd_image *img = NULL; + struct raw_header *rh; + struct mime_text_part *tp; + struct html_image *himg; + const gchar *cid, *html_cid; + guint cid_len, i, j; + if ((type = detect_image_type (part->content)) != IMAGE_TYPE_UNKNOWN) { switch (type) { case IMAGE_TYPE_PNG: @@ -228,6 +235,53 @@ process_image (struct rspamd_task *task, struct mime_part *part) task->message_id); img->filename = part->filename; task->images = g_list_prepend (task->images, img); + + /* Check Content-Id */ + rh = g_hash_table_lookup (part->raw_headers, "Content-Id"); + + if (rh != NULL) { + cid = rh->decoded; + if (*cid == '<') { + cid ++; + } + cid_len = strlen (cid); + + if (cid_len > 0) { + if (cid[cid_len - 1] == '>') { + cid_len --; + } + + for (i = 0; i < task->text_parts->len; i ++) { + tp = g_ptr_array_index (task->text_parts, i); + + if (IS_PART_HTML (tp) && tp->html != 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) { + html_cid = himg->src; + + if (strncmp (html_cid, "cid:", 4) == 0) { + html_cid += 4; + } + + if (strlen (html_cid) == cid_len && + memcmp (html_cid, cid, cid_len) == 0) { + img->html_image = himg; + + debug_task ("found linked image by cid: <%s>", + cid); + } + } + } + } + } + + } + + } } } |