From: Vsevolod Stakhov Date: Thu, 11 May 2017 12:05:59 +0000 (+0100) Subject: [Feature] Store hash of headers order and names X-Git-Tag: 1.6.0~236 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a43df55fa537d37c93d151b0c17578eefd83eb84;p=rspamd.git [Feature] Store hash of headers order and names --- diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index e44b14eaa..b4203f0d4 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -413,6 +413,9 @@ rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target, if (check_newlines) { guint max_cnt = 0; gint sel = 0; + GList *cur; + rspamd_cryptobox_hash_state_t hs; + guchar hout[rspamd_cryptobox_HASHBYTES], *hexout; for (gint i = 0; i < RSPAMD_TASK_NEWLINES_MAX; i ++) { if (nlines_count[i] > max_cnt) { @@ -422,6 +425,27 @@ rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target, } task->nlines_type = sel; + + cur = order->head; + rspamd_cryptobox_hash_init (&hs, NULL, 0); + + while (cur) { + nh = cur->data; + + if (nh->name) { + rspamd_cryptobox_hash_update (&hs, nh->name, strlen (nh->name)); + } + + cur = g_list_next (cur); + } + + rspamd_cryptobox_hash_final (&hs, hout); + hexout = rspamd_mempool_alloc (task->task_pool, sizeof (hout) * 2 + 1); + hexout[sizeof (hout) * 2] = '\0'; + rspamd_encode_hex_buf (hout, sizeof (hout), hexout, + sizeof (hout) * 2 + 1); + rspamd_mempool_set_variable (task->task_pool, "headers_hash", + hexout, NULL); } }