From: Vsevolod Stakhov Date: Fri, 13 May 2011 15:22:09 +0000 (+0400) Subject: * Strip email addresses from braces X-Git-Tag: 0.3.13~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4c4cdd54fbc5afde43e8ff18090c10dd60e06e0a;p=rspamd.git * Strip email addresses from braces Ignore empty domains in settings --- diff --git a/src/protocol.c b/src/protocol.c index 4d6507652..ff626bc85 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -457,7 +457,7 @@ parse_header (struct worker_task *task, f_str_t * line) case 'D': /* Deliver-To */ if (g_ascii_strncasecmp (headern, DELIVER_TO_HEADER, sizeof (DELIVER_TO_HEADER) - 1) == 0) { - task->deliver_to = memory_pool_fstrdup (task->task_pool, line); + task->deliver_to = escape_braces_addr_fstr (task->task_pool, line); debug_task ("read deliver-to header, value: %s", task->deliver_to); } else { @@ -481,7 +481,7 @@ parse_header (struct worker_task *task, f_str_t * line) case 'F': /* from */ if (g_ascii_strncasecmp (headern, FROM_HEADER, sizeof (FROM_HEADER) - 1) == 0) { - task->from = memory_pool_fstrdup (task->task_pool, line); + task->from = escape_braces_addr_fstr (task->task_pool, line); debug_task ("read from header, value: %s", task->from); } else { @@ -516,7 +516,7 @@ parse_header (struct worker_task *task, f_str_t * line) case 'R': /* rcpt */ if (g_ascii_strncasecmp (headern, RCPT_HEADER, sizeof (RCPT_HEADER) - 1) == 0) { - tmp = memory_pool_fstrdup (task->task_pool, line); + tmp = escape_braces_addr_fstr (task->task_pool, line); task->rcpt = g_list_prepend (task->rcpt, tmp); debug_task ("read rcpt header, value: %s", tmp); } diff --git a/src/settings.c b/src/settings.c index 2f3dd85be..05757a61c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -285,8 +285,10 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data) for(j = 0; j < n; j++) { it_val = json_array_get(cur_nm, j); if (it_val && json_is_string (it_val)) { - g_hash_table_insert (cur_settings->whitelist, + if (strlen (json_string_value (it_val)) > 0) { + g_hash_table_insert (cur_settings->whitelist, g_strdup (json_string_value (it_val)), g_strdup (json_string_value (it_val))); + } } } @@ -298,8 +300,10 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data) for(j = 0; j < n; j++) { it_val = json_array_get(cur_nm, j); if (it_val && json_is_string (it_val)) { - g_hash_table_insert (cur_settings->blacklist, + if (strlen (json_string_value (it_val)) > 0) { + g_hash_table_insert (cur_settings->blacklist, g_strdup (json_string_value (it_val)), g_strdup (json_string_value (it_val))); + } } } diff --git a/src/util.c b/src/util.c index 89bc13336..cec4e455d 100644 --- a/src/util.c +++ b/src/util.c @@ -1336,6 +1336,29 @@ free_task_soft (gpointer ud) free_task (task, FALSE); } +gchar * +escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in) +{ + gint len = 0; + gchar *res, *orig, *p; + + orig = in->begin; + while ((g_ascii_isspace (*orig) || *orig == '<') && orig - in->begin < in->len) { + orig ++; + } + + p = orig; + while ((!g_ascii_isspace (*p) && *p != '>') && p - in->begin < in->len) { + p ++; + len ++; + } + + res = memory_pool_alloc (pool, len + 1); + rspamd_strlcpy (res, orig, len + 1); + + return res; +} + /* * vi:ts=4 */ diff --git a/src/util.h b/src/util.h index 8f910e404..1c29ba91d 100644 --- a/src/util.h +++ b/src/util.h @@ -6,6 +6,7 @@ #include "radix.h" #include "statfile.h" #include "printf.h" +#include "fstring.h" struct config_file; struct rspamd_main; @@ -143,6 +144,11 @@ const gchar * process_to_str (enum process_type type); */ enum process_type str_to_process (const gchar *str); +/* + * Strip <> from email address + */ +gchar * escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in); + /* * Convert milliseconds to timeval fields */