aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-07-29 20:25:22 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-07-29 20:25:22 +0400
commit9bd902ee1d0ebb87e789e335dc71bc7fb87e9e8e (patch)
treee68d476e7cd564a5462e697a7743da983aec3827
parentc4621d35aebaf9c6d466bf7a15a9de340b20b0ce (diff)
downloadrspamd-9bd902ee1d0ebb87e789e335dc71bc7fb87e9e8e.tar.gz
rspamd-9bd902ee1d0ebb87e789e335dc71bc7fb87e9e8e.zip
* Add support for empty text or html parts
-rw-r--r--src/expressions.c6
-rw-r--r--src/message.c22
-rw-r--r--src/message.h1
-rw-r--r--src/plugins/regexp.c10
4 files changed, 30 insertions, 9 deletions
diff --git a/src/expressions.c b/src/expressions.c
index 9b3b9bf2f..83bceae7a 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -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);
diff --git a/src/message.c b/src/message.c
index cc9da181c..dce8473e1 100644
--- a/src/message.c
+++ b/src/message.c
@@ -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));
diff --git a/src/message.h b/src/message.h
index a14a92aa4..939379ced 100644
--- a/src/message.h
+++ b/src/message.h
@@ -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;
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index 23ec3908c..45f07f9e7 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -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;
}