]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Push dynamic symbol weight
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 8 Jul 2024 13:42:03 +0000 (14:42 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 8 Jul 2024 13:42:03 +0000 (14:42 +0100)
src/lua/lua_task.c

index dc41d4ab78583da09d5cb961d8097693189094cc..61aac63f25ce854820024c7e3e8d160b9204473c 100644 (file)
@@ -2642,7 +2642,7 @@ struct rspamd_url_query_to_inject_cbd {
 
 static gboolean
 inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
-                                               gsize end_offset, gpointer ud)
+                                                 gsize end_offset, gpointer ud)
 {
        struct rspamd_url_query_to_inject_cbd *cbd =
                (struct rspamd_url_query_to_inject_cbd *) ud;
@@ -2661,7 +2661,7 @@ inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
 
 static void
 inject_url_query(struct rspamd_task *task, struct rspamd_url *url,
-                                          GPtrArray *part_urls)
+                                GPtrArray *part_urls)
 {
        if (url->querylen > 0) {
                struct rspamd_url_query_to_inject_cbd cbd;
@@ -2692,11 +2692,11 @@ lua_task_inject_url(lua_State *L)
        if (lua_isuserdata(L, 3)) {
                /* We also have a mime part there */
                mpart = *((struct rspamd_mime_part **)
-                                                          rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
+                                         rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
        }
        if (task && task->message && url && url->url) {
                if (rspamd_url_set_add_or_increase(MESSAGE_FIELD(task, urls), url->url, false)) {
-                       if(mpart && mpart->urls) {
+                       if (mpart && mpart->urls) {
                                inject_url_query(task, url->url, mpart->urls);
                        }
                }
@@ -4682,7 +4682,7 @@ lua_push_symbol_result(lua_State *L,
        struct rspamd_symbol_option *opt;
        struct rspamd_symbols_group *sym_group;
        unsigned int i;
-       int j = 1, table_fields_cnt = 4;
+       int j = 1, table_fields_cnt = 5;
 
        if (!metric_res) {
                metric_res = task->result;
@@ -4710,10 +4710,22 @@ lua_push_symbol_result(lua_State *L,
                        lua_pushstring(L, symbol);
                        lua_settable(L, -3);
                }
+
                lua_pushstring(L, "score");
                lua_pushnumber(L, s->score);
                lua_settable(L, -3);
 
+               /* Dynamic weight of the symbol */
+               if (s->sym->score != 0) {
+                       lua_pushstring(L, "weight");
+                       lua_pushnumber(L, s->score / s->sym->score);
+               }
+               else {
+                       lua_pushstring(L, "weight");
+                       lua_pushnumber(L, 0.0);
+               }
+               lua_settable(L, -3);
+
                if (s->sym && s->sym->gr) {
                        lua_pushstring(L, "group");
                        lua_pushstring(L, s->sym->gr->name);