]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to fold header in a different way using Lua API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 24 Jun 2017 22:59:31 +0000 (23:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 24 Jun 2017 22:59:31 +0000 (23:59 +0100)
src/lua/lua_util.c

index aef1b79762c623ea5e690170cc20e1fea8d1b0bf..ec825c30f35adef33484361d4b9bfeb5f12aa774 100644 (file)
@@ -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);