]> source.dussan.org Git - rspamd.git/commitdiff
* Strip email addresses from braces
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 13 May 2011 15:22:09 +0000 (19:22 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 13 May 2011 15:22:09 +0000 (19:22 +0400)
Ignore empty domains in settings

src/protocol.c
src/settings.c
src/util.c
src/util.h

index 4d6507652f038f5e31f47198af50b2e7187891f1..ff626bc8510fddf264438955f26b40dfcb893b56 100644 (file)
@@ -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);
                }
index 2f3dd85bee7e62cbd9cd9cdeb37c9bfc4ae64e90..05757a61c4cd65751ddf6461f0fbb0b2a4d76435 100644 (file)
@@ -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)));
+                                       }
                                }
 
                        }
index 89bc1333606a2862fcae96cfa07953ea0e0751ed..cec4e455dc88abb25e2b008704cf97292fe2fc5a 100644 (file)
@@ -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
  */
index 8f910e404339d6afdc20600eca42757be6f8b09b..1c29ba91d14c94e09850c064b58ab3c09c08a8fe 100644 (file)
@@ -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
  */