bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
b7324e421e2132cbbf753e6fdbe675bbaecdf929Timo Sirainenstatic const struct {
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a&<♣>b",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen "a&<\xE2\x99\xA3>b" },
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<style>stylesheet is ignored</style>b",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<stylea>b</stylea>c",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<!--x <p foo=\"bar\">commented tags ignored also</p> y-->b",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<script>javascript <p>foo</p> ignored</script>b",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<scripta>b</scripta>c",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<blockquote><blockquote>second level</blockquote>ignored</blockquote>b",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen { "a<![CDATA[<style>]] >b</style>]]>c",
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen "a<style>]] >b</style>c" },
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen "a<blockquote>b<blockquote><blockquote>c</blockquote>d</blockquote>e</blockquote>f";
c9141125278100269eb3a907c911afe78c46717cTimo Sirainenstatic const char *test_blockquote_output = "a b c d e f";
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen unsigned int i, j;
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen ht = mail_html2text_init(MAIL_HTML2TEXT_FLAG_SKIP_QUOTED);
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen test_assert_idx(strcmp(str_c(str), tests[i].output) == 0, i);
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen /* test without skipping quoted */
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen mail_html2text_more(ht, (const void *)test_blockquote_input,
c9141125278100269eb3a907c911afe78c46717cTimo Sirainen test_assert(strcmp(str_c(str), test_blockquote_output) == 0);
0bbddb0182685d0bb12973d8263bdb66415ae37aTimo Sirainen for (unsigned int i = 0; i < 1000; i++) {
0bbddb0182685d0bb12973d8263bdb66415ae37aTimo Sirainen char valid_chars[] = { '0', 'a', '<', '>', '&', ';', '\\', '\'', '"', '/' };
0bbddb0182685d0bb12973d8263bdb66415ae37aTimo Sirainen unsigned char s[2];
0bbddb0182685d0bb12973d8263bdb66415ae37aTimo Sirainen for (unsigned int i = 0; i < 100; i++) {
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek s[0] = valid_chars[i_rand_limit(N_ELEMENTS(valid_chars))];
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek s[1] = valid_chars[i_rand_limit(N_ELEMENTS(valid_chars))];
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek mail_html2text_more(ht, s, i_rand_minmax(1, 2), str);
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {