]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow to fold headers on stop characters
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Mar 2018 12:25:34 +0000 (13:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Mar 2018 12:25:34 +0000 (13:25 +0100)
src/client/rspamc.c
src/libserver/protocol.c
src/libutil/str_util.c
src/libutil/str_util.h
src/lua/lua_util.c

index 2bd1376072329d165f682dd8e4ed53d059cc5a22..a8139d1cabee38c183665def09e6c99829c3cdf7 100644 (file)
@@ -1339,9 +1339,9 @@ rspamc_mime_output (FILE *out, ucl_object_t *result, GString *input,
 
                folded_symbuf = rspamd_header_value_fold ("X-Spam-Symbols",
                                symbuf->str,
-                               0, nl_type);
+                               0, nl_type, ",");
                rspamd_printf_gstring (added_headers, "X-Spam-Symbols: %v%s",
-                               folded_symbuf, line_end);
+                               folded_symbuf, line_end, ",");
 
                g_string_free (folded_symbuf, TRUE);
                g_string_free (symbuf, TRUE);
index 77bbe04bfd1f6c82af9fcbb12e304d79625e8179..421e36574c851b24a7bac637aaa817f57f9a72da 100644 (file)
@@ -1127,11 +1127,11 @@ rspamd_protocol_write_ucl (struct rspamd_task *task,
 
                        if (task->flags & RSPAMD_TASK_FLAG_MILTER) {
                                folded_header = rspamd_header_value_fold ("DKIM-Signature",
-                                               dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF);
+                                               dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF, NULL);
                        }
                        else {
                                folded_header = rspamd_header_value_fold ("DKIM-Signature",
-                                               dkim_sig->str, 80, task->nlines_type);
+                                               dkim_sig->str, 80, task->nlines_type, NULL);
                        }
                        /*
                         * According to milter docs, we need to be extra careful
index 7d346354fc3f51309e3b74c7fdec69af52b51979..238f95c87fdf5867be3ab980def4319f9d107189 100644 (file)
@@ -918,7 +918,8 @@ GString *
 rspamd_header_value_fold (const gchar *name,
                const gchar *value,
                guint fold_max,
-               enum rspamd_newlines_type how)
+               enum rspamd_newlines_type how,
+               const gchar *fold_on_chars)
 {
        GString *res;
        const guint default_fold_max = 76;
@@ -1019,6 +1020,13 @@ rspamd_header_value_fold (const gchar *name,
                                        cur_len ++;
                                }
                        }
+                       else if (fold_on_chars && strchr (fold_on_chars, *p) != NULL) {
+                               fold_type = fold_after;
+                               state = fold_token;
+                               next_state = read_token;
+
+                               p ++;
+                       }
                        else {
                                p ++;
                                cur_len ++;
index 68ec5f0bda93e1bd48e48182684fe1fadb0e16ac..5f0695c2a025f8b5cade08efee5c108ed3faf306 100644 (file)
@@ -242,12 +242,16 @@ gint rspamd_strings_levenshtein_distance (const gchar *s1, gsize s1len,
  * Fold header using rfc822 rules, return new GString from the previous one
  * @param name name of header (used just for folding)
  * @param value value of header
+ * @param fold_max
+ * @param how
+ * @param fold_on_chars
  * @return new GString with the folded value
  */
 GString *rspamd_header_value_fold (const gchar *name,
                const gchar *value,
                guint fold_max,
-               enum rspamd_newlines_type how);
+               enum rspamd_newlines_type how,
+               const gchar *fold_on_chars);
 
 /**
  * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm
index a14de69f3adca5ffa5e4af8866ed39301ee806d9..46f103f1a89f12216bfea3d6a1106f2d49d12964 100644 (file)
@@ -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) {