]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: imap_append_string_for_humans() - Change CR/LF to space
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 2 May 2017 09:18:40 +0000 (12:18 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 3 May 2017 09:20:12 +0000 (12:20 +0300)
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. :)

src/lib-imap/imap-quote.c
src/lib-imap/test-imap-quote.c

index 390463ed99e93f242aa420f9ec0587a63b0974b7..f4ff853b90826db00f76cfa3c5b009089d51dad2 100644 (file)
@@ -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]);
index c67f14979e6d57cae4f09f4b5d9012ff86277023..bf9557565dbdbab7cdcc7aac9e55b717b3b6b691 100644 (file)
@@ -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();
 }