diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-28 13:25:34 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-28 13:25:34 +0100 |
commit | a709da98c462abc9f6b08e4288525ad92698685f (patch) | |
tree | 520f84f168210f31cb9c9585db1d590cfb74882e | |
parent | 8fb798b5091a66c39aeef381ebb5afd1b345b690 (diff) | |
download | rspamd-a709da98c462abc9f6b08e4288525ad92698685f.tar.gz rspamd-a709da98c462abc9f6b08e4288525ad92698685f.zip |
[Feature] Allow to fold headers on stop characters
-rw-r--r-- | src/client/rspamc.c | 4 | ||||
-rw-r--r-- | src/libserver/protocol.c | 4 | ||||
-rw-r--r-- | src/libutil/str_util.c | 10 | ||||
-rw-r--r-- | src/libutil/str_util.h | 6 | ||||
-rw-r--r-- | src/lua/lua_util.c | 19 |
5 files changed, 31 insertions, 12 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 2bd137607..a8139d1ca 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -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); diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 77bbe04bf..421e36574 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -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 diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 7d346354f..238f95c87 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -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 ++; diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index 68ec5f0bd..5f0695c2a 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -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 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) { |