From 53a377bc6814a3335fac4f2c457ed4e3b26738df Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 12 Jun 2017 14:24:59 +0300 Subject: [PATCH] pop3-migration: Strip trailing spaces from headers when calculating hash Fixes matching mails with Zimbra. --- .../pop3-migration/pop3-migration-plugin.c | 16 +++++++++++++++- .../pop3-migration/test-pop3-migration-plugin.c | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugins/pop3-migration/pop3-migration-plugin.c b/src/plugins/pop3-migration/pop3-migration-plugin.c index 80bead91c8..4a4f6a42a2 100644 --- a/src/plugins/pop3-migration/pop3-migration-plugin.c +++ b/src/plugins/pop3-migration/pop3-migration-plugin.c @@ -171,7 +171,21 @@ pop3_header_filter_callback(struct header_filter_istream *input ATTR_UNUSED, /* Yahoo IMAP drops headers with invalid names, while Yahoo POP3 preserves them. Drop them all. */ *matched = TRUE; - } + } else if (hdr->value_len > 0 && + hdr->value[hdr->value_len-1] == ' ') T_BEGIN { + /* Delete trailing whitespace. Zimbra is stripping it + away with BODY[HEADER]. */ + struct message_header_line new_hdr = *hdr; + while (new_hdr.value_len > 0 && + new_hdr.value[new_hdr.value_len-1] == ' ') + new_hdr.value_len--; + new_hdr.crlf_newline = FALSE; /* CRs are stripped */ + string_t *new_line = t_str_new(128); + message_header_line_write(new_line, &new_hdr); + i_stream_header_filter_add(input, str_data(new_line), + str_len(new_line)); + *matched = TRUE; + } T_END; } } diff --git a/src/plugins/pop3-migration/test-pop3-migration-plugin.c b/src/plugins/pop3-migration/test-pop3-migration-plugin.c index b8db7fe0b4..49d6c87808 100644 --- a/src/plugins/pop3-migration/test-pop3-migration-plugin.c +++ b/src/plugins/pop3-migration/test-pop3-migration-plugin.c @@ -17,6 +17,9 @@ static void test_pop3_migration_get_hdr_sha1(void) { "", "da39a3ee5e6b4b0d3255bfef95601890afd80709", FALSE }, { "\n", "adc83b19e793491b1c6ea0fd8b46cd9f32e592fc", TRUE }, { "a: b\r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", FALSE }, + { "a: b \r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", FALSE }, + { "a: b \r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", FALSE }, + { "a: b \r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", FALSE }, { "a: b\r\n\r\n", "d14841695e1d9e2de6625d9222abd149ec821b0d", TRUE }, { "a: b\r\n\r\r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", FALSE }, { "a: b\r\n\r\r\nc: d\r\n\r\n", "3edb5ce145cf1d1e2413e02b8bed70f1ae3ed105", TRUE }