From e33ea5e4782b4a6e3f706634d85058d1a4f42d6b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 15 Aug 2016 18:32:42 +0100 Subject: [PATCH] [Feature] Store task checksum --- src/libmime/message.c | 29 +++++++++++++++++++++++++---- src/libserver/task.h | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index 09176cfe30..1f63568813 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1375,6 +1375,8 @@ rspamd_message_parse (struct rspamd_task *task) gint i; gdouble diff, *pdiff; guint tw, *ptw, dw; + rspamd_cryptobox_hash_state_t st; + guchar digest_out[rspamd_cryptobox_HASHBYTES]; if (RSPAMD_TASK_IS_EMPTY (task)) { /* Don't do anything with empty task */ @@ -1430,6 +1432,7 @@ rspamd_message_parse (struct rspamd_task *task) * pool allocator */ g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE); + rspamd_cryptobox_hash_init (&st, NULL, 0); if (task->flags & RSPAMD_TASK_FLAG_MIME) { @@ -1474,6 +1477,10 @@ rspamd_message_parse (struct rspamd_task *task) task->raw_headers_content.len = hdr_pos; task->raw_headers_content.body_start = p + body_pos; + rspamd_cryptobox_hash_update (&st, + task->raw_headers_content.begin, + task->raw_headers_content.len); + if (task->raw_headers_content.len > 0) { process_raw_headers (task, task->raw_headers, task->raw_headers_content.begin, @@ -1718,13 +1725,27 @@ rspamd_message_parse (struct rspamd_task *task) "them with each other"); } + for (i = 0; i < task->parts->len; i ++) { + struct rspamd_mime_part *part; + + part = g_ptr_array_index (task->parts, i); + rspamd_cryptobox_hash_update (&st, part->digest, sizeof (part->digest)); + } + + rspamd_cryptobox_hash_final (&st, digest_out); + memcpy (task->digest, digest_out, sizeof (task->digest)); + if (task->queue_id) { - msg_info_task ("loaded message; id: <%s>; queue-id: <%s>; size: %z", - task->message_id, task->queue_id, task->msg.len); + msg_info_task ("loaded message; id: <%s>; queue-id: <%s>; size: %z; " + "checksum: <%*xs>", + task->message_id, task->queue_id, task->msg.len, + (gint)sizeof (task->digest), task->digest); } else { - msg_info_task ("loaded message; id: <%s>; size: %z", - task->message_id, task->msg.len); + msg_info_task ("loaded message; id: <%s>; size: %z; " + "checksum: <%*xs>", + task->message_id, task->msg.len, + (gint)sizeof (task->digest), task->digest); } return TRUE; diff --git a/src/libserver/task.h b/src/libserver/task.h index c76dd614e4..f436c8275b 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -188,6 +188,7 @@ struct rspamd_task { ucl_object_t *settings; /**< Settings applied to task */ const gchar *classifier; /**< Classifier to learn (if needed) */ + guchar digest[16]; }; /** -- 2.47.3