]> source.dussan.org Git - rspamd.git/commitdiff
* Add support for empty text or html parts
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 29 Jul 2009 16:25:22 +0000 (20:25 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 29 Jul 2009 16:25:22 +0000 (20:25 +0400)
src/expressions.c
src/message.c
src/message.h
src/plugins/regexp.c

index 9b3b9bf2ffd7e9a543eee2eb83e01dd2623523cd..83bceae7a99d2fbd849b1c906ddb7122fb68711e 100644 (file)
@@ -1532,7 +1532,7 @@ rspamd_is_html_balanced (struct worker_task *task, GList *args)
        cur = g_list_first (task->text_parts);
        while (cur) {
                p = cur->data;
-               if (p->is_html) {
+               if (!p->is_empty && p->is_html) {
                        if (p->is_balanced) {
                                res = TRUE;
                        }
@@ -1598,7 +1598,7 @@ rspamd_has_html_tag (struct worker_task *task, GList *args)
 
        while (cur && res == FALSE) {
                p = cur->data;
-               if (p->is_html && p->html_nodes) {
+               if (!p->is_empty && p->is_html && p->html_nodes) {
                        g_node_traverse (p->html_nodes, G_PRE_ORDER, G_TRAVERSE_ALL, -1, search_html_node_callback, &cd);
                }
                cur = g_list_next (cur);
@@ -1619,7 +1619,7 @@ rspamd_has_fake_html (struct worker_task *task, GList *args)
 
        while (cur && res == FALSE) {
                p = cur->data;
-               if (p->is_html && p->html_nodes == NULL) {
+               if (!p->is_empty && p->is_html && p->html_nodes == NULL) {
                        res = TRUE;
                }
                cur = g_list_next (cur);
index cc9da181cc530942fe1cce2f44c2262f605c420b..dce8473e18de74ef4d615ac1e6001414f4e3d024 100644 (file)
@@ -504,7 +504,7 @@ convert_text_to_utf (struct worker_task *task, GByteArray *part_content, GMimeCo
 }
 
 static void
-process_text_part (struct worker_task *task, GByteArray *part_content, GMimeContentType *type)
+process_text_part (struct worker_task *task, GByteArray *part_content, GMimeContentType *type, gboolean is_empty)
 {
        struct mime_text_part *text_part;
 
@@ -512,8 +512,14 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont
                msg_debug ("mime_foreach_callback: got urls from text/html part");
 
                text_part = memory_pool_alloc (task->task_pool, sizeof (struct mime_text_part));
-               text_part->orig = convert_text_to_utf (task, part_content, type, text_part);
                text_part->is_html = TRUE;
+               if (is_empty) {
+                       text_part->is_empty = TRUE;
+                       text_part->orig = NULL;
+                       text_part->content = NULL;
+                       return;
+               }
+               text_part->orig = convert_text_to_utf (task, part_content, type, text_part);
                text_part->is_balanced = TRUE;
                text_part->html_nodes = NULL;
 
@@ -542,9 +548,15 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont
                msg_debug ("mime_foreach_callback: got urls from text/plain part");
 
                text_part = memory_pool_alloc (task->task_pool, sizeof (struct mime_text_part));
+               text_part->is_html = FALSE;
+               if (is_empty) {
+                       text_part->is_empty = TRUE;
+                       text_part->orig = NULL;
+                       text_part->content = NULL;
+                       return;
+               }
                text_part->orig = convert_text_to_utf (task, part_content, type, text_part);
                text_part->content = text_part->orig;
-               text_part->is_html = FALSE;
                text_part->fuzzy = fuzzy_init_byte_array (text_part->content, task->task_pool);
                text_part->html_urls = NULL;
                text_part->urls = g_tree_new ( (GCompareFunc)g_ascii_strcasecmp);
@@ -641,9 +653,7 @@ mime_foreach_callback (GMimeObject *part, gpointer user_data)
                                msg_debug ("mime_foreach_callback: found part with content-type: %s/%s", type->type, type->subtype);
                                task->parts = g_list_prepend (task->parts, mime_part);
                                /* Skip empty parts */
-                               if (part_content->len > 0) {
-                                       process_text_part (task, part_content, type);
-                               }
+                               process_text_part (task, part_content, type, (part_content->len > 0));
                        }
                        else {
                                msg_warn ("mime_foreach_callback: write to stream failed: %d, %s", errno, strerror (errno));
index a14a92aa4acad582d9a92d5e968d1504df9a4228..939379cedc0f6bed1d171586e9f63add676b2488 100644 (file)
@@ -21,6 +21,7 @@ struct mime_text_part {
        gboolean is_html;
        gboolean is_raw;
        gboolean is_balanced;
+       gboolean is_empty;
        GByteArray *orig;
        GByteArray *content;
        GNode *html_nodes;
index 23ec3908ca47a3e8456f496d1b7bb14ddc38d725..45f07f9e7864b5d14381646ffc8595403b69783b 100644 (file)
@@ -335,6 +335,11 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                        cur = g_list_first (task->text_parts);
                        while (cur) {
                                part = (struct mime_text_part *)cur->data;
+                               /* Skip empty parts */
+                               if (part->is_empty) {
+                                       cur = g_list_next (cur);
+                                       continue;
+                               }
                                if (part->is_raw) {
                                        regexp = re->raw_regexp;
                                }
@@ -371,6 +376,11 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                        cur = g_list_first (task->text_parts);
                        while (cur) {
                                part = (struct mime_text_part *)cur->data;
+                               /* Skip empty parts */
+                               if (part->is_empty) {
+                                       cur = g_list_next (cur);
+                                       continue;
+                               }
                                if (part->is_raw) {
                                        regexp = re->raw_regexp;
                                }