aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-29 15:55:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-29 15:55:59 +0100
commitf0a9da38f3df5b4efa75be07df129f49932f2526 (patch)
tree34c85baaee2659b7ae947f9704e79dd706d1d7da
parent2aabcddd7434e73bff07170ce5260201d348005d (diff)
downloadrspamd-f0a9da38f3df5b4efa75be07df129f49932f2526.tar.gz
rspamd-f0a9da38f3df5b4efa75be07df129f49932f2526.zip
Allow to get mime part from text part in lua.
-rw-r--r--src/lua/lua_mimepart.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index f1012811a..354dd3824 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -98,6 +98,12 @@ LUA_FUNCTION_DEF (textpart, get_fuzzy);
*/
LUA_FUNCTION_DEF (textpart, get_language);
/***
+ * @method text_part:get_mimepart()
+ * Returns the mime part object corresponding to this text part
+ * @return {mimepart} mimepart object
+ */
+LUA_FUNCTION_DEF (textpart, get_mimepart);
+/***
* @method text_part:compare_distance(other)
* Calculates the difference to another text part. This function is intended to work with
* the parts of `multipart/alternative` container only. If the two parts are not the parts of the
@@ -117,6 +123,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, get_mimepart),
LUA_INTERFACE_DEF (textpart, compare_distance),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
@@ -381,6 +388,26 @@ lua_textpart_get_language (lua_State * L)
}
static gint
+lua_textpart_get_mimepart (lua_State * L)
+{
+ struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_part **pmime;
+
+ if (part != NULL) {
+ if (part->mime_part != NULL) {
+ pmime = lua_newuserdata (L, sizeof (struct mime_part *));
+ rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
+ *pmime = part->mime_part;
+
+ return 1;
+ }
+ }
+
+ lua_pushnil (L);
+ return 1;
+}
+
+static gint
lua_textpart_compare_distance (lua_State * L)
{
struct mime_text_part *part = lua_check_textpart (L), *other;