*/
#include "config.h"
#include "images.h"
-#include "rspamd.h"
+#include "task.h"
#include "message.h"
#include "html.h"
for (i = 0; i < task->parts->len; i ++) {
part = g_ptr_array_index (task->parts, i);
- if (g_mime_content_type_is_type (part->type, "image",
- "*") && part->content->len > 0) {
+ if (g_mime_content_type_is_type (part->type, "image", "*") &&
+ part->content->len > 0) {
process_image (task, part);
}
}
img->width, img->height,
task->message_id);
img->filename = part->filename;
- task->images = g_list_prepend (task->images, img);
+ part->flags |= RSPAMD_MIME_PART_IMAGE;
+ part->specific_data = img;
/* Check Content-Id */
rh = g_hash_table_lookup (part->raw_headers, "Content-Id");
#define IMAGES_H_
#include "config.h"
-#include "rspamd.h"
struct html_image;
+struct rspamd_task;
enum rspamd_image_type {
IMAGE_TYPE_PNG = 0,
return;
}
+ mime_part->flags |= RSPAMD_MIME_PART_TEXT;
+ mime_part->specific_data = text_part;
+
if (rspamd_check_gtube (task, text_part)) {
struct metric_result *mres;
rspamd_email_address_unref (task->from_envelope);
}
- if (task->images) {
- g_list_free (task->images);
- }
-
if (task->messages) {
g_list_free (task->messages);
}
GPtrArray *received; /**< list of received headers */
GHashTable *urls; /**< list of parsed urls */
GHashTable *emails; /**< list of parsed emails */
- GList *images; /**< list of images */
GHashTable *raw_headers; /**< list of raw headers */
GHashTable *results; /**< hash table of metric_result indexed by
* metric's name */
ar = g_array_sized_new (FALSE, FALSE, sizeof (elt), 4);
/* Insert images */
- cur = g_list_first (task->images);
+ for (i = 0; i < task->parts->len; i ++) {
+ part = g_ptr_array_index (task->parts, i);
- while (cur) {
- img = cur->data;
+ if (part->flags & RSPAMD_MIME_PART_IMAGE) {
+ img = part->specific_data;
- /* If an image has a linked HTML part, then we push its details to the stat */
- if (img->html_image) {
- elt.begin = (gchar *)"image";
- elt.len = 5;
- g_array_append_val (ar, elt);
- elt.begin = (gchar *)&img->html_image->height;
- elt.len = sizeof (img->html_image->height);
- g_array_append_val (ar, elt);
- elt.begin = (gchar *)&img->html_image->width;
- elt.len = sizeof (img->html_image->width);
- g_array_append_val (ar, elt);
- elt.begin = (gchar *)&img->type;
- elt.len = sizeof (img->type);
- g_array_append_val (ar, elt);
-
- if (img->filename) {
- elt.begin = (gchar *)img->filename;
- elt.len = strlen (elt.begin);
+ /* If an image has a linked HTML part, then we push its details to the stat */
+ if (img->html_image) {
+ elt.begin = (gchar *)"image";
+ elt.len = 5;
+ g_array_append_val (ar, elt);
+ elt.begin = (gchar *)&img->html_image->height;
+ elt.len = sizeof (img->html_image->height);
+ g_array_append_val (ar, elt);
+ elt.begin = (gchar *)&img->html_image->width;
+ elt.len = sizeof (img->html_image->width);
+ g_array_append_val (ar, elt);
+ elt.begin = (gchar *)&img->type;
+ elt.len = sizeof (img->type);
g_array_append_val (ar, elt);
- }
- msg_debug_task ("added stat tokens for image '%s'", img->html_image->src);
- }
+ if (img->filename) {
+ elt.begin = (gchar *)img->filename;
+ elt.len = strlen (elt.begin);
+ g_array_append_val (ar, elt);
+ }
- cur = g_list_next (cur);
+ msg_debug_task ("added stat tokens for image '%s'", img->html_image->src);
+ }
+ }
}
/* Process mime parts */
lua_task_get_images (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- gint i = 1;
- GList *cur;
+ guint nelt = 0, i;
+ struct rspamd_mime_part *part;
struct rspamd_image **pimg;
if (task) {
- cur = task->images;
+ lua_newtable (L);
- if (cur) {
- lua_newtable (L);
+ for (i = 0; i < task->parts->len; i ++) {
+ part = g_ptr_array_index (task->parts, i);
- while (cur) {
+ if (part->flags & RSPAMD_MIME_PART_IMAGE) {
pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
rspamd_lua_setclass (L, "rspamd{image}", -1);
- *pimg = cur->data;
- lua_rawseti (L, -2, i++);
- cur = g_list_next (cur);
+ *pimg = part->specific_data;
+ lua_rawseti (L, -2, ++nelt);
}
}
- else {
- /* Return nil if there are no images to preserve compatibility */
- lua_pushnil (L);
- }
}
else {
return luaL_error (L, "invalid arguments");
}
}
- /* Process images */
- GList *cur;
+ /* Process other parts and images */
+ for (i = 0; i < task->parts->len; i ++) {
+ mime_part = g_ptr_array_index (task->parts, i);
- cur = task->images;
- while (cur) {
- image = cur->data;
- if (image->data->len > 0) {
- if (fuzzy_module_ctx->min_height <= 0 || image->height >=
- fuzzy_module_ctx->min_height) {
- if (fuzzy_module_ctx->min_width <= 0 || image->width >=
- fuzzy_module_ctx->min_width) {
- io = fuzzy_cmd_from_data_part (rule, c, flag, value,
- task->task_pool,
- image->data->data, image->data->len);
- if (io) {
- g_ptr_array_add (res, io);
+ if (mime_part->flags & RSPAMD_MIME_PART_IMAGE) {
+ image = mime_part->specific_data;
+
+ if (image->data->len > 0) {
+ if (fuzzy_module_ctx->min_height <= 0 || image->height >=
+ fuzzy_module_ctx->min_height) {
+ if (fuzzy_module_ctx->min_width <= 0 || image->width >=
+ fuzzy_module_ctx->min_width) {
+ io = fuzzy_cmd_from_data_part (rule, c, flag, value,
+ task->task_pool,
+ image->data->data, image->data->len);
+ if (io) {
+ g_ptr_array_add (res, io);
+ }
}
}
}
}
- cur = g_list_next (cur);
- }
-
- /* Process other parts */
- for (i = 0; i < task->parts->len; i ++) {
- mime_part = g_ptr_array_index (task->parts, i);
if (mime_part->content->len > 0 &&
fuzzy_check_content_type (rule, mime_part->type)) {