Mercurial > dovecot > core-2.2
changeset 9934:9444d7964766 HEAD
message_header_decode*() should ignore LWSP between two encoded-words.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 13 Sep 2009 19:01:01 -0400 |
parents | 27904121ae72 |
children | 364ee96c6195 |
files | src/lib-mail/Makefile.am src/lib-mail/message-header-decode.c src/lib-mail/test-message-header-decode.c |
diffstat | 3 files changed, 77 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-mail/Makefile.am Sun Sep 13 18:37:05 2009 -0400 +++ b/src/lib-mail/Makefile.am Sun Sep 13 19:01:01 2009 -0400 @@ -58,6 +58,7 @@ 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_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)
--- a/src/lib-mail/message-header-decode.c Sun Sep 13 18:37:05 2009 -0400 +++ b/src/lib-mail/message-header-decode.c Sun Sep 13 19:01:01 2009 -0400 @@ -56,6 +56,18 @@ 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 @@ } /* 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)) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/test-message-header-decode.c Sun Sep 13 19:01:01 2009 -0400 @@ -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); +}