From: Vsevolod Stakhov Date: Sat, 23 Sep 2017 13:51:07 +0000 (+0100) Subject: [Feature] Allow to insert headers into specific position X-Git-Tag: 1.6.6~3^2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90104eed49a76a75189ce3cd6656bf84902ba102;p=rspamd.git [Feature] Allow to insert headers into specific position --- diff --git a/src/libserver/milter.c b/src/libserver/milter.c index 49f953f41..2e4090c02 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -1461,6 +1461,7 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session, const ucl_object_t *elt, *cur, *cur_elt; ucl_object_iter_t it; GString *hname, *hvalue; + gint idx = -1; if (obj && ucl_object_type (obj) == UCL_OBJECT) { elt = ucl_object_lookup (obj, "remove_headers"); @@ -1484,6 +1485,8 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session, /* * add_headers: {"name": "value", ... } * name could have multiple values + * -or- (since 1.7) + * {"name": {"value": "val", "order": 0}, ... } */ if (elt && ucl_object_type (elt) == UCL_OBJECT) { it = NULL; @@ -1500,6 +1503,39 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session, g_string_free (hname, TRUE); g_string_free (hvalue, TRUE); } + else if (ucl_object_type (cur_elt) == UCL_OBJECT) { + const ucl_object_t *val; + + val = ucl_object_lookup (cur_elt, "value"); + + if (val && ucl_object_type (val) == UCL_STRING) { + const ucl_object_t *idx_obj; + + idx_obj = ucl_object_lookup_any (cur_elt, "order", + "index", NULL); + if (idx_obj) { + idx = ucl_object_toint (idx_obj); + } + + hname = g_string_new (ucl_object_key (cur)); + hvalue = g_string_new (ucl_object_tostring (val)); + + if (idx >= 0) { + rspamd_milter_send_action (session, + RSPAMD_MILTER_INSHEADER, + idx, + hname, hvalue); + } + else { + rspamd_milter_send_action (session, + RSPAMD_MILTER_ADDHEADER, + hname, hvalue); + } + + g_string_free (hname, TRUE); + g_string_free (hvalue, TRUE); + } + } } } } @@ -1607,8 +1643,8 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, hname = g_string_new (RSPAMD_MILTER_DKIM_HEADER); hvalue = g_string_new (ucl_object_tostring (elt)); - rspamd_milter_send_action (session, RSPAMD_MILTER_ADDHEADER, - hname, hvalue); + rspamd_milter_send_action (session, RSPAMD_MILTER_INSHEADER, + 0, hname, hvalue); g_string_free (hname, TRUE); g_string_free (hvalue, TRUE); }