diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-05-13 19:22:09 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-05-13 19:22:09 +0400 |
commit | 4c4cdd54fbc5afde43e8ff18090c10dd60e06e0a (patch) | |
tree | d28e92cbac21f6dd99ee154b13cde57829d12e6f | |
parent | 04d82cf8b4d82aa979138d97fa4293534d04812e (diff) | |
download | rspamd-4c4cdd54fbc5afde43e8ff18090c10dd60e06e0a.tar.gz rspamd-4c4cdd54fbc5afde43e8ff18090c10dd60e06e0a.zip |
* Strip email addresses from braces
Ignore empty domains in settings
-rw-r--r-- | src/protocol.c | 6 | ||||
-rw-r--r-- | src/settings.c | 8 | ||||
-rw-r--r-- | src/util.c | 23 | ||||
-rw-r--r-- | src/util.h | 6 |
4 files changed, 38 insertions, 5 deletions
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; @@ -144,6 +145,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 */ #define msec_to_tv(msec, tv) do { (tv)->tv_sec = (msec) / 1000; (tv)->tv_usec = ((msec) - (tv)->tv_sec * 1000) * 1000; } while(0) |