diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-07-13 11:04:06 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-07-13 11:04:06 +0400 |
commit | c6d62c095bc27aebd6c5f8dc9716467ae147fb68 (patch) | |
tree | 8099f0ebde9a3e99d33d46fa6fdb23d475ed7751 | |
parent | a569705d3057b09684ffda4452d2bf6101d2d9f3 (diff) | |
download | rspamd-c6d62c095bc27aebd6c5f8dc9716467ae147fb68.tar.gz rspamd-c6d62c095bc27aebd6c5f8dc9716467ae147fb68.zip |
* Add second argument to compare_parts_distance function so it can be used as interval: arg2 <= distance <= arg1
-rw-r--r-- | src/expressions.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/expressions.c b/src/expressions.c index d330526de..c2af8288c 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -58,26 +58,26 @@ static struct _fl { rspamd_internal_func_t func; void *user_data; } rspamd_functions_list[] = { - { - "compare_encoding", rspamd_compare_encoding, NULL}, { - "compare_parts_distance", rspamd_parts_distance, NULL}, { - "compare_recipients_distance", rspamd_recipients_distance, NULL}, { - "compare_transfer_encoding", rspamd_compare_transfer_encoding, NULL}, { - "content_type_compare_param", rspamd_content_type_compare_param, NULL}, { - "content_type_has_param", rspamd_content_type_has_param, NULL}, { - "content_type_is_subtype", rspamd_content_type_is_subtype, NULL}, { - "content_type_is_type", rspamd_content_type_is_type, NULL}, { - "has_content_part", rspamd_has_content_part, NULL}, { - "has_content_part_len", rspamd_has_content_part_len, NULL}, { - "has_fake_html", rspamd_has_fake_html, NULL}, { - "has_html_tag", rspamd_has_html_tag, NULL}, { - "has_only_html_part", rspamd_has_only_html_part, NULL}, { - "header_exists", rspamd_header_exists, NULL}, { - "is_html_balanced", rspamd_is_html_balanced, NULL}, { - "is_recipients_sorted", rspamd_is_recipients_sorted, NULL},}; + {"compare_encoding", rspamd_compare_encoding, NULL}, + {"compare_parts_distance", rspamd_parts_distance, NULL}, + {"compare_recipients_distance", rspamd_recipients_distance, NULL}, + {"compare_transfer_encoding", rspamd_compare_transfer_encoding, NULL}, + {"content_type_compare_param", rspamd_content_type_compare_param, NULL}, + {"content_type_has_param", rspamd_content_type_has_param, NULL}, + {"content_type_is_subtype", rspamd_content_type_is_subtype, NULL}, + {"content_type_is_type", rspamd_content_type_is_type, NULL}, + {"has_content_part", rspamd_has_content_part, NULL}, + {"has_content_part_len", rspamd_has_content_part_len, NULL}, + {"has_fake_html", rspamd_has_fake_html, NULL}, + {"has_html_tag", rspamd_has_html_tag, NULL}, + {"has_only_html_part", rspamd_has_only_html_part, NULL}, + {"header_exists", rspamd_header_exists, NULL}, + {"is_html_balanced", rspamd_is_html_balanced, NULL}, + {"is_recipients_sorted", rspamd_is_recipients_sorted, NULL} +}; static struct _fl *list_ptr = &rspamd_functions_list[0]; -static guint32 functions_number = sizeof (rspamd_functions_list) / sizeof (struct _fl); +static guint32 functions_number = sizeof (rspamd_functions_list) / sizeof (struct _fl); static gboolean list_allocated = FALSE; /* Bsearch routine */ @@ -1010,7 +1010,7 @@ rspamd_header_exists (struct worker_task * task, GList * args, void *unused) gboolean rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) { - gint threshold, diff; + gint threshold, threshold2 = -1, diff; struct mime_text_part *p1, *p2; GList *cur; struct expression_argument *arg; @@ -1030,6 +1030,15 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) msg_info ("bad numeric value for threshold \"%s\", assume it 100", (gchar *)args->data); threshold = 100; } + if (args->next) { + arg = get_function_arg (args->next->data, task, TRUE); + errno = 0; + threshold2 = strtoul ((gchar *)arg->data, NULL, 10); + if (errno != 0) { + msg_info ("bad numeric value for threshold \"%s\", ignore it", (gchar *)arg->data); + threshold2 = -1; + } + } } if ((pdiff = memory_pool_get_variable (task->task_pool, "parts_distance")) != NULL) { @@ -1078,8 +1087,15 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) debug_task ("got likeliness between parts of %d%%, threshold is %d%%", diff, threshold); *pdiff = diff; memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); - if (diff <= threshold) { - return TRUE; + if (threshold2 > 0 && threshold > threshold2) { + if (diff <= threshold && diff >= threshold2) { + return TRUE; + } + } + else { + if (diff <= threshold) { + return TRUE; + } } } else if ((p1->is_empty && !p2->is_empty) || (!p1->is_empty && p2->is_empty)) { |