]> source.dussan.org Git - rspamd.git/commitdiff
Adopt spf module for new from/rcpt.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Aug 2014 14:00:07 +0000 (15:00 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Aug 2014 14:00:07 +0000 (15:00 +0100)
src/libserver/protocol.c
src/libserver/spf.c
src/libserver/spf.h

index e7be5a1c32e757307cffec8b2800e77d6ba461b4..38d6452cfb9a8352e2aa32af79b8f8ad082f420c 100644 (file)
@@ -229,10 +229,10 @@ gboolean
 rspamd_protocol_handle_headers (struct rspamd_task *task,
        struct rspamd_http_message *msg)
 {
-       gchar *headern, *err, *tmp;
+       gchar *headern, *tmp;
        gboolean res = TRUE, validh;
        struct rspamd_http_header *h;
-       InternetAddressList *tmp;
+       InternetAddressList *tmp_addr;
 
        LL_FOREACH (msg->headers, h)
        {
@@ -317,14 +317,14 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                if (task->rcpt_envelope == NULL) {
                                        task->rcpt_envelope = internet_address_list_new ();
                                }
-                               tmp = internet_address_list_parse_string (h->value->str);
-                               internet_address_list_append (task->rcpt_envelope, tmp);
+                               tmp_addr = internet_address_list_parse_string (h->value->str);
+                               internet_address_list_append (task->rcpt_envelope, tmp_addr);
 #ifdef GMIME24
-                               g_object_unref (tmp);
+                               g_object_unref (tmp_addr);
 #else
-                               internet_address_list_destroy (tmp);
+                               internet_address_list_destroy (tmp_addr);
 #endif
-                               debug_task ("read rcpt header, value: %s", tmp);
+                               debug_task ("read rcpt header, value: %v", h->value);
                        }
                        else {
                                msg_info ("wrong header: %s", headern);
@@ -484,7 +484,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
                msg_info ("<%s> URL: %s - %s: %s",
                        cb->task->message_id,
                        cb->task->user ?
-                       cb->task->user : (cb->task->from ? cb->task->from : "unknown"),
+                       cb->task->user : "unknown",
                        rspamd_inet_address_to_string (&cb->task->from_addr),
                        struri (url));
        }
index 56640cead8a35c29baa90f65c5b53da9e80f006d..0ef952a31c0a95b4bd7417dd01ce35d30eea23e7 100644 (file)
@@ -1551,35 +1551,14 @@ gchar *
 get_spf_domain (struct rspamd_task *task)
 {
        gchar *domain, *res = NULL;
-       GList *domains;
+       const gchar *sender;
 
-       if (task->from &&
-               (domain = strchr (task->from, '@')) != NULL && *domain == '@') {
-               res = rspamd_mempool_strdup (task->task_pool, domain + 1);
-               if ((domain = strchr (res, '>')) != NULL) {
-                       *domain = '\0';
-               }
-       }
-       else {
-               /* Extract from header */
-               domains = message_get_header (task->task_pool,
-                               task->message,
-                               "From",
-                               FALSE);
+       sender = rspamd_task_get_sender (task);
 
-               if (domains != NULL) {
-                       res = rspamd_mempool_strdup (task->task_pool, domains->data);
-
-                       if ((domain = strrchr (res, '@')) == NULL) {
-                               g_list_free (domains);
-                               return NULL;
-                       }
+       if (sender != NULL) {
+               domain = strchr (sender, '@');
+               if (domain) {
                        res = rspamd_mempool_strdup (task->task_pool, domain + 1);
-                       g_list_free (domains);
-
-                       if ((domain = strchr (res, '>')) != NULL) {
-                               *domain = '\0';
-                       }
                }
        }
 
@@ -1591,31 +1570,27 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback)
 {
        struct spf_record *rec;
        gchar *domain;
-       GList *domains;
+       const gchar *sender;
+
+       sender = rspamd_task_get_sender (task);
 
        rec = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct spf_record));
        rec->task = task;
        rec->callback = callback;
+
        /* Add destructor */
        rspamd_mempool_add_destructor (task->task_pool,
                (rspamd_mempool_destruct_t)spf_record_destructor,
                rec);
 
        /* Extract from data */
-       if (task->from &&
-               (domain = strchr (task->from, '@')) != NULL && *domain == '@') {
-               rec->sender = task->from;
-
-               rec->local_part = rspamd_mempool_strdup (task->task_pool, task->from);
-               *(rec->local_part + (domain - task->from)) = '\0';
-               if (*rec->local_part == '<') {
-                       memmove (rec->local_part, rec->local_part + 1,
-                               strlen (rec->local_part));
-               }
+       if (sender != NULL && (domain = strchr (sender, '@')) != NULL) {
+               rec->sender = sender;
+
+               rec->local_part = rspamd_mempool_alloc (task->task_pool,
+                               domain - sender);
+               rspamd_strlcpy (rec->local_part, sender, domain - sender);
                rec->cur_domain = rspamd_mempool_strdup (task->task_pool, domain + 1);
-               if ((domain = strchr (rec->cur_domain, '>')) != NULL) {
-                       *domain = '\0';
-               }
                rec->sender_domain = rec->cur_domain;
 
                if (make_dns_request (task->resolver, task->s, task->task_pool,
@@ -1626,44 +1601,6 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback)
                        return TRUE;
                }
        }
-       else {
-               /* Extract from header */
-               domains = message_get_header (task->task_pool,
-                               task->message,
-                               "From",
-                               FALSE);
-
-               if (domains != NULL) {
-                       rec->cur_domain = rspamd_mempool_strdup (task->task_pool,
-                                       domains->data);
-                       g_list_free (domains);
-
-                       if ((domain = strrchr (rec->cur_domain, '@')) == NULL) {
-                               return FALSE;
-                       }
-                       rec->sender = rspamd_mempool_strdup (task->task_pool,
-                                       rec->cur_domain);
-                       rec->local_part = rec->cur_domain;
-                       *domain = '\0';
-                       rec->cur_domain = domain + 1;
-
-                       if ((domain = strchr (rec->local_part, '<')) != NULL) {
-                               memmove (rec->local_part, domain + 1, strlen (domain));
-                       }
-
-                       if ((domain = strchr (rec->cur_domain, '>')) != NULL) {
-                               *domain = '\0';
-                       }
-                       rec->sender_domain = rec->cur_domain;
-                       if (make_dns_request (task->resolver, task->s, task->task_pool,
-                               spf_dns_callback, (void *)rec, RDNS_REQUEST_TXT,
-                               rec->cur_domain)) {
-                               task->dns_requests++;
-                               rec->requests_inflight++;
-                               return TRUE;
-                       }
-               }
-       }
 
        return FALSE;
 }
index 18d8229f88722b04690670bb54d14d02430fe1ec..616595c356ffcaca4dce4b8bb004c9ae5ebb5164 100644 (file)
@@ -60,7 +60,7 @@ struct spf_record {
 
        GList *addrs;
        gchar *cur_domain;
-       gchar *sender;
+       const gchar *sender;
        gchar *sender_domain;
        gchar *local_part;
        struct rspamd_task *task;