]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
message_header_decode*() should ignore LWSP between two encoded-words.
authorTimo Sirainen <tss@iki.fi>
Sun, 13 Sep 2009 23:01:01 +0000 (19:01 -0400)
committerTimo Sirainen <tss@iki.fi>
Sun, 13 Sep 2009 23:01:01 +0000 (19:01 -0400)
--HG--
branch : HEAD

src/lib-mail/Makefile.am
src/lib-mail/message-header-decode.c
src/lib-mail/test-message-header-decode.c [new file with mode: 0644]

index fb8ba72ca08308812ca4f4d9b90ecf92213dc519..4db24a4731b94008c74d68f86ec9b0b7c1a4ad01 100644 (file)
@@ -58,6 +58,7 @@ test_programs = \
        test-message-address \
        test-message-date \
        test-message-decoder \
+       test-message-header-decode \
        test-message-header-parser \
        test-message-id \
        test-message-parser \
@@ -94,6 +95,10 @@ test_message_decoder_SOURCES = test-message-decoder.c
 test_message_decoder_LDADD = message-decoder.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs)
 test_message_decoder_DEPENDENCIES = message-decoder.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs)
 
+test_message_header_decode_SOURCES = test-message-header-decode.c
+test_message_header_decode_LDADD = message-header-decode.lo quoted-printable.lo $(test_libs)
+test_message_header_decode_DEPENDENCIES = message-header-decode.lo quoted-printable.lo $(test_libs)
+
 test_message_header_parser_SOURCES = test-message-header-parser.c
 test_message_header_parser_LDADD = message-header-parser.lo $(test_libs)
 test_message_header_parser_DEPENDENCIES = message-header-parser.lo $(test_libs)
index c0d0d2fd34c486463f2efd49a892a25d342e98f3..1d44b7028db8710ddfb2bb19b5378d2c513d9f64 100644 (file)
@@ -56,6 +56,18 @@ message_header_decode_encoded(const unsigned char *data, size_t size,
        return start_pos[2] + 2;
 }
 
+static bool is_only_lwsp(const unsigned char *data, unsigned int size)
+{
+       unsigned int i;
+
+       for (i = 0; i < size; i++) {
+               if (!(data[i] == ' ' || data[i] == '\t' ||
+                     data[i] == '\r' || data[i] == '\n'))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
 void message_header_decode(const unsigned char *data, size_t size,
                           message_header_decode_callback_t *callback,
                           void *context)
@@ -73,7 +85,8 @@ void message_header_decode(const unsigned char *data, size_t size,
                }
 
                /* encoded string beginning */
-               if (pos != start_pos) {
+               if (pos != start_pos &&
+                   !is_only_lwsp(data+start_pos, pos-start_pos)) {
                        /* send the unencoded data so far */
                        if (!callback(data + start_pos, pos - start_pos,
                                      NULL, context)) {
diff --git a/src/lib-mail/test-message-header-decode.c b/src/lib-mail/test-message-header-decode.c
new file mode 100644 (file)
index 0000000..09efbaf
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "buffer.h"
+#include "str.h"
+#include "charset-utf8.h"
+#include "message-header-decode.h"
+#include "test-common.h"
+
+bool charset_is_utf8(const char *charset ATTR_UNUSED) { return TRUE; }
+
+int charset_to_utf8_begin(const char *charset ATTR_UNUSED,
+                         enum charset_flags flags ATTR_UNUSED,
+                         struct charset_translation **t_r ATTR_UNUSED) { return 0; }
+void charset_to_utf8_end(struct charset_translation **t ATTR_UNUSED) {}
+
+enum charset_result
+charset_to_utf8(struct charset_translation *t ATTR_UNUSED,
+               const unsigned char *src, size_t *src_size, buffer_t *dest)
+{
+       buffer_append(dest, src, *src_size);
+       return CHARSET_RET_OK;
+}
+
+static void test_message_header_decode(void)
+{
+       static const char *data[] = {
+               "a =?utf-8?q?=c3=a4?= b", "a ä b",
+               "a =?utf-8?q?=c3=a4?= b", "a ä b",
+               "a =?utf-8?q?=c3=a4?=\t\t\r\n =?utf-8?q?=c3=a4?= b", "a ää b",
+               "a =?utf-8?q?=c3=a4?=  x  =?utf-8?q?=c3=a4?= b", "a ä  x  ä b",
+               "a =?utf-8?b?w6TDpCDDpA==?= b", "a ää ä b",
+               "=?utf-8?b?w6Qgw6Q=?=", "ä ä",
+       };
+       string_t *dest;
+       unsigned int i;
+
+       test_begin("message header decode");
+
+       dest = t_str_new(256);
+       for (i = 0; i < N_ELEMENTS(data); i += 2) {
+               str_truncate(dest, 0);
+               test_assert(message_header_decode_utf8((const unsigned char *)data[i],
+                                                      strlen(data[i]),
+                                                      dest, FALSE));
+               test_assert(strcmp(str_c(dest), data[i+1]) == 0);
+       }
+       test_end();
+}
+
+int main(void)
+{
+       static void (*test_functions[])(void) = {
+               test_message_header_decode,
+               NULL
+       };
+       return test_run(test_functions);
+}