bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* beginning of the line */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* within normal text */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* within quoted text - skip until EOL */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic bool snippet_generate(struct snippet_context *ctx,
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen mail_html2text_more(ctx->html2text, data, size,
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* message-decoder should feed us only valid and complete
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen UTF-8 input */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (data[i] == '>' && ctx->html2text == NULL) {
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* fallthrough */
099737facc44553349a15521cdfcc65b112054caTimo Sirainen ((data[i] == 0xEF && data[i+1] == 0xBB && data[i+2] == 0xBF) ||
099737facc44553349a15521cdfcc65b112054caTimo Sirainen (data[i] == 0xBF && data[i+1] == 0xBB && data[i+2] == 0xEF))) {
73083841b92505091b7d1070554930651b91b701Aki Tuomi /* skip any leading whitespace */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenint message_snippet_generate(struct istream *input,
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen pool = pool_alloconly_create("message snippet", 1024);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen parser = message_parser_init(pool_datastack_create(), input, 0, 0);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &raw_block)) > 0) {
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (!message_decoder_decode_next_block(decoder, &raw_block, &block))
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* end of headers - verify that we can use this
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen Content-Type. we get here only once, because we
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen always handle only one non-multipart MIME part. */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen ct = message_decoder_current_content_type(decoder);
00a50d6dc74e15b5b83afcb8c12c2109a2ca376dTimo Sirainen else if (mail_html2text_content_type_match(ct)) {
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen ctx.html2text = mail_html2text_init(MAIL_HTML2TEXT_FLAG_SKIP_QUOTED);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen ctx.plain_output = buffer_create_dynamic(pool, 1024);