]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow to get mime headers from a task
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 9 Apr 2016 12:13:38 +0000 (13:13 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 9 Apr 2016 12:13:38 +0000 (13:13 +0100)
src/libmime/message.c
src/libmime/message.h

index f14c3b1857d72db6cc1d3a6f7bca352d2aa04a40..a7a3f743915c2d88017ab4e95de54d7fbfd6f554 100644 (file)
@@ -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;
+}
index 06ff78e7af4491841c736dd912cbe0c708ef6866..d946fa0a49b6f6c52a411e0c671767ff76c952bb 100644 (file)
@@ -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