]> source.dussan.org Git - rspamd.git/commitdiff
* Write Emails: header in output
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 11 Feb 2011 13:51:02 +0000 (16:51 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 11 Feb 2011 13:51:02 +0000 (16:51 +0300)
src/protocol.c
src/tokenizers/tokenizers.c
src/url.c

index 08bd88059ebfb68bc058ccd362567a30cfacf07f..f5ef6bac2f50737d053690b47e24d3f4e731c52a 100644 (file)
@@ -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);
index 9c3e7f1f9a5ac1b103e1e22022289add0a1afb78..faa8f074b837e2b6b2050dca16d4860df9d779bf 100644 (file)
@@ -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) {
index 596d17d3ad21465b8e12c18bb69d5044bff1b44c..1251b06b63a1dcb25c0d8a7d3d9ae0c782612296 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -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;
                }