]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Add ability to extract filename and size of images from lua
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 25 Aug 2010 16:15:29 +0000 (20:15 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 25 Aug 2010 16:15:29 +0000 (20:15 +0400)
src/images.c
src/images.h
src/lua/lua_task.c
src/message.c
src/message.h

index 00c9599c04bee6289cfe6e6b0dc8cea26d17e281..d071c38e717f941643df9496b38220d358c9713e 100644 (file)
@@ -226,6 +226,7 @@ process_image (struct worker_task *task, struct mime_part *part)
                                image_type_str (img->type),
                                img->width, img->height,
                                task->message_id);
+               img->filename = part->filename;
                task->images = g_list_prepend (task->images, img);
        }
 }
index 2a79e4edd8f581962cdf91d67e1355873cfddb74..f7616a680bf01e69e3dc9b3f10468097168d1bf0 100644 (file)
@@ -17,6 +17,7 @@ struct rspamd_image {
        GByteArray *data;
        guint32 width;
        guint32 height;
+       const char *filename;
 };
 
 void process_images (struct worker_task *task);
index b18cfc21f035544c0bb731a22974fc2e74444a90..cb9433d5e958984a61157dffc8dd347b2701b3ff 100644 (file)
@@ -109,11 +109,15 @@ static const struct luaL_reg    textpartlib_m[] = {
 LUA_FUNCTION_DEF (image, get_width);
 LUA_FUNCTION_DEF (image, get_height);
 LUA_FUNCTION_DEF (image, get_type);
+LUA_FUNCTION_DEF (image, get_filename);
+LUA_FUNCTION_DEF (image, get_size);
 
 static const struct luaL_reg    imagelib_m[] = {
        LUA_INTERFACE_DEF (image, get_width),
        LUA_INTERFACE_DEF (image, get_height),
        LUA_INTERFACE_DEF (image, get_type),
+       LUA_INTERFACE_DEF (image, get_filename),
+       LUA_INTERFACE_DEF (image, get_size),
        {"__tostring", lua_class_tostring},
        {NULL, NULL}
 };
@@ -885,6 +889,36 @@ lua_image_get_type (lua_State *L)
        return 1;
 }
 
+static int
+lua_image_get_size (lua_State *L)
+{
+       struct rspamd_image             *img = lua_check_image (L);
+
+       if (img != NULL) {
+               lua_pushinteger (L, img->data->len);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
+
+static int
+lua_image_get_filename (lua_State *L)
+{
+       struct rspamd_image             *img = lua_check_image (L);
+
+       if (img != NULL && img->filename != NULL) {
+               lua_pushstring (L, img->filename);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
+
 /* Init part */
 int
 luaopen_task (lua_State * L)
index ad730d3608628dc702b4f48fb79466303fa3db90..2491ddfc0ef6947535084ba58053bae63931e3c6 100644 (file)
@@ -709,6 +709,7 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data)
                                mime_part->type = type;
                                mime_part->content = part_content;
                                mime_part->parent = task->parser_parent_part;
+                               mime_part->filename = g_mime_part_get_filename (GMIME_PART (part));
                                /* Extract checksums for some types */
                                if (g_mime_content_type_is_type (type, "image", "*") && part_content->len > 0) {
                                        mime_part->checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, part_content->data, part_content->len);
index 3bdb0285d4d03e0a983f17ea3ed823cd51633f4b..4b51064ab7d9b7e3d0b9d9a14cefad92202955d4 100644 (file)
@@ -17,6 +17,7 @@ struct mime_part {
        GByteArray *content;
        GMimeObject *parent;
        gchar *checksum;
+       const char *filename;
 };
 
 struct mime_text_part {