diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-13 11:22:44 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-13 11:23:12 +0100 |
commit | ebe5dfa9bbd8f2a6241fefe3daa99eb654da6336 (patch) | |
tree | dc0b24a6039341272671fc5ee53ca00f88cba802 /src/libmime | |
parent | a7b2ee81dfc78d0f9b17e93a3ed9ce9fbe220eba (diff) | |
download | rspamd-ebe5dfa9bbd8f2a6241fefe3daa99eb654da6336.tar.gz rspamd-ebe5dfa9bbd8f2a6241fefe3daa99eb654da6336.zip |
[Feature] Pre-calculate blake2 digest for all parts
Diffstat (limited to 'src/libmime')
-rw-r--r-- | src/libmime/images.c | 1 | ||||
-rw-r--r-- | src/libmime/images.h | 8 | ||||
-rw-r--r-- | src/libmime/message.c | 22 | ||||
-rw-r--r-- | src/libmime/message.h | 5 |
4 files changed, 31 insertions, 5 deletions
diff --git a/src/libmime/images.c b/src/libmime/images.c index 5a556ce9c..f2c27f865 100644 --- a/src/libmime/images.c +++ b/src/libmime/images.c @@ -226,6 +226,7 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part) img->width, img->height, task->message_id); img->filename = part->filename; + img->parent = part; part->flags |= RSPAMD_MIME_PART_IMAGE; part->specific_data = img; diff --git a/src/libmime/images.h b/src/libmime/images.h index aa63d92e2..73e00aebd 100644 --- a/src/libmime/images.h +++ b/src/libmime/images.h @@ -5,6 +5,7 @@ struct html_image; struct rspamd_task; +struct rspamd_mime_part; enum rspamd_image_type { IMAGE_TYPE_PNG = 0, @@ -15,12 +16,13 @@ enum rspamd_image_type { }; struct rspamd_image { - enum rspamd_image_type type; + struct rspamd_mime_part *parent; GByteArray *data; - guint32 width; - guint32 height; const gchar *filename; struct html_image *html_image; + enum rspamd_image_type type; + guint32 width; + guint32 height; }; /* diff --git a/src/libmime/message.c b/src/libmime/message.c index a3b673f28..f97de592f 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1061,6 +1061,17 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) GMimeStream *part_stream; GByteArray *part_content; gchar *hdrs; + /* Blake2b applied to string 'rspamd' */ + static const guchar hash_key[] = { + 0x78,0x6a,0x02,0xf7,0x42,0x01,0x59,0x03, + 0xc6,0xc6,0xfd,0x85,0x25,0x52,0xd2,0x72, + 0x91,0x2f,0x47,0x40,0xe1,0x58,0x47,0x61, + 0x8a,0x86,0xe2,0x17,0xf7,0x1f,0x54,0x19, + 0xd2,0x5e,0x10,0x31,0xaf,0xee,0x58,0x53, + 0x13,0x89,0x64,0x44,0x93,0x4e,0xb0,0x4b, + 0x90,0x3a,0x68,0x5b,0x14,0x48,0xb7,0x55, + 0xd5,0x6f,0x70,0x1a,0xfe,0x9b,0xe2,0xce + }; task = md->task; /* 'part' points to the current part node that g_mime_message_foreach_part() is iterating over */ @@ -1139,6 +1150,11 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) mime_part->mime = part; mime_part->boundary = g_mime_multipart_get_boundary (GMIME_MULTIPART (part)); + if (mime_part->boundary) { + rspamd_cryptobox_hash (mime_part->digest, mime_part->boundary, + strlen (mime_part->boundary), hash_key, sizeof (hash_key)); + } + debug_task ("found part with content-type: %s/%s", type->type, type->subtype); @@ -1203,6 +1219,12 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) part)); mime_part->mime = part; + if (mime_part->content->len > 0) { + rspamd_cryptobox_hash (mime_part->digest, + mime_part->content->data, mime_part->content->len, + hash_key, sizeof (hash_key)); + } + debug_task ("found part with content-type: %s/%s", type->type, type->subtype); diff --git a/src/libmime/message.h b/src/libmime/message.h index 3fe26e685..b6f7062dc 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -9,6 +9,7 @@ #include "config.h" #include "email_addr.h" #include "addr.h" +#include "cryptobox.h" #include <gmime/gmime.h> struct rspamd_task; @@ -29,11 +30,11 @@ struct rspamd_mime_part { GMimeObject *mime; GHashTable *raw_headers; gchar *raw_headers_str; - gchar *checksum; + guchar digest[rspamd_cryptobox_HASHBYTES]; const gchar *filename; const gchar *boundary; - enum rspamd_mime_part_flags flags; gpointer specific_data; + enum rspamd_mime_part_flags flags; }; #define RSPAMD_MIME_TEXT_PART_FLAG_UTF (1 << 0) |