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;
}
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);
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);
}
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;
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;
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);
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));