]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Store hash of headers order and names
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 May 2017 12:05:59 +0000 (13:05 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 May 2017 12:05:59 +0000 (13:05 +0100)
src/libmime/mime_headers.c

index e44b14eaa1e492962c61c523dc82389cec276fa0..b4203f0d47c656df578366b52ba82523717d36d8 100644 (file)
@@ -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);
        }
 }