bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenbool charset_is_utf8(const char *charset ATTR_UNUSED) { return TRUE; }
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenint charset_to_utf8_begin(const char *charset ATTR_UNUSED,
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen struct charset_translation **t_r ATTR_UNUSED) { return 0; }
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenvoid charset_to_utf8_end(struct charset_translation **t ATTR_UNUSED) {}
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainencharset_to_utf8(struct charset_translation *t ATTR_UNUSED,
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen const unsigned char *src, size_t *src_size, buffer_t *dest)
19ed8f08b23d6ed204e6b27e5d1c0c6fe6bb11ddPhil Carmody " \t=?utf-8?q?=c3=a4?= =?utf-8?q?=c3=a4?= b \t\r\n ", "\xC3\xA4\xC3\xA4 b \t\r\n ",
19ed8f08b23d6ed204e6b27e5d1c0c6fe6bb11ddPhil Carmody "a =?utf-8?q?=c3=a4?=\t\t\r\n =?utf-8?q?=c3=a4?= b", "a \xC3\xA4\xC3\xA4 b",
19ed8f08b23d6ed204e6b27e5d1c0c6fe6bb11ddPhil Carmody "a =?utf-8?q?=c3=a4?= x =?utf-8?q?=c3=a4?= b", "a \xC3\xA4 x \xC3\xA4 b",
19ed8f08b23d6ed204e6b27e5d1c0c6fe6bb11ddPhil Carmody "a =?utf-8?b?w6TDpCDDpA==?= b", "a \xC3\xA4\xC3\xA4 \xC3\xA4 b",
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen unsigned int i;
82d3a1d1594ed93d04d7bf999027b3e5104de6e4Timo Sirainen message_header_decode_utf8((const unsigned char *)data[i],
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen test_assert(strcmp(str_c(dest), data[i+1]) == 0);
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainenstatic void test_message_header_decode_read_overflow(void)
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainen const unsigned char input[] = "=?utf-8?Q?=EF?=";
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainen test_begin("message header decode read overflow");
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainen message_header_decode_utf8(input, sizeof(input)-2, dest, NULL);
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainenstatic void test_message_header_decode_encode_random(void)
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainen test_begin("message header encode & decode randomly");
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainen for (i = 0; i < 1000; i++) {
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainen /* fill only with 7bit data so we don't have to worry about
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainen the data being valid UTF-8 */
2d310b66c9e541e4a3db7bac89b01534f486bb95Timo Sirainen for (j = 0; j < sizeof(buf); j++)
2d310b66c9e541e4a3db7bac89b01534f486bb95Timo Sirainen message_header_encode_q(buf, buflen, encoded, 0);
2d310b66c9e541e4a3db7bac89b01534f486bb95Timo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
2d310b66c9e541e4a3db7bac89b01534f486bb95Timo Sirainen message_header_encode_b(buf, buflen, encoded, 0);
a5f1628ad97ad649bfef86c84c3afc1d9cb0f326Timo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {