]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Store task checksum
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Aug 2016 17:32:42 +0000 (18:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Aug 2016 17:32:42 +0000 (18:32 +0100)
src/libmime/message.c
src/libserver/task.h

index 09176cfe304eed7e0268b7a48463f88561589f39..1f6356881302008850418a645c960ea725688552 100644 (file)
@@ -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;
index c76dd614e4bc9baac111659b6f1146a2fb5877e9..f436c8275bd3cbda2d9ad970fd8489cce833625c 100644 (file)
@@ -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];
 };
 
 /**