From: Timo Sirainen Date: Wed, 19 Jul 2017 07:57:36 +0000 (+0300) Subject: lib-mail: message_header_hash() - add v4 that strips tabs X-Git-Tag: 2.2.32.rc1~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=736eaae8f15cf4208754c3825b7ab0ef69c3250b;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: message_header_hash() - add v4 that strips tabs This helps with Zimbra, which strips away trailing tabs in BODY[HEADER]. --- diff --git a/src/lib-mail/message-header-hash.c b/src/lib-mail/message-header-hash.c index d4265d5ba9..070af04168 100644 --- a/src/lib-mail/message-header-hash.c +++ b/src/lib-mail/message-header-hash.c @@ -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: diff --git a/src/lib-mail/message-header-hash.h b/src/lib-mail/message-header-hash.h index 4183ed2f9e..633d0c1e86 100644 --- a/src/lib-mail/message-header-hash.h +++ b/src/lib-mail/message-header-hash.h @@ -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; diff --git a/src/lib-mail/test-message-header-hash.c b/src/lib-mail/test-message-header-hash.c index 1bcc5ecfd9..c1f8cde6c8 100644 --- a/src/lib-mail/test-message-header-hash.c +++ b/src/lib-mail/test-message-header-hash.c @@ -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)