summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-28 13:25:34 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-28 13:25:34 +0100
commita709da98c462abc9f6b08e4288525ad92698685f (patch)
tree520f84f168210f31cb9c9585db1d590cfb74882e /src/lua/lua_util.c
parent8fb798b5091a66c39aeef381ebb5afd1b345b690 (diff)
downloadrspamd-a709da98c462abc9f6b08e4288525ad92698685f.tar.gz
rspamd-a709da98c462abc9f6b08e4288525ad92698685f.zip
[Feature] Allow to fold headers on stop characters
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r--src/lua/lua_util.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index a14de69f3..46f103f1a 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -135,11 +135,13 @@ LUA_FUNCTION_DEF (util, levenshtein_distance);
LUA_FUNCTION_DEF (util, parse_addr);
/***
- * @function util.fold_header(name, value)
+ * @function util.fold_header(name, value, [how, [stop_chars]])
* Fold rfc822 header according to the folding rules
*
* @param {string} name name of the header
* @param {string} value value of the header
+ * @param {string} how "cr" for \r, "lf" for \n and "crlf" for \r\n (default)
+ * @param {string} stop_chars also fold header when the
* @return {string} Folded value of the header
*/
LUA_FUNCTION_DEF (util, fold_header);
@@ -1178,7 +1180,7 @@ lua_util_parse_addr (lua_State *L)
static gint
lua_util_fold_header (lua_State *L)
{
- const gchar *name, *value, *how;
+ const gchar *name, *value, *how, *stop_chars = NULL;
GString *folded;
name = luaL_checkstring (L, 1);
@@ -1187,24 +1189,29 @@ lua_util_fold_header (lua_State *L)
if (name && value) {
if (lua_isstring (L, 3)) {
+
how = lua_tostring (L, 3);
+ if (lua_isstring (L, 4)) {
+ stop_chars = lua_tostring (L, 4);
+ }
+
if (strcmp (how, "cr") == 0) {
folded = rspamd_header_value_fold (name, value, 0,
- RSPAMD_TASK_NEWLINES_CR);
+ RSPAMD_TASK_NEWLINES_CR, stop_chars);
}
else if (strcmp (how, "lf") == 0) {
folded = rspamd_header_value_fold (name, value, 0,
- RSPAMD_TASK_NEWLINES_LF);
+ RSPAMD_TASK_NEWLINES_LF, stop_chars);
}
else {
folded = rspamd_header_value_fold (name, value, 0,
- RSPAMD_TASK_NEWLINES_CRLF);
+ RSPAMD_TASK_NEWLINES_CRLF, stop_chars);
}
}
else {
folded = rspamd_header_value_fold (name, value, 0,
- RSPAMD_TASK_NEWLINES_CRLF);
+ RSPAMD_TASK_NEWLINES_CRLF, stop_chars);
}
if (folded) {