aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-03 14:28:47 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-03 14:28:47 +0000
commit5244e863178e776d8af230e966da502920d1197b (patch)
tree6b349a875511315bad8965c97485a287873a9a62 /src
parent6d8ad20e0adfb6985c8fa2d53e4905ed7c2d822e (diff)
downloadrspamd-5244e863178e776d8af230e966da502920d1197b.tar.gz
rspamd-5244e863178e776d8af230e966da502920d1197b.zip
[Feature] Add rule to detect broken content type
Diffstat (limited to 'src')
-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 dba66b818..6d17c3a66 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -288,6 +288,12 @@ LUA_FUNCTION_DEF (mimepart, get_text);
* @return {string} 128 characters hex string with digest of the part
*/
LUA_FUNCTION_DEF (mimepart, get_digest);
+/***
+ * @method mime_part:is_broken()
+ * Returns true if mime part has incorrectly specified content type
+ * @return {bool} true if a part has bad content type
+ */
+LUA_FUNCTION_DEF (mimepart, is_broken);
static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_content),
@@ -302,6 +308,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, is_archive),
LUA_INTERFACE_DEF (mimepart, get_archive),
LUA_INTERFACE_DEF (mimepart, is_text),
+ LUA_INTERFACE_DEF (mimepart, is_broken),
LUA_INTERFACE_DEF (mimepart, get_text),
LUA_INTERFACE_DEF (mimepart, get_digest),
{"__tostring", rspamd_lua_class_tostring},
@@ -739,6 +746,26 @@ lua_mimepart_is_text (lua_State * L)
}
static gint
+lua_mimepart_is_broken (lua_State * L)
+{
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
+
+ if (part == NULL) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ if (part->ct) {
+ lua_pushboolean (L, (part->ct->flags & RSPAMD_CONTENT_TYPE_BROKEN) ?
+ true : false);
+ }
+ else {
+ lua_pushboolean (L, true);
+ }
+
+ return 1;
+}
+
+static gint
lua_mimepart_get_image (lua_State * L)
{
struct rspamd_mime_part *part = lua_check_mimepart (L);