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
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 },
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)
{
}
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;
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;
/* 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);