aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-29 17:20:57 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-29 17:20:57 +0100
commitd85fd8877d691aab88a18c6d54cd72e1198a6844 (patch)
treee6c456cb3878005ce5cc5750b43f295e8278c9df /src
parente487db32bc47aadb69753cffbb6c554a3153dc00 (diff)
downloadrspamd-d85fd8877d691aab88a18c6d54cd72e1198a6844.tar.gz
rspamd-d85fd8877d691aab88a18c6d54cd72e1198a6844.zip
[Fix] Fix folding and folding tests
Diffstat (limited to 'src')
-rw-r--r--src/libutil/str_util.c129
1 files changed, 61 insertions, 68 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 238f95c87..29df7e744 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -955,72 +955,7 @@ rspamd_header_value_fold (const gchar *name,
while (*p) {
switch (state) {
case read_token:
- if (*p == ',' || *p == ';') {
- /* We have something similar to the token's end, so check len */
- if (cur_len > fold_max * 0.8 && cur_len < fold_max) {
- /* We want fold */
- fold_type = fold_after;
- state = fold_token;
- next_state = read_token;
- }
- else if (cur_len > fold_max && !first_token) {
- fold_type = fold_before;
- state = fold_token;
- next_state = read_token;
- }
- else {
- g_string_append_len (res, c, p - c + 1);
- c = p + 1;
- first_token = FALSE;
- }
- p ++;
- }
- else if (*p == '"') {
- /* Fold before quoted tokens */
- g_string_append_len (res, c, p - c);
- c = p;
- state = read_quoted;
- }
- else if (*p == '\r' || *p == '\n') {
- if (cur_len > fold_max && !first_token) {
- fold_type = fold_before;
- state = fold_token;
- next_state = read_token;
- }
- else {
- /* Reset line length */
- cur_len = 0;
-
- while (g_ascii_isspace (*p)) {
- p ++;
- }
-
- g_string_append_len (res, c, p - c);
- c = p;
- first_token = TRUE;
- }
- }
- else if (g_ascii_isspace (*p)) {
- if (cur_len > fold_max * 0.8 && cur_len < fold_max) {
- /* We want fold */
- fold_type = fold_after;
- state = fold_token;
- next_state = read_token;
- }
- else if (cur_len > fold_max && !first_token) {
- fold_type = fold_before;
- state = fold_token;
- next_state = read_token;
- }
- else {
- g_string_append_len (res, c, p - c);
- c = p;
- first_token = FALSE;
- p ++;
- cur_len ++;
- }
- }
- else if (fold_on_chars && strchr (fold_on_chars, *p) != NULL) {
+ if (fold_on_chars && strchr (fold_on_chars, *p) != NULL) {
fold_type = fold_after;
state = fold_token;
next_state = read_token;
@@ -1028,8 +963,66 @@ rspamd_header_value_fold (const gchar *name,
p ++;
}
else {
- p ++;
- cur_len ++;
+ if (*p == ',' || *p == ';') {
+ /* We have something similar to the token's end, so check len */
+ if (cur_len > fold_max * 0.8 && cur_len < fold_max) {
+ /* We want fold */
+ fold_type = fold_after;
+ state = fold_token;
+ next_state = read_token;
+ } else if (cur_len > fold_max && !first_token) {
+ fold_type = fold_before;
+ state = fold_token;
+ next_state = read_token;
+ } else {
+ g_string_append_len (res, c, p - c + 1);
+ c = p + 1;
+ first_token = FALSE;
+ }
+ p++;
+ } else if (*p == '"') {
+ /* Fold before quoted tokens */
+ g_string_append_len (res, c, p - c);
+ c = p;
+ state = read_quoted;
+ } else if (*p == '\r' || *p == '\n') {
+ if (cur_len > fold_max && !first_token) {
+ fold_type = fold_before;
+ state = fold_token;
+ next_state = read_token;
+ } else {
+ /* Reset line length */
+ cur_len = 0;
+
+ while (g_ascii_isspace (*p)) {
+ p++;
+ }
+
+ g_string_append_len (res, c, p - c);
+ c = p;
+ first_token = TRUE;
+ }
+ } else if (g_ascii_isspace (*p)) {
+ if (cur_len > fold_max * 0.8 && cur_len < fold_max) {
+ /* We want fold */
+ fold_type = fold_after;
+ state = fold_token;
+ next_state = read_token;
+ } else if (cur_len > fold_max && !first_token) {
+ fold_type = fold_before;
+ state = fold_token;
+ next_state = read_token;
+ } else {
+ g_string_append_len (res, c, p - c);
+ c = p;
+ first_token = FALSE;
+ p++;
+ cur_len++;
+ }
+ } else {
+ p++;
+ cur_len++;
+ }
}
break;
case fold_token: