@@ -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); |
@@ -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 |
@@ -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 ++; |
@@ -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 |
@@ -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) { |