diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-02-11 16:51:02 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-02-11 16:51:02 +0300 |
commit | 234e7468612c110feafce72b87a0b4b242050406 (patch) | |
tree | 9fcb127fc1fd7ae36fc7fede02334a7fd98fa4a0 /src | |
parent | 0aab87dab86cc9186e267b1448373411d816136e (diff) | |
download | rspamd-234e7468612c110feafce72b87a0b4b242050406.tar.gz rspamd-234e7468612c110feafce72b87a0b4b242050406.zip |
* Write Emails: header in output
Diffstat (limited to 'src')
-rw-r--r-- | src/protocol.c | 59 | ||||
-rw-r--r-- | src/tokenizers/tokenizers.c | 2 | ||||
-rw-r--r-- | src/url.c | 6 |
3 files changed, 63 insertions, 4 deletions
diff --git a/src/protocol.c b/src/protocol.c index 08bd88059..f5ef6bac2 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -550,6 +550,61 @@ show_url_header (struct worker_task *task) return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE); } +static gboolean +show_email_header (struct worker_task *task) +{ + gint r = 0; + gchar outbuf[OUTBUFSIZ]; + struct uri *url; + GList *cur; + gsize len; + GTree *url_tree; + + r = rspamd_snprintf (outbuf, sizeof (outbuf), "Emails: "); + url_tree = g_tree_new (compare_url_func); + cur = task->emails; + while (cur) { + url = cur->data; + if (g_tree_lookup (url_tree, url) == NULL && url->hostlen > 0) { + g_tree_insert (url_tree, url, url); + len = url->hostlen + url->userlen + 1; + /* Skip long hosts to avoid protocol coollisions */ + if (len > OUTBUFSIZ) { + cur = g_list_next (cur); + continue; + } + /* Do header folding */ + if (len + r >= OUTBUFSIZ - 3) { + outbuf[r++] = '\r'; + outbuf[r++] = '\n'; + outbuf[r] = ' '; + if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, TRUE, FALSE)) { + return FALSE; + } + r = 0; + } + /* Write url host to buf */ + if (g_list_next (cur) != NULL) { + r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%*s@%*s, ", + url->userlen, url->user, + url->hostlen, url->host); + } + else { + r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%*s@%*s", + url->userlen, url->user, + url->hostlen, url->host); + } + } + cur = g_list_next (cur); + } + if (r == 0) { + return TRUE; + } + r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, CRLF); + + return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE); +} + static void metric_symbols_callback (gpointer key, gpointer value, void *user_data) { @@ -853,6 +908,10 @@ write_check_reply (struct worker_task *task) if (! show_url_header (task)) { return FALSE; } + /* Emails stat */ + if (! show_email_header (task)) { + return FALSE; + } } write_hashes_to_log (task, logbuf, cd.log_offset, cd.log_size); diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 9c3e7f1f9..faa8f074b 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -264,7 +264,7 @@ tokenize_subject (struct worker_task *task, GTree ** tree) memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_tree_destroy, *tree); } - osb_tokenizer = get_tokenizer ("osb"); + osb_tokenizer = get_tokenizer ("osb-text"); /* Try to use pre-defined subject */ if (task->subject != NULL) { @@ -1117,17 +1117,17 @@ url_email_start (const gchar *begin, const gchar *end, const gchar *pos, url_mat if (pos > begin && *pos == '@') { /* Try to extract it with username */ p = pos - 1; - while (p > begin && is_atom (*p)) { + while (p > begin && (is_domain (*p) || *p == '.')) { p --; } - if (!is_atom (*p)) { + if (!is_domain (*p)) { match->m_begin = p + 1; return TRUE; } } else { p = pos + strlen (match->pattern); - if (is_atom (*p)) { + if (is_domain (*p)) { match->m_begin = p; return TRUE; } |