From: Vsevolod Stakhov Date: Thu, 14 May 2009 14:59:56 +0000 (+0400) Subject: * Fix work with raw headers and with senders in message X-Git-Tag: 0.2.7~145 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e279ee1ddaa16b3bd1598010b53320fde8f65a52;p=rspamd.git * Fix work with raw headers and with senders in message --- diff --git a/src/message.c b/src/message.c index 33cf04732..5d344db62 100644 --- a/src/message.c +++ b/src/message.c @@ -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 }, diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index e088e1e02..8535c94f7 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -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);