test-message-address \
test-message-date \
test-message-decoder \
+ test-message-header-decode \
test-message-header-parser \
test-message-id \
test-message-parser \
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)
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)
}
/* 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
+/* 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);
+}