message-snippet.c revision 7f7be2cbf68f8a202a688d5bc50f82483d461643
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* beginning of the line */
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen /* within normal text */
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen /* within quoted text - skip until EOL */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenstatic bool snippet_generate(struct snippet_context *ctx,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen unsigned int i, count;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mail_html2text_more(ctx->html2text, data, size,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* message-decoder should feed us only valid and complete
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen UTF-8 input */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen if (data[i] == '>' && ctx->html2text == NULL) {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* fallthrough */
eac3948d67eff8623d51aeaea9eca582f3aec677Timo Sirainenint message_snippet_generate(struct istream *input,
e376693bfa3985232c41df99c7010fca22612c89Timo Sirainen pool = pool_alloconly_create("message snippet", 1024);
e376693bfa3985232c41df99c7010fca22612c89Timo Sirainen parser = message_parser_init(pool_datastack_create(), input, 0, 0);
e376693bfa3985232c41df99c7010fca22612c89Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &raw_block)) > 0) {
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen if (!message_decoder_decode_next_block(decoder, &raw_block, &block))
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen const char *ct;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen /* end of headers - verify that we can use this
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen Content-Type. we get here only once, because we
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen always handle only one non-multipart MIME part. */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen ct = message_decoder_current_content_type(decoder);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ctx.html2text = mail_html2text_init(MAIL_HTML2TEXT_FLAG_SKIP_QUOTED);
5ada3f57a970f226eb29956d30f66afc3537200dTimo Sirainen ctx.plain_output = buffer_create_dynamic(pool, 1024);
5ada3f57a970f226eb29956d30f66afc3537200dTimo Sirainen if (!snippet_generate(&ctx, block.data, block.size))