Mercurial > dovecot > core-2.2
changeset 22036:8ae3f141b7a4
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. :)
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 02 May 2017 12:18:40 +0300 |
parents | 86b3bb91add1 |
children | 7d09937dc4ff |
files | src/lib-imap/imap-quote.c src/lib-imap/test-imap-quote.c |
diffstat | 2 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap/imap-quote.c Fri May 12 11:13:09 2017 +0300 +++ b/src/lib-imap/imap-quote.c Tue May 02 12:18:40 2017 +0300 @@ -131,6 +131,8 @@ last_lwsp = FALSE; modify = TRUE; break; + case 13: + case 10: case '\t': modify = TRUE; /* fall through */ @@ -141,11 +143,6 @@ } last_lwsp = TRUE; break; - case 13: - case 10: - remove_count++; - modify = TRUE; - break; case '"': case '\\': modify = TRUE; @@ -188,15 +185,14 @@ 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]);
--- a/src/lib-imap/test-imap-quote.c Fri May 12 11:13:09 2017 +0300 +++ b/src/lib-imap/test-imap-quote.c Tue May 02 12:18:40 2017 +0300 @@ -21,7 +21,14 @@ { "\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 @@ 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(); }