From: Timo Sirainen Date: Tue, 2 May 2017 09:18:40 +0000 (+0300) Subject: lib-imap: imap_append_string_for_humans() - Change CR/LF to space X-Git-Tag: 2.3.0.rc1~1671 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f950619b1d003b0e8c604478df7fe3067d934b26;p=thirdparty%2Fdovecot%2Fcore.git lib-imap: imap_append_string_for_humans() - Change CR/LF to space Practically this shouldn't matter, because in email headers a CR/LF is always followed by a space/tab. But maybe this can be used for some other purposes in future, and it makes the unit tests clearer. :) --- diff --git a/src/lib-imap/imap-quote.c b/src/lib-imap/imap-quote.c index 390463ed99..f4ff853b90 100644 --- a/src/lib-imap/imap-quote.c +++ b/src/lib-imap/imap-quote.c @@ -131,6 +131,8 @@ void imap_append_string_for_humans(string_t *dest, last_lwsp = FALSE; modify = TRUE; break; + case 13: + case 10: case '\t': modify = TRUE; /* fall through */ @@ -141,11 +143,6 @@ void imap_append_string_for_humans(string_t *dest, } last_lwsp = TRUE; break; - case 13: - case 10: - remove_count++; - modify = TRUE; - break; case '"': case '\\': modify = TRUE; @@ -188,15 +185,14 @@ void imap_append_string_for_humans(string_t *dest, str_append_c(dest, 128); last_lwsp = FALSE; break; + case 13: + case 10: case '\t': case ' ': if (!last_lwsp) str_append_c(dest, ' '); last_lwsp = TRUE; break; - case 13: - case 10: - break; default: last_lwsp = FALSE; str_append_c(dest, src[i]); diff --git a/src/lib-imap/test-imap-quote.c b/src/lib-imap/test-imap-quote.c index c67f14979e..bf9557565d 100644 --- a/src/lib-imap/test-imap-quote.c +++ b/src/lib-imap/test-imap-quote.c @@ -21,7 +21,14 @@ static void test_imap_append_string_for_humans(void) { "\t \tfoo", "{3}\r\nfoo" }, { " foo ", "{3}\r\nfoo" }, { " foo ", "{3}\r\nfoo" }, - { " foo \t \t", "{3}\r\nfoo" } + { " foo \t \t", "{3}\r\nfoo" }, + { "hello\"world", "{11}\r\nhello\"world" }, + { "hello\\world", "{11}\r\nhello\\world" }, + { "hello\rworld", "{11}\r\nhello world" }, + { "hello\nworld", "{11}\r\nhello world" }, + { "hello\r\nworld", "{11}\r\nhello world" }, + { "hello\r\n world", "{11}\r\nhello world" }, + { "hello \r\n world", "{11}\r\nhello world" }, }; string_t *str = t_str_new(128); unsigned int i; @@ -32,7 +39,7 @@ static void test_imap_append_string_for_humans(void) str_truncate(str, 0); imap_append_string_for_humans(str, (const void *)tests[i].input, strlen(tests[i].input)); - test_assert(strcmp(tests[i].output, str_c(str)) == 0); + test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i); } test_end(); }