aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-22 14:46:05 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-22 14:46:05 +0100
commit5313f6745d4958c014985685f44ca8594788d316 (patch)
tree899753e70437fce4ea9a90a2c48b931b6eb491d8 /src/libmime
parente99bbb8a9c8ef48c8c2bdeff11d557d015581653 (diff)
downloadrspamd-5313f6745d4958c014985685f44ca8594788d316.tar.gz
rspamd-5313f6745d4958c014985685f44ca8594788d316.zip
[Feature] Add more methods to get headers from a task
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/message.c145
-rw-r--r--src/libmime/message.h26
2 files changed, 171 insertions, 0 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index fb916abfe..a234e43be 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -2017,3 +2017,148 @@ rspamd_message_get_mime_header_array (struct rspamd_task *task,
return ret;
}
+
+GPtrArray *
+rspamd_message_get_headers_array (struct rspamd_task *task, ...)
+{
+ va_list ap;
+ GPtrArray *ret;
+ struct raw_header *rh, *cur;
+ guint nelems = 0;
+ const gchar *hname;
+
+ va_start (ap, task);
+
+ for (hname = va_arg (ap, const char *); hname != NULL;) {
+ rh = g_hash_table_lookup (task->raw_headers, hname);
+
+ if (rh == NULL) {
+ continue;
+ }
+ LL_FOREACH (rh, cur) {
+ nelems ++;
+ }
+ }
+
+ va_end (ap);
+
+ if (nelems == 0) {
+ return NULL;
+ }
+
+ ret = g_ptr_array_sized_new (nelems);
+
+ /* Restart varargs processing */
+ va_start (ap, task);
+
+ for (hname = va_arg (ap, const char *); hname != NULL;) {
+ rh = g_hash_table_lookup (task->raw_headers, hname);
+
+ if (rh == NULL) {
+ continue;
+ }
+ LL_FOREACH (rh, cur) {
+ g_ptr_array_add (ret, cur);
+ }
+ }
+
+ va_end (ap);
+
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ret);
+
+ return ret;
+}
+
+GPtrArray *
+rspamd_message_get_header_array_str (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) {
+ if (strong) {
+ if (strcmp (rh->name, field) != 0) {
+ continue;
+ }
+ }
+
+ if (cur->decoded) {
+ g_ptr_array_add (ret, cur->decoded);
+ }
+ }
+
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ret);
+
+ return ret;
+}
+
+GPtrArray *
+rspamd_message_get_headers_array_str (struct rspamd_task *task, ...)
+{
+ va_list ap;
+ GPtrArray *ret;
+ struct raw_header *rh, *cur;
+ guint nelems = 0;
+ const gchar *hname;
+
+ va_start (ap, task);
+
+ for (hname = va_arg (ap, const char *); hname != NULL;) {
+ rh = g_hash_table_lookup (task->raw_headers, hname);
+
+ if (rh == NULL) {
+ continue;
+ }
+ LL_FOREACH (rh, cur) {
+ nelems ++;
+ }
+ }
+
+ va_end (ap);
+
+ if (nelems == 0) {
+ return NULL;
+ }
+
+ ret = g_ptr_array_sized_new (nelems);
+
+ /* Restart varargs processing */
+ va_start (ap, task);
+
+ for (hname = va_arg (ap, const char *); hname != NULL;) {
+ rh = g_hash_table_lookup (task->raw_headers, hname);
+
+ if (rh == NULL) {
+ continue;
+ }
+ LL_FOREACH (rh, cur) {
+ if (cur->decoded) {
+ g_ptr_array_add (ret, cur->decoded);
+ }
+ }
+ }
+
+ va_end (ap);
+
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ret);
+
+ return ret;
+}
diff --git a/src/libmime/message.h b/src/libmime/message.h
index 4f8f27b0b..2f7539825 100644
--- a/src/libmime/message.h
+++ b/src/libmime/message.h
@@ -110,5 +110,31 @@ GPtrArray *rspamd_message_get_mime_header_array (struct rspamd_task *task,
const gchar *field,
gboolean strong);
+/**
+ * Get array of all headers from the list specified
+ * @param task
+ * @param h1
+ * @return An array of headers (should not be freed as well)
+ */
+GPtrArray *rspamd_message_get_headers_array (struct rspamd_task *task, ...);
+
+/**
+ * Get an array of header's values with specified header's name returning decoded strings as values
+ * @param task worker task structure
+ * @param field header's name
+ * @param strong if this flag is TRUE header's name is case sensitive, otherwise it is not
+ * @return An array of header's values or NULL. It is NOT permitted to free array or values.
+ */
+GPtrArray *rspamd_message_get_header_array_str (struct rspamd_task *task,
+ const gchar *field,
+ gboolean strong);
+
+/**
+ * Get array of all headers from the list specified returning decoded strings as values
+ * @param task
+ * @param h1
+ * @return An array of headers (should not be freed as well)
+ */
+GPtrArray *rspamd_message_get_headers_array_str (struct rspamd_task *task, ...);
#endif