aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-27 14:35:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-27 14:35:03 +0100
commit1af1d6ec7bf52eef7955474f8f51bc6351fa5980 (patch)
treeba6aacce0a4ca18c8265f820da060da6793b7801
parent0b2882ea9b6722a6ca9533e9121a5f30bd55fc49 (diff)
downloadrspamd-1af1d6ec7bf52eef7955474f8f51bc6351fa5980.tar.gz
rspamd-1af1d6ec7bf52eef7955474f8f51bc6351fa5980.zip
[Feature] Allow setting fuzzy flag by symbol not by value
-rw-r--r--src/client/rspamc.c6
-rw-r--r--src/plugins/fuzzy_check.c40
2 files changed, 45 insertions, 1 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 638ccedfe..68c33472d 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -43,6 +43,7 @@ static gchar *sort = NULL;
static gchar **http_headers = NULL;
static gint weight = 0;
static gint flag = 0;
+static gchar *fuzzy_symbol = NULL;
static gint max_requests = 8;
static gdouble timeout = 10.0;
static gboolean pass_all;
@@ -133,6 +134,8 @@ static GOptionEntry entries[] =
"Sort output in a specific order (name, weight, time)", NULL},
{ "empty", 'E', 0, G_OPTION_ARG_NONE, &empty_input,
"Allow empty input instead of reading from stdin", NULL },
+ { "fuzzy-symbol", 'S', 0, G_OPTION_ARG_STRING, &fuzzy_symbol,
+ "Learn the specified fuzzy symbol", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
@@ -468,6 +471,9 @@ add_options (GQueue *opts)
rspamd_printf_gstring (numbuf, "%d", weight);
ADD_CLIENT_HEADER (opts, "Weight", numbuf->str);
}
+ if (fuzzy_symbol != NULL) {
+ ADD_CLIENT_HEADER (opts, "Symbol", fuzzy_symbol);
+ }
if (flag != 0) {
numbuf = g_string_sized_new (8);
rspamd_printf_gstring (numbuf, "%d", flag);
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index caf894bf3..d2b0137f2 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -2321,7 +2321,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
return;
}
-static gboolean
+static int
fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd)
{
@@ -2337,14 +2337,52 @@ fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
msg_info ("error converting numeric argument %T", arg);
}
}
+
arg = rspamd_http_message_find_header (msg, "Flag");
if (arg) {
errno = 0;
+
if (!rspamd_strtol (arg->begin, arg->len, &flag)) {
msg_info ("error converting numeric argument %T", arg);
flag = 0;
}
}
+ else {
+ flag = 0;
+ arg = rspamd_http_message_find_header (msg, "Symbol");
+
+ /* Search flag by symbol */
+ if (arg) {
+ struct fuzzy_rule *rule;
+ GList *cur;
+ GHashTableIter it;
+ gpointer k, v;
+ struct fuzzy_mapping *map;
+
+ for (cur = fuzzy_module_ctx->fuzzy_rules; cur != NULL && flag == 0;
+ cur = g_list_next (cur)) {
+ rule = cur->data;
+
+ g_hash_table_iter_init (&it, rule->mappings);
+
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ map = v;
+
+ if (strlen (map->symbol) == arg->len &&
+ rspamd_lc_cmp (map->symbol, arg->begin, arg->len) == 0) {
+ flag = map->fuzzy_flag;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (flag == 0) {
+ msg_err ("no flag defined to learn fuzzy");
+ rspamd_controller_send_error (conn_ent, 404, "Unknown or missing flag");
+ return 0;
+ }
fuzzy_process_handler (conn_ent, msg, cmd, value, flag,
(struct fuzzy_ctx *)ctx);