]> source.dussan.org Git - rspamd.git/commitdiff
* Fix work with raw headers and with senders in message
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 14 May 2009 14:59:56 +0000 (18:59 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 14 May 2009 14:59:56 +0000 (18:59 +0400)
src/message.c
src/plugins/regexp.c

index 33cf047329f431593335659437120127980fb62b..5d344db62602abdf0b8c3dd3a91c9dbc294fe7a4 100644 (file)
@@ -760,6 +760,50 @@ local_mime_message_set_date_from_string (GMimeMessage *message, const gchar *str
        g_mime_message_set_date (message, date, offset); 
 }
 
+/*
+ * Replacements for standart gmime functions but converting adresses to IA
+ */
+static const char*
+local_message_get_sender (GMimeMessage *message)
+{
+       char *res;
+       const char *from = g_mime_message_get_sender (message);
+       InternetAddressList *ia;
+       
+#ifndef        GMIME24
+       ia = internet_address_parse_string (from);
+#else
+       ia = internet_address_list_parse_string (from);
+#endif
+       if (!ia) {
+               return NULL;
+       }
+       res = internet_address_list_to_string (ia, FALSE);
+       internet_address_list_destroy (ia);
+       
+       return res;
+}
+
+static const char*
+local_message_get_reply_to (GMimeMessage *message)
+{
+       char *res;
+       const char *from = g_mime_message_get_reply_to (message);
+       InternetAddressList *ia;
+
+#ifndef        GMIME24
+       ia = internet_address_parse_string (from);
+#else
+       ia = internet_address_list_parse_string (from);
+#endif
+       if (!ia) {
+               return NULL;
+       }
+       res = internet_address_list_to_string (ia, FALSE);
+       internet_address_list_destroy (ia);
+       
+       return res;
+}
 
 #ifdef GMIME24
 
@@ -833,8 +877,8 @@ static struct {
        SetListFunc     setlfunc;
        gint            functype;
 } fieldfunc[] = {
-       { "From",               g_mime_message_get_sender,              NULL, NULL,                             g_mime_message_set_sender,      NULL, FUNC_CHARPTR },
-       { "Reply-To",   g_mime_message_get_reply_to,    NULL, NULL,                             g_mime_message_set_reply_to,    NULL, FUNC_CHARPTR },
+       { "From",               local_message_get_sender,                                       NULL, NULL,     g_mime_message_set_sender, NULL, FUNC_CHARFREEPTR },
+       { "Reply-To",   local_message_get_reply_to,                             NULL, NULL,     g_mime_message_set_reply_to, NULL, FUNC_CHARFREEPTR },
 #ifndef GMIME24
        { "To", NULL,   (GetRcptFunc)g_mime_message_get_recipients,     NULL, NULL, (SetListFunc)g_mime_message_add_recipients_from_string, FUNC_IA },
        { "Cc", NULL,   (GetRcptFunc)g_mime_message_get_recipients,     NULL, NULL, (SetListFunc)g_mime_message_add_recipients_from_string, FUNC_IA },
index e088e1e0238e56b1facce003bae8c5353bb86f0f..8535c94f73d9f6811e0f8d66cc9b55045e134949 100644 (file)
@@ -202,6 +202,40 @@ regexp_module_reconfig (struct config_file *cfg)
        return regexp_module_config (cfg);
 }
 
+static const char *
+find_raw_header_pos (const char *headers, const char *headerv)
+{
+       const char *p = headers;
+       gsize headerlen = strlen (headerv);
+
+       if (headers == NULL) {
+               return NULL;
+       }
+
+       while (*p) {
+               /* Try to find headers only at the begin of line */
+               if (*p == '\r' || *p == '\n') {
+                       if (*(p + 1) == '\n' && *p == '\r') {
+                               p ++;
+                       }
+                       if (g_ascii_isspace (*(++p))) {
+                               /* Folding */
+                               continue;
+                       }
+                       if (memcmp (p, headerv, headerlen) == 0) {
+                               /* Find semicolon */
+                               p += headerlen;
+                               if (*p == ':') {
+                                       return p;
+                               }
+                       }
+               }
+               p ++;
+       }
+
+       return NULL;
+}
+
 static gsize
 process_regexp (struct rspamd_regexp *re, struct worker_task *task)
 {
@@ -248,6 +282,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                                }
                                cur = headerlist;
                                while (cur) {
+                                       msg_debug ("process_regexp: found header \"%s\" with value \"%s\"", re->header, (char *)cur->data);
                                        if (cur->data && g_regex_match (re->regexp, cur->data, 0, NULL) == TRUE) {
                                                task_cache_add (task, re, 1);
                                                return 1;
@@ -312,7 +347,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                                task_cache_add (task, re, 0);
                                return 0;
                        }
-                       if ((headerv = strstr (task->raw_headers, re->header)) == NULL) {
+                       if ((headerv = (char *)find_raw_header_pos (task->raw_headers, re->header)) == NULL) {
                                /* No header was found */
                                task_cache_add (task, re, 0);
                                return 0;
@@ -342,6 +377,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                        /* Temporary null terminate this part of string */
                        t = *c;
                        *c = '\0';
+                       msg_debug ("process_regexp: found raw header \"%s\" with value \"%s\"", re->header, headerv);
                        if (g_regex_match (re->raw_regexp, headerv, 0, NULL) == TRUE) {
                                *c = t;
                                task_cache_add (task, re, 1);