bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen#include "lib.h"
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen#include "message-parser.h"
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen#include "fts-parser.h"
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen#include <unistd.h>
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainenint main(void)
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen{
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen struct fts_parser *parser;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen unsigned char buf[IO_BLOCK_SIZE];
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen struct message_block block;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen ssize_t ret;
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov struct fts_parser_context parser_context = {.content_type = "text/html"};
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen lib_init();
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov parser = fts_parser_html.try_init(&parser_context);
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen i_assert(parser != NULL);
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&block);
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen while ((ret = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen block.data = buf;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen block.size = ret;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen parser->v.more(parser, &block);
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen if (write(STDOUT_FILENO, block.data, block.size) < 0)
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen i_fatal("write(stdout) failed: %m");
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen }
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen if (ret < 0)
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen i_fatal("read(stdin) failed: %m");
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen for (;;) {
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen block.size = 0;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen parser->v.more(parser, &block);
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen if (block.size == 0)
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen break;
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen if (write(STDOUT_FILENO, block.data, block.size) < 0)
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen i_fatal("write(stdout) failed: %m");
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen }
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen lib_deinit();
de1ba3e655a7de31c5522911ee0ba18bc65f05afTimo Sirainen return 0;
04f80fbc38561c95cd3f71a4c8fd3cd48a9c78d4Timo Sirainen}