aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libmime/message.c4
-rw-r--r--src/libmime/message.h2
-rw-r--r--src/lua/lua_mimepart.c62
3 files changed, 65 insertions, 3 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 0d495fcd8..b2d37890c 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -459,7 +459,7 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
part->non_spaces ++;
if (G_UNLIKELY (*p & 0x80)) {
- part->non_aciii_chars ++;
+ part->non_ascii_chars ++;
}
else {
part->ascii_chars ++;
@@ -515,7 +515,7 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
part->non_spaces ++;
if (G_UNLIKELY (*p & 0x80)) {
- part->non_aciii_chars ++;
+ part->non_ascii_chars ++;
}
else {
part->ascii_chars ++;
diff --git a/src/libmime/message.h b/src/libmime/message.h
index 599521f6f..8dc06eb3a 100644
--- a/src/libmime/message.h
+++ b/src/libmime/message.h
@@ -96,7 +96,7 @@ struct rspamd_mime_text_part {
GArray *normalized_hashes;
guint nlines;
guint spaces;
- guint non_aciii_chars;
+ guint non_ascii_chars;
guint ascii_chars;
guint double_spaces;
guint non_spaces;
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index d83125044..75b270189 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -108,6 +108,18 @@ LUA_FUNCTION_DEF (textpart, get_urls_length);
*/
LUA_FUNCTION_DEF (textpart, get_lines_count);
/***
+ * @method mime_part:get_stats()
+ * Returns a table with the following data:
+ * - `lines`: number of lines
+ * - `spaces`: number of spaces
+ * - `double_spaces`: double spaces
+ * - `empty_lines`: number of empty lines
+ * - `non_ascii_characters`: number of non ascii characters
+ * - `ascii_characters`: number of ascii characters
+ * @return {table} table of stats
+ */
+LUA_FUNCTION_DEF (textpart, get_stats);
+/***
* @method mime_part:get_words_count()
* Get words number in the part
* @return {integer} number of words in the part
@@ -161,6 +173,7 @@ static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, get_html),
LUA_INTERFACE_DEF (textpart, get_language),
LUA_INTERFACE_DEF (textpart, get_mimepart),
+ LUA_INTERFACE_DEF (textpart, get_stats),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
@@ -715,6 +728,55 @@ lua_textpart_get_mimepart (lua_State * L)
return 1;
}
+/***
+ * @method mime_part:get_stats()
+ * Returns a table with the following data:
+ * -
+ * - `lines`: number of lines
+ * - `spaces`: number of spaces
+ * - `double_spaces`: double spaces
+ * - `empty_lines`: number of empty lines
+ * - `non_ascii_characters`: number of non ascii characters
+ * - `ascii_characters`: number of ascii characters
+ * @return {table} table of stats
+ */
+static gint
+lua_textpart_get_stats (lua_State * L)
+{
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
+
+ if (part != NULL) {
+ lua_createtable (L, 0, 7);
+
+ lua_pushstring (L, "lines");
+ lua_pushnumber (L, part->nlines);
+ lua_settable (L, -3);
+ lua_pushstring (L, "empty_lines");
+ lua_pushnumber (L, part->empty_lines);
+ lua_settable (L, -3);
+ lua_pushstring (L, "spaces");
+ lua_pushnumber (L, part->spaces);
+ lua_settable (L, -3);
+ lua_pushstring (L, "non_spaces");
+ lua_pushnumber (L, part->non_spaces);
+ lua_settable (L, -3);
+ lua_pushstring (L, "double_spaces");
+ lua_pushnumber (L, part->double_spaces);
+ lua_settable (L, -3);
+ lua_pushstring (L, "ascii_characters");
+ lua_pushnumber (L, part->ascii_chars);
+ lua_settable (L, -3);
+ lua_pushstring (L, "non_ascii_characters");
+ lua_pushnumber (L, part->non_ascii_chars);
+ lua_settable (L, -3);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
/* Mimepart implementation */
static gint