From a36ee5a03288e9fabf82778a4a1a197bf0e69327 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 9 Apr 2016 13:13:38 +0100 Subject: [PATCH] [Feature] Allow to get mime headers from a task --- src/libmime/message.c | 49 +++++++++++++++++++++++++++++++++++++++++++ src/libmime/message.h | 4 ++++ 2 files changed, 53 insertions(+) diff --git a/src/libmime/message.c b/src/libmime/message.c index f14c3b185..a7a3f7439 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1985,8 +1985,57 @@ rspamd_message_get_header_array (struct rspamd_task *task, ret = g_ptr_array_sized_new (nelems); LL_FOREACH (rh, cur) { + if (strong) { + if (strcmp (rh->name, field) != 0) { + continue; + } + } + g_ptr_array_add (ret, cur); } return ret; } + +GPtrArray * +rspamd_message_get_mime_header_array (struct rspamd_task *task, + const gchar *field, + gboolean strong) +{ + GPtrArray *ret; + struct raw_header *rh, *cur; + guint nelems = 0, i; + struct mime_part *mp; + + for (i = 0; i < task->parts->len; i ++) { + mp = g_ptr_array_index (task->parts, i); + rh = g_hash_table_lookup (mp->raw_headers, field); + + if (rh == NULL) { + continue; + } + + LL_FOREACH (rh, cur) { + nelems ++; + } + } + + ret = g_ptr_array_sized_new (nelems); + + for (i = 0; i < task->parts->len; i ++) { + mp = g_ptr_array_index (task->parts, i); + rh = g_hash_table_lookup (mp->raw_headers, field); + + LL_FOREACH (rh, cur) { + if (strong) { + if (strcmp (rh->name, field) != 0) { + continue; + } + } + + g_ptr_array_add (ret, cur); + } + } + + return ret; +} diff --git a/src/libmime/message.h b/src/libmime/message.h index 06ff78e7a..d946fa0a4 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -91,4 +91,8 @@ GPtrArray *rspamd_message_get_header_array (struct rspamd_task *task, const gchar *field, gboolean strong); +GPtrArray *rspamd_message_get_mime_header_array (struct rspamd_task *task, + const gchar *field, + gboolean strong); + #endif -- 2.39.5