aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mimepart.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-22 13:27:38 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-22 13:27:38 +0000
commit229cde8387f8aecf5d21ef3a1fcf40ba8c53a156 (patch)
tree9fd1fd7ad41adc5343d3378ec51d820ff040275e /src/lua/lua_mimepart.c
parent412a182adc97374df1c852e5ac79c44c441eb564 (diff)
downloadrspamd-229cde8387f8aecf5d21ef3a1fcf40ba8c53a156.tar.gz
rspamd-229cde8387f8aecf5d21ef3a1fcf40ba8c53a156.zip
[Minor] Add is_attachment method
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r--src/lua/lua_mimepart.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 5a1bd0860..c672591bf 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -363,6 +363,12 @@ LUA_FUNCTION_DEF (mimepart, get_image);
* @return {bool} true if a part is an archive
*/
LUA_FUNCTION_DEF (mimepart, is_archive);
+/***
+ * @method mime_part:is_attachment()
+ * Returns true if mime part looks like an attachment
+ * @return {bool} true if a part looks like an attachment
+ */
+LUA_FUNCTION_DEF (mimepart, is_attachment);
/***
* @method mime_part:get_archive()
@@ -457,6 +463,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_children),
LUA_INTERFACE_DEF (mimepart, is_text),
LUA_INTERFACE_DEF (mimepart, is_broken),
+ LUA_INTERFACE_DEF (mimepart, is_attachment),
LUA_INTERFACE_DEF (mimepart, get_text),
LUA_INTERFACE_DEF (mimepart, get_digest),
LUA_INTERFACE_DEF (mimepart, get_id),
@@ -1356,6 +1363,37 @@ lua_mimepart_is_multipart (lua_State * L)
}
static gint
+lua_mimepart_is_attachment (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
+
+ if (part == NULL) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ if (!(part->flags & (RSPAMD_MIME_PART_IMAGE|RSPAMD_MIME_PART_TEXT))) {
+ if (part->cd && part->cd->type == RSPAMD_CT_ATTACHMENT) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ if (part->cd->filename.len > 0) {
+ /* We still have filename and it is not an image */
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+ }
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+
+ return 1;
+}
+
+static gint
lua_mimepart_is_text (lua_State * L)
{
LUA_TRACE_POINT;