]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow to pass extradata from rspamd to rmilter
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jul 2016 16:38:59 +0000 (17:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jul 2016 16:40:07 +0000 (17:40 +0100)
src/libserver/protocol.c
src/lua/lua_task.c

index de1e085926c72f9d301d60e43ea3e45d2e8fa8c9..e7192dff278ac017f13b1219de34a956b7381e3b 100644 (file)
@@ -984,6 +984,7 @@ rspamd_protocol_write_ucl (struct rspamd_task *task)
        ucl_object_t *top = NULL, *obj;
        GHashTableIter hiter;
        GString *dkim_sig;
+       const ucl_object_t *rmilter_reply;
        gpointer h, v;
 
        g_hash_table_iter_init (&hiter, task->results);
@@ -1021,6 +1022,13 @@ rspamd_protocol_write_ucl (struct rspamd_task *task)
                                        "dkim-signature", 0, false);
        }
 
+       rmilter_reply = rspamd_mempool_get_variable (task->task_pool, "rmilter-reply");
+
+       if (rmilter_reply) {
+               ucl_object_insert_key (top, ucl_object_ref (rmilter_reply),
+                               "rmilter", 0, false);
+       }
+
        return top;
 }
 
index d18eaa4eadcf17dfd5f300d93d100cda25360e87..e11c3e5c181a1ef7ff3d6a244e037d1985c22bfe 100644 (file)
@@ -534,10 +534,22 @@ LUA_FUNCTION_DEF (task, get_settings);
 /***
  * @method task:get_settings_id()
  * Get numeric hash of settings id if specified for this task. 0 is returned otherwise.
- * @param {any} obj any lua object that corresponds to the settings format
+ * @return {number} settings-id hash
  */
 LUA_FUNCTION_DEF (task, get_settings_id);
 
+/***
+ * @method task:set_rmilter_reply(obj)
+ * Set special reply for rmilter
+ * @param {any} obj any lua object that corresponds to the settings format
+ * @example
+task:set_rmilter_reply({
+       add_headers = {{'X-Lua', 'test'}},
+       remove_headers = {'DKIM-Signature},
+})
+ */
+LUA_FUNCTION_DEF (task, set_rmilter_reply);
+
 /***
  * @method task:process_re(params)
  * Processes the specified regexp and returns number of captures (cached or new)
@@ -716,6 +728,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, set_flag),
        LUA_INTERFACE_DEF (task, get_flags),
        LUA_INTERFACE_DEF (task, has_flag),
+       LUA_INTERFACE_DEF (task, set_rmilter_reply),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
 };
@@ -2842,6 +2855,25 @@ lua_task_set_settings (lua_State *L)
        return 0;
 }
 
+static gint
+lua_task_set_rmilter_reply (lua_State *L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+       ucl_object_t *reply;
+
+       reply = ucl_object_lua_import (L, 2);
+
+       if (reply != NULL && task != NULL) {
+               rspamd_mempool_set_variable (task->task_pool, "rmilter-reply",
+                               reply, (rspamd_mempool_destruct_t)ucl_object_unref);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 0;
+}
+
 static gint
 lua_task_get_settings (lua_State *L)
 {