struct rspamd_dns_resolver *lua_check_dns_resolver (lua_State *L, gint pos);
+struct rspamd_lua_url *lua_check_url (lua_State * L, gint pos);
+
enum rspamd_lua_parse_arguments_flags {
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0,
RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING,
* @return {boolean} true if a task has urls (urls or emails if `need_emails` is true)
*/
LUA_FUNCTION_DEF (task, has_urls);
+/***
+ * @method task:inject_url(url)
+ * Inserts an url into a task (useful for redirected urls)
+ * @param {lua_url} url url to inject
+ */
+LUA_FUNCTION_DEF (task, inject_url);
/***
* @method task:get_content()
* Get raw content for the specified task
LUA_INTERFACE_DEF (task, append_message),
LUA_INTERFACE_DEF (task, has_urls),
LUA_INTERFACE_DEF (task, get_urls),
+ LUA_INTERFACE_DEF (task, inject_url),
LUA_INTERFACE_DEF (task, get_content),
LUA_INTERFACE_DEF (task, get_filename),
LUA_INTERFACE_DEF (task, get_rawbody),
return 1;
}
+static gint
+lua_task_inject_url (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ struct rspamd_lua_url *url = lua_check_url (L, 2);
+
+ if (task && task->message && url && url->url) {
+ struct rspamd_url *existing;
+
+ if ((existing = g_hash_table_lookup (MESSAGE_FIELD (task, urls),
+ url->url)) == NULL) {
+ g_hash_table_insert (MESSAGE_FIELD (task, urls), url->url, url->url);
+ }
+ else {
+ existing->count ++;
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 0;
+}
+
static gint
lua_task_get_content (lua_State * L)
{
local pre_filter = rule['prefilter']
local function match_element(r, value, callback)
- lua_util.debugm(N, task, 'check value %s for multimap %s', value,
- rule.symbol)
if not value then
return false
end
+ lua_util.debugm(N, task, 'check value %s for multimap %s', value,
+ rule.symbol)
+
local ret = false
if r['cdb'] then