commit e8f8cc3: [Feature] Parse ical files
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Apr 8 12:28:08 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-04-08 13:24:55 +0100
URL: https://github.com/rspamd/rspamd/commit/e8f8cc343f2d32cbbeeb9fbd95d8bb394a1504e6 (HEAD -> master)
[Feature] Parse ical files
---
src/libmime/message.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 3 deletions(-)
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 6825bc2f0..9bbd25d32 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -34,7 +34,8 @@
#include <math.h>
#include <unicode/uchar.h>
-#include <src/libserver/cfg_file_private.h>
+#include "libserver/cfg_file_private.h"
+#include "lua/lua_common.h"
#define GTUBE_SYMBOL "GTUBE"
@@ -686,8 +687,69 @@ rspamd_message_process_plain_text_part (struct rspamd_task *task,
rspamd_mime_text_part_maybe_convert (task, text_part);
if (text_part->utf_raw_content != NULL) {
- /* Different from HTML, where we also parse HTML and strip tags */
- text_part->utf_content = text_part->utf_raw_content;
+ /* Check for ical */
+ rspamd_ftok_t cal_ct;
+
+ RSPAMD_FTOK_ASSIGN (&cal_ct, "calendar");
+
+ if (rspamd_ftok_casecmp (&cal_ct, &text_part->mime_part->ct->subtype) == 0) {
+ lua_State *L = task->cfg->lua_state;
+ gint err_idx;
+
+ lua_pushcfunction (L, &rspamd_lua_traceback);
+ err_idx = lua_gettop (L);
+
+ /* Obtain function */
+ if (!rspamd_lua_require_function (L, "lua_ical", "ical_txt_values")) {
+ msg_err_task ("cannot require lua_ical.ical_txt_values");
+ lua_settop (L, err_idx - 1);
+
+ return FALSE;
+ }
+
+ lua_pushlstring (L, text_part->utf_raw_content->data,
+ text_part->utf_raw_content->len);
+
+ if (lua_pcall (L, 1, 1, err_idx) != 0) {
+ GString *tb;
+
+ tb = lua_touserdata (L, -1);
+ msg_err_task ("cannot call lua lua_ical.ical_txt_values: %s", tb->str);
+ g_string_free (tb, TRUE);
+ lua_settop (L, err_idx - 1);
+
+ return FALSE;
+ }
+
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ const char *ndata;
+ gsize nsize;
+
+ ndata = lua_tolstring (L, -1, &nsize);
+ text_part->utf_content = g_byte_array_sized_new (nsize);
+ g_byte_array_append (text_part->utf_content, ndata, nsize);
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t) free_byte_array_callback,
+ text_part->utf_content);
+ }
+ else if (lua_type (L, -1) == LUA_TNIL) {
+ msg_info_task ("cannot convert text/calendar to plain text");
+ text_part->utf_content = text_part->utf_raw_content;
+ }
+ else {
+ msg_err_task ("invalid return type when calling lua_ical.ical_txt_values: %s",
+ lua_typename (L, lua_type (L, -1)));
+ lua_settop (L, err_idx - 1);
+
+ return FALSE;
+ }
+
+ lua_settop (L, err_idx - 1);
+ }
+ else {
+ /* Just have the same content */
+ text_part->utf_content = text_part->utf_raw_content;
+ }
}
else {
/*
More information about the Commits
mailing list