istream-header-filter.c revision 01e606cda5192c4254c090624a0b2ca92da6da8e
/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "message-parser.h"
#include "istream-internal.h"
#include "istream-header-filter.h"
#include <stdlib.h>
struct header_filter_istream {
struct istream_private istream;
struct message_header_parser_ctx *hdr_ctx;
const char **headers;
unsigned int headers_count;
void *context;
struct message_size header_size;
unsigned int cur_line, parsed_lines;
ARRAY_DEFINE(match_change_lines, unsigned int);
unsigned int header_read:1;
unsigned int seen_eoh:1;
unsigned int header_parsed:1;
unsigned int exclude:1;
unsigned int crlf:1;
unsigned int hide_body:1;
unsigned int add_missing_eoh:1;
};
{
struct header_filter_istream *mstream =
(struct header_filter_istream *)stream;
}
static ssize_t
{
const unsigned char *data;
return -1;
}
if (pos == body_highwater_size) {
if (ret <= 0)
return ret;
}
return ret;
}
{
}
{
const unsigned int *lines;
unsigned int count;
return FALSE;
}
{
else
}
{
struct message_header_line *hdr;
bool matched;
int hdr_ret;
NULL, 0);
}
/* remove skipped data from hdr_buf */
if (mstream->header_read) {
/* we want to return mixed headers and body */
}
}
&hdr)) > 0) {
if (!mstream->header_parsed &&
}
if (!matched)
continue;
continue;
}
bsearch_strcasecmp) != NULL;
/* nothing gets excluded */
/* first time in this line */
bool orig_matched = matched;
if (matched != orig_matched) {
}
} else {
/* second time in this line. was it excluded by the
callback the first time? */
if (match_line_changed(mstream))
}
/* ignore */
} else {
}
if (!hdr->no_newline)
/* we need more */
} else {
if (mstream->skip_count > 0) {
mstream->skip_count = 0;
}
break;
}
}
}
if (hdr_ret < 0) {
return -1;
}
}
}
/* don't copy eof here because we're only returning headers here.
the body will be returned in separate read() call. */
if (hdr_ret == 0) {
/* need more data to finish parsing headers. we may have some
data already available though. */
return ret;
}
/* finished */
}
if (ret == 0) {
/* we're at the end of headers. */
return read_header(mstream);
}
return ret;
}
{
struct header_filter_istream *mstream =
(struct header_filter_istream *)stream;
if (!mstream->header_read ||
return ret;
}
return -1;
}
}
{
while (!mstream->header_read) {
break;
}
}
{
struct header_filter_istream *mstream =
(struct header_filter_istream *)stream;
}
/* seek into headers. we'll have to re-parse them, use
skip_count to set the wanted position */
} else {
/* body */
}
}
static void ATTR_NORETURN
{
i_panic("istream-header-filter sync() not implemented");
}
static const struct stat *
{
struct header_filter_istream *mstream =
(struct header_filter_istream *)stream;
return st;
}
struct istream *
enum header_filter_flags flags,
const char *const *headers,
unsigned int headers_count,
{
struct header_filter_istream *mstream;
unsigned int i;
"header filter stream", 4096);
for (i = 0; i < headers_count; i++)
}