From 1ce182c9bb3c7fd436ac5b982905d0e3616cd7a8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 29 Mar 2016 16:53:30 +0100 Subject: [PATCH] [Feature] Add method to get headers as array for speed --- src/libmime/message.c | 28 ++++++++++++++++++++++++++++ src/libmime/message.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/src/libmime/message.c b/src/libmime/message.c index 9c50750d9..f14c3b185 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1962,3 +1962,31 @@ rspamd_message_get_header (struct rspamd_task *task, return gret; } + +GPtrArray * +rspamd_message_get_header_array (struct rspamd_task *task, + const gchar *field, + gboolean strong) +{ + GPtrArray *ret; + struct raw_header *rh, *cur; + guint nelems = 0; + + rh = g_hash_table_lookup (task->raw_headers, field); + + if (rh == NULL) { + return NULL; + } + + LL_FOREACH (rh, cur) { + nelems ++; + } + + ret = g_ptr_array_sized_new (nelems); + + LL_FOREACH (rh, cur) { + g_ptr_array_add (ret, cur); + } + + return ret; +} diff --git a/src/libmime/message.h b/src/libmime/message.h index 13ccaa4fa..06ff78e7a 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -87,4 +87,8 @@ GList * rspamd_message_get_header (struct rspamd_task *task, const gchar *field, gboolean strong); +GPtrArray *rspamd_message_get_header_array (struct rspamd_task *task, + const gchar *field, + gboolean strong); + #endif -- 2.39.5