From 5ebc4f7215714626e2a3eb6bb617a423c984a4b1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 24 Jun 2017 23:59:31 +0100 Subject: [PATCH] [Minor] Allow to fold header in a different way using Lua API --- src/lua/lua_util.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index aef1b7976..ec825c30f 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -1127,15 +1127,34 @@ lua_util_parse_addr (lua_State *L) static gint lua_util_fold_header (lua_State *L) { - const gchar *name, *value; + const gchar *name, *value, *how; GString *folded; name = luaL_checkstring (L, 1); value = luaL_checkstring (L, 2); if (name && value) { - folded = rspamd_header_value_fold (name, value, 0, - RSPAMD_TASK_NEWLINES_CRLF); + + if (lua_isstring (L, 3)) { + how = lua_tostring (L, 3); + + if (g_ascii_strcasecmp (how, "cr") == 0) { + folded = rspamd_header_value_fold (name, value, 0, + RSPAMD_TASK_NEWLINES_CR); + } + else if (g_ascii_strcasecmp (how, "lf") == 0) { + folded = rspamd_header_value_fold (name, value, 0, + RSPAMD_TASK_NEWLINES_LF); + } + else { + folded = rspamd_header_value_fold (name, value, 0, + RSPAMD_TASK_NEWLINES_CRLF); + } + } + else { + folded = rspamd_header_value_fold (name, value, 0, + RSPAMD_TASK_NEWLINES_CRLF); + } if (folded) { lua_pushlstring (L, folded->str, folded->len); -- 2.39.5