summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-24 16:59:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-01 14:03:04 +0100
commitfd3444e7a595689809ad07150c74cc755c7e8d59 (patch)
treeb4919a9808c6d042c2a4ab7a27d4a1a0317f39f9
parentfffac183f4648f6635228fab1f0f064566a4d6a9 (diff)
downloadrspamd-fd3444e7a595689809ad07150c74cc755c7e8d59.tar.gz
rspamd-fd3444e7a595689809ad07150c74cc755c7e8d59.zip
[Minor] Add lua methods to detect if a part has 8bit characters
-rw-r--r--src/lua/lua_mimepart.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 581a2c260..ae79880b2 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -45,6 +45,21 @@ end
* @return {boolean} true if part is valid `UTF8` part
*/
LUA_FUNCTION_DEF (textpart, is_utf);
+
+/***
+ * @method text_part:is_8bit_raw()
+ * Return TRUE if a part has raw 8bit characters
+ * @return {boolean} true if a part has raw 8bit characters
+ */
+LUA_FUNCTION_DEF (textpart, is_8bit_raw);
+
+/***
+ * @method text_part:is_8bit()
+ * Return TRUE if a part has raw 8bit characters
+ * @return {boolean} true if a part has encoded 8bit characters
+ */
+LUA_FUNCTION_DEF (textpart, is_8bit);
+
/***
* @method text_part:get_content([type])
* Get the text of the part (html tags stripped). Optional `type` defines type of content to get:
@@ -131,6 +146,8 @@ LUA_FUNCTION_DEF (textpart, get_mimepart);
static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, is_utf),
+ LUA_INTERFACE_DEF (textpart, is_8bit_raw),
+ LUA_INTERFACE_DEF (textpart, is_8bit),
LUA_INTERFACE_DEF (textpart, get_content),
LUA_INTERFACE_DEF (textpart, get_raw_content),
LUA_INTERFACE_DEF (textpart, get_content_oneline),
@@ -378,6 +395,47 @@ lua_textpart_is_utf (lua_State * L)
static gint
+lua_textpart_is_8bit_raw (lua_State * L)
+{
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
+
+ if (part) {
+ if (part->flags & RSPAMD_MIME_TEXT_PART_FLAG_8BIT) {
+ lua_pushboolean (L, TRUE);
+ }
+ else {
+ lua_pushboolean (L, FALSE);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
+lua_textpart_is_8bit (lua_State * L)
+{
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
+
+ if (part) {
+ if (part->flags & RSPAMD_MIME_TEXT_PART_FLAG_8BIT_ENCODED) {
+ lua_pushboolean (L, TRUE);
+ }
+ else {
+ lua_pushboolean (L, FALSE);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+
+static gint
lua_textpart_get_content (lua_State * L)
{
struct rspamd_mime_text_part *part = lua_check_textpart (L);