aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 17:58:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 17:58:27 +0000
commit145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac (patch)
tree7f94b740dfeb6ea8f4e93bd9d822173cc22c0660
parentdb804038ea664d0acff9c58bbb767754e115d036 (diff)
downloadrspamd-145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac.tar.gz
rspamd-145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac.zip
[Minor] Add ID to mime parts
-rw-r--r--src/libmime/message.h8
-rw-r--r--src/libmime/mime_parser.c2
-rw-r--r--src/lua/lua_mimepart.c23
3 files changed, 31 insertions, 2 deletions
diff --git a/src/libmime/message.h b/src/libmime/message.h
index 17077860d..0f5c3dfb7 100644
--- a/src/libmime/message.h
+++ b/src/libmime/message.h
@@ -51,11 +51,16 @@ struct rspamd_mime_part {
rspamd_ftok_t raw_data;
rspamd_ftok_t parsed_data;
struct rspamd_mime_part *parent_part;
- GHashTable *raw_headers;
+
GQueue *headers_order;
+ GHashTable *raw_headers;
+
gchar *raw_headers_str;
gsize raw_headers_len;
+
enum rspamd_cte cte;
+ enum rspamd_mime_part_flags flags;
+ guint id;
union {
struct rspamd_mime_multipart mp;
@@ -64,7 +69,6 @@ struct rspamd_mime_part {
struct rspamd_archive *arch;
} specific;
- enum rspamd_mime_part_flags flags;
guchar digest[rspamd_cryptobox_HASHBYTES];
};
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index c1c5c0889..2972d3389 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -510,6 +510,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
g_assert_not_reached ();
}
+ part->id = task->parts->len;
g_ptr_array_add (task->parts, part);
msg_debug_mime ("parsed data part %T/%T of length %z (%z orig), %s cte",
&part->ct->type, &part->ct->subtype, part->parsed_data.len,
@@ -815,6 +816,7 @@ rspamd_mime_parse_multipart_part (struct rspamd_task *task,
return RSPAMD_MIME_PARSE_NESTING;
}
+ part->id = task->parts->len;
g_ptr_array_add (task->parts, part);
st->nesting ++;
rspamd_mime_part_get_cte (task, part->raw_headers, part, FALSE);
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 78c3e05b9..33d1a3011 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -402,6 +402,13 @@ 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:get_id()
+ * Returns the order of the part in parts list
+ * @return {number} index of the part (starting from 1 as it is Lua API)
+ */
+LUA_FUNCTION_DEF (mimepart, get_id);
/***
* @method mime_part:is_broken()
* Returns true if mime part has incorrectly specified content type
@@ -444,6 +451,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, is_broken),
LUA_INTERFACE_DEF (mimepart, get_text),
LUA_INTERFACE_DEF (mimepart, get_digest),
+ LUA_INTERFACE_DEF (mimepart, get_id),
LUA_INTERFACE_DEF (mimepart, headers_foreach),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
@@ -1472,6 +1480,21 @@ lua_mimepart_get_digest (lua_State * L)
}
static gint
+lua_mimepart_get_id (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
+
+ if (part == NULL) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ lua_pushnumber (L, part->id);
+
+ return 1;
+}
+
+static gint
lua_mimepart_headers_foreach (lua_State *L)
{
LUA_TRACE_POINT;