]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_header_hash() - add v4 that strips tabs
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Jul 2017 07:57:36 +0000 (10:57 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Jul 2017 09:19:40 +0000 (12:19 +0300)
This helps with Zimbra, which strips away trailing tabs in BODY[HEADER].

src/lib-mail/message-header-hash.c
src/lib-mail/message-header-hash.h
src/lib-mail/test-message-header-hash.c

index d4265d5ba9a7c7ed888949274f20235bdda10b99..070af041689fb3611e64205fd44bd583be617c10 100644 (file)
@@ -30,22 +30,28 @@ void message_header_hash_more(struct message_header_hash_context *ctx,
           remove any repeated '?', which hopefully will satisfy everybody.
 
           Also:
-          - Zimbra removes trailing spaces from IMAP BODY[HEADER], but not
-          IMAP BODY[] or POP3 TOP. Just strip away all spaces with version 3.
-
+          - Zimbra removes trailing spaces and tabs from IMAP BODY[HEADER],
+          but not IMAP BODY[] or POP3 TOP. Just strip away all spaces with
+          version 3 and tabs also with version 4.
        */
        for (i = start = 0; i < size; i++) {
                bool cur_is_questionmark = FALSE;
 
                switch (data[i]) {
                case ' ':
-                       if (version == 3) {
+                       if (version >= 3) {
                                /* strip away spaces */
                                method->loop(context, data + start, i-start);
                                start = i+1;
                        }
                        break;
                case '\t':
+                       if (version >= 4) {
+                               /* strip away tabs */
+                               method->loop(context, data + start, i-start);
+                               start = i+1;
+                       }
+                       break;
                case '\n':
                        break;
                default:
index 4183ed2f9e8ee5fc145e07a5c1d19f64fd3b0f6e..633d0c1e86fe9939b07d9f58d7e6ad83116ea2a1 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MESSAGE_HEADER_HASH_H
 #define MESSAGE_HEADER_HASH_H
 
-#define MESSAGE_HEADER_HASH_MAX_VERSION 3
+#define MESSAGE_HEADER_HASH_MAX_VERSION 4
 
 struct hash_method;
 
index 1bcc5ecfd9039c506677f97f3a6bdc3c4bdbd44c..c1f8cde6c89047ccd52ccbc9d90fa5311bdc42e1 100644 (file)
@@ -31,12 +31,20 @@ static const struct {
        { "? ? ? hi \x01\x02   \x03   ", 2, "? ? ? hi ?   ?   " },
 
        { test_input_with_nuls, 3, "?\t\n?!?x?yz?-plop?" },
-       { "\n\nhi\n\n", 2, "\n\nhi\n\n" },
+       { "\n\nhi\n\n", 3, "\n\nhi\n\n" },
        { "", 3, "" },
        { " ", 3, "" },
        { "   ", 3, "" },
        { " ? ", 3, "?" },
        { "? ? ? hi \x01\x02   \x03   ", 3, "???hi??" },
+       { " \t \t", 3, "\t\t" },
+
+       { test_input_with_nuls, 4, "?\n?!?x?yz?-plop?" },
+       { "\n\nhi\n\n", 4, "\n\nhi\n\n" },
+       { "", 4, "" },
+       { " ", 4, "" },
+       { " \t \t", 4, "" },
+       { "foo\t\t", 4, "foo" },
 };
 
 static void test_message_header_hash_more(void)