istream-header-filter.c revision 270c7cd669b1ad4b69edb366dc5f22262948bfed
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2003-2016 Dovecot authors, see the included COPYING file */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen const char **headers;
73083841b92505091b7d1070554930651b91b701Aki Tuomiheader_filter_callback *null_header_filter_callback = NULL;
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic ssize_t i_stream_header_filter_read(struct istream_private *stream);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic void i_stream_header_filter_destroy(struct iostream_private *stream)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen message_parse_header_deinit(&mstream->hdr_ctx);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (array_is_created(&mstream->match_change_lines))
73083841b92505091b7d1070554930651b91b701Aki Tuomiread_mixed(struct header_filter_istream *mstream, size_t body_highwater_size)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen const unsigned char *data;
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen data = i_stream_get_data(mstream->istream.parent, &pos);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen mstream->istream.istream.eof = mstream->istream.parent->eof;
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (mstream->end_body_with_lf && data[pos-1] != '\n' &&
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen /* add missing trailing LF to body */
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen data = i_stream_get_data(mstream->istream.parent, &pos);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen buffer_append(mstream->hdr_buf, data + body_highwater_size,
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen mstream->istream.buffer = buffer_get_data(mstream->hdr_buf, &pos);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen ret = (ssize_t)(pos - mstream->istream.pos - mstream->istream.skip);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic int cmp_uint(const unsigned int *i1, const unsigned int *i2)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic bool match_line_changed(struct header_filter_istream *mstream)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (!array_is_created(&mstream->match_change_lines))
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen return array_bsearch(&mstream->match_change_lines, &mstream->cur_line,
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic void add_eol(struct header_filter_istream *mstream, bool orig_crlf)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen if (mstream->crlf || (orig_crlf && mstream->crlf_preserve))
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainenstatic ssize_t hdr_stream_update_pos(struct header_filter_istream *mstream)
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen mstream->istream.buffer = buffer_get_data(mstream->hdr_buf, &pos);
7f7be2cbf68f8a202a688d5bc50f82483d461643Timo Sirainen ret = (ssize_t)(pos - mstream->istream.pos - mstream->istream.skip);
return ret;
int hdr_ret;
NULL, 0);
&hdr)) > 0) {
bool matched;
if (!matched) {
if (hdr_ret < 0) {
if (hdr_ret == 0) {
return ret;
if (ret == 0) {
return ret;
static ssize_t
const unsigned char *data;
bool last_lf;
else if (size > 0)
return ret;
return ret;
return ret;
if (v_offset == 0) {
static void ATTR_NORETURN
struct istream *
const char *const *headers,
unsigned int headers_count,
int ret;
for (i = j = 0; i < headers_count; i++) {
if (ret == 0) {