aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-28 22:43:48 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-28 22:43:48 +0000
commit79c19905d02ca1bc5802c791b8c7be41fd65e506 (patch)
tree74f2303d2b5ee534367d9785302d68a138563a9f /src
parent158c9f6a505cf40d850ab3cae4dc115b80bf3a1d (diff)
downloadrspamd-79c19905d02ca1bc5802c791b8c7be41fd65e506.tar.gz
rspamd-79c19905d02ca1bc5802c791b8c7be41fd65e506.zip
Add routines to set recipients and sender for a task.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/protocol.c38
-rw-r--r--src/libserver/task.c64
-rw-r--r--src/libserver/task.h16
3 files changed, 86 insertions, 32 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 1b38c2b2c..2a43d0549 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -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 {
diff --git a/src/libserver/task.c b/src/libserver/task.c
index c442db8fe..b43438a27 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -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;
+}
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 43349ffa9..ded241b31 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -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_ */