]> source.dussan.org Git - rspamd.git/commitdiff
Add routines to set recipients and sender for a task.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Feb 2015 22:43:48 +0000 (22:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Feb 2015 22:43:48 +0000 (22:43 +0000)
src/libserver/protocol.c
src/libserver/task.c
src/libserver/task.h

index 1b38c2b2cbb2d22eb6bb4006e1e2d0b153c49aee..2a43d054932565c66e51b25a732d035dbc40f685 100644 (file)
@@ -234,7 +234,6 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
        gchar *headern, *tmp;
        gboolean res = TRUE, validh;
        struct rspamd_http_header *h;
-       InternetAddressList *tmp_addr;
 
        LL_FOREACH (msg->headers, h)
        {
@@ -272,20 +271,10 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'f':
                case 'F':
                        if (g_ascii_strcasecmp (headern, FROM_HEADER) == 0) {
-                               task->from_envelope = internet_address_list_parse_string (
-                                               h->value->str);
-                               if (task->from_envelope) {
-#ifdef GMIME24
-                                       rspamd_mempool_add_destructor (task->task_pool,
-                                                       (rspamd_mempool_destruct_t) g_object_unref,
-                                                       task->from_envelope);
-#else
-                                       rspamd_mempool_add_destructor (task->task_pool,
-                                                       (rspamd_mempool_destruct_t) internet_address_list_destroy,
-                                                       task->from_envelope);
-#endif
+                               if (!rspamd_task_add_sender (task, h->value->str)) {
+                                       msg_err ("bad from header: '%s'", h->value->str);
+                                       validh = FALSE;
                                }
-                               debug_task ("read from header, value: %v", h->value);
                        }
                        else {
                                debug_task ("wrong header: %s", headern);
@@ -316,25 +305,10 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'r':
                case 'R':
                        if (g_ascii_strcasecmp (headern, RCPT_HEADER) == 0) {
-                               if (task->rcpt_envelope == NULL) {
-                                       task->rcpt_envelope = internet_address_list_new ();
-#ifdef GMIME24
-                                       rspamd_mempool_add_destructor (task->task_pool,
-                                                       (rspamd_mempool_destruct_t) g_object_unref,
-                                                       task->rcpt_envelope);
-#else
-                                       rspamd_mempool_add_destructor (task->task_pool,
-                                                       (rspamd_mempool_destruct_t) internet_address_list_destroy,
-                                                       task->rcpt_envelope);
-#endif
+                               if (!rspamd_task_add_recipient (task, h->value->str)) {
+                                       msg_err ("bad from header: '%s'", h->value->str);
+                                       validh = FALSE;
                                }
-                               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_addr);
-#else
-                               internet_address_list_destroy (tmp_addr);
-#endif
                                debug_task ("read rcpt header, value: %v", h->value);
                        }
                        else {
index c442db8fef3c0a92d3a4510d981f6edb0bf0f5d0..b43438a277a08f389857d996e257b8245b77c3cb 100644 (file)
@@ -376,3 +376,67 @@ rspamd_task_get_sender (struct rspamd_task *task)
 
        return (imb ? internet_address_mailbox_get_addr (imb) : NULL);
 }
+
+gboolean
+rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt)
+{
+       InternetAddressList *tmp_addr;
+
+       if (task->rcpt_envelope == NULL) {
+               task->rcpt_envelope = internet_address_list_new ();
+#ifdef GMIME24
+               rspamd_mempool_add_destructor (task->task_pool,
+                               (rspamd_mempool_destruct_t) g_object_unref,
+                               task->rcpt_envelope);
+#else
+               rspamd_mempool_add_destructor (task->task_pool,
+                               (rspamd_mempool_destruct_t) internet_address_list_destroy,
+                               task->rcpt_envelope);
+#endif
+       }
+       tmp_addr = internet_address_list_parse_string (rcpt);
+
+       if (tmp_addr) {
+               internet_address_list_append (task->rcpt_envelope, tmp_addr);
+#ifdef GMIME24
+               g_object_unref (tmp_addr);
+#else
+               internet_address_list_destroy (tmp_addr);
+#endif
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+gboolean
+rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender)
+{
+       InternetAddressList *tmp_addr;
+
+       if (task->from_envelope == NULL) {
+               task->from_envelope = internet_address_list_new ();
+#ifdef GMIME24
+               rspamd_mempool_add_destructor (task->task_pool,
+                               (rspamd_mempool_destruct_t) g_object_unref,
+                               task->from_envelope);
+#else
+               rspamd_mempool_add_destructor (task->task_pool,
+                               (rspamd_mempool_destruct_t) internet_address_list_destroy,
+                               task->from_envelope);
+#endif
+       }
+       tmp_addr = internet_address_list_parse_string (sender);
+
+       if (tmp_addr) {
+               internet_address_list_append (task->from_envelope, tmp_addr);
+#ifdef GMIME24
+               g_object_unref (tmp_addr);
+#else
+               internet_address_list_destroy (tmp_addr);
+#endif
+               return TRUE;
+       }
+
+       return FALSE;
+}
index 43349ffa9e6dc68d31089c2a7a61db8775d4c269..ded241b317eb8fe17ec1f380168b66fbaf50705e 100644 (file)
@@ -195,4 +195,20 @@ gboolean rspamd_task_process (struct rspamd_task *task,
  */
 const gchar *rspamd_task_get_sender (struct rspamd_task *task);
 
+/**
+ * Add a recipient for a task
+ * @param task task object
+ * @param rcpt string representation of recipient address
+ * @return TRUE if an address has been parsed and added
+ */
+gboolean rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt);
+/**
+ * Add a sender for a task
+ * @param task task object
+ * @param sender string representation of sender's address
+ * @return TRUE if an address has been parsed and added
+ */
+gboolean rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender);
+
+
 #endif /* TASK_H_ */