From a709da98c462abc9f6b08e4288525ad92698685f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 28 Mar 2018 13:25:34 +0100 Subject: [Feature] Allow to fold headers on stop characters --- src/lua/lua_util.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/lua/lua_util.c') 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) { -- cgit v1.2.3