summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-12 21:13:10 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-12 21:13:10 +0400
commita569705d3057b09684ffda4452d2bf6101d2d9f3 (patch)
treec259a5aeefb7b3d239f3472305b369c20c38ecd4 /src/lua
parentff4871310ff5b269dcd02ea300cf78092860e1d4 (diff)
downloadrspamd-a569705d3057b09684ffda4452d2bf6101d2d9f3.tar.gz
rspamd-a569705d3057b09684ffda4452d2bf6101d2d9f3.zip
* Add ability to get difference between two parts from lua code
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 8c90feb4b..4916a50ad 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -110,6 +110,7 @@ LUA_FUNCTION_DEF (textpart, is_empty);
LUA_FUNCTION_DEF (textpart, is_html);
LUA_FUNCTION_DEF (textpart, get_fuzzy);
LUA_FUNCTION_DEF (textpart, get_language);
+LUA_FUNCTION_DEF (textpart, compare_distance);
static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, get_content),
@@ -117,6 +118,7 @@ static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, is_html),
LUA_INTERFACE_DEF (textpart, get_fuzzy),
LUA_INTERFACE_DEF (textpart, get_language),
+ LUA_INTERFACE_DEF (textpart, compare_distance),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
@@ -1341,6 +1343,49 @@ lua_textpart_get_language (lua_State * L)
return 1;
}
+static gint
+lua_textpart_compare_distance (lua_State * L)
+{
+ struct mime_text_part *part = lua_check_textpart (L), *other;
+ void *ud = luaL_checkudata (L, 2, "rspamd{textpart}");
+ gint diff = -1;
+ GMimeObject *parent;
+ const GMimeContentType *ct;
+
+ luaL_argcheck (L, ud != NULL, 2, "'textpart' expected");
+ other = *((struct mime_text_part **)ud);
+
+ if (part->parent && part->parent == other->parent) {
+ parent = part->parent;
+ ct = g_mime_object_get_content_type (parent);
+#ifndef GMIME24
+ if (ct == NULL || ! g_mime_content_type_is_type (ct, "multipart", "alternative")) {
+#else
+ if (ct == NULL || ! g_mime_content_type_is_type ((GMimeContentType *)ct, "multipart", "alternative")) {
+#endif
+ diff = -1;
+
+ }
+ else {
+ if (!part->is_empty && !other->is_empty) {
+ diff = fuzzy_compare_parts (part, other);
+ }
+ else if ((part->is_empty && !other->is_empty) || (!part->is_empty && other->is_empty)) {
+ /* Empty and non empty parts are different */
+ diff = 0;
+ }
+ }
+ }
+ else {
+ diff = -1;
+ }
+
+
+ lua_pushinteger (L, diff);
+
+ return 1;
+}
+
/* Image functions */
static gint
lua_image_get_width (lua_State *L)