test-istream-header-filter.c revision 75891a354ed229a4e56bbb0eceab75a0d1278687
/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "istream.h"
#include "message-header-parser.h"
#include "istream-header-filter.h"
#include "test-common.h"
struct run_ctx {
bool null_hdr_seen;
bool callback_called;
};
struct message_header_line *hdr,
{
}
static inline void
{
}
static void
const char *output,
bool first,
{
const unsigned char *data;
if (first)
else
}
static void
enum header_filter_flags flags,
{
unsigned int i;
run_callback, &run_ctx);
for (i = 1; i < input_len; i++) {
}
/* run again to make sure it's still correct the second time */
i_stream_seek(filter, 0);
while (i_stream_read(filter) > 0) ;
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
/* drop 1) first header, 2) X-Drop header */
}
}
static void test_istream_filter(void)
{
const char *input = "From: foo\nFrom: abc\nTo: bar\nSubject: plop\nX-Drop: 1\n\nhello world\n";
const char *output = "From: abc\n\nhello world\n";
unsigned int i;
const unsigned char *data;
test_begin("i_stream_create_header_filter: exclude");
filter_callback, (void *)NULL);
(void *)NULL);
for (i = 1; i < input_len; i++) {
}
i_stream_seek(filter, 0);
while (i_stream_read(filter) > 0) ;
test_end();
}
{
unsigned int i;
for (i = 0; i < count; i++)
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
bool *matched, bool *null_hdr_seen)
{
*null_hdr_seen = TRUE;
}
static void test_istream_filter_large_buffer(void)
{
const unsigned char *data;
const char *p;
unsigned int i;
bool null_hdr_seen = FALSE;
test_begin("i_stream_create_header_filter: large buffer");
NULL, 0,
for (i = 0; i < 2; i++) {
for (;;) {
if (ret == -1)
break;
if (ret == -2) {
}
}
/* callbacks are called only once */
test_assert(null_hdr_seen == (i == 0));
p = strchr(p, '\n');
/* seek back and retry once with caching and different
buffer size */
i_stream_seek(filter, 0);
str_truncate(output, 0);
}
test_end();
}
static void test_istream_filter_large_buffer2(void)
{
static const char *wanted_headers[] = { "References" };
const unsigned char *data;
unsigned int i;
int ret;
test_begin("i_stream_create_header_filter: large buffer2");
*null_header_filter_callback, (void *)NULL);
for (i = 0; i < 2; i++) {
}
/* seek back and retry once with caching and different
buffer size */
i_stream_seek(filter, 0);
str_truncate(output, 0);
}
test_end();
}
static void
struct message_header_line *hdr,
{
}
static void test_istream_callbacks(void)
{
unsigned int i;
test_begin("i_stream_create_header_filter: callbacks");
NULL, 0,
output);
/* callback should be called exactly once for all the header input */
for (i = 0; i < 2; i++) {
}
test_end();
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
return;
/* add a new header */
const char *new_hdr = "Added: header\n\n";
/* modify To header */
const char *new_to = "To: 123\n";
}
}
static void test_istream_edit(void)
{
const char *input = "From: foo\nTo: bar\n\nhello world\n";
const char *output = "From: foo\nTo: 123\nAdded: header\n\nhello world\n";
test_begin("i_stream_create_header_filter: edit headers");
test_end();
}
static void test_istream_end_body_with_lf(void)
{
const char *input = "From: foo\n\nhello world";
const char *output = "From: foo\n\nhello world\n";
unsigned int i;
const unsigned char *data;
test_begin("i_stream_create_header_filter: end_body_with_lf");
NULL, 0,
(void *)NULL);
for (i = 1; i < input_len; i++) {
}
i_stream_seek(filter, 0);
for (i = 1; i < input_len; i++) {
if (size > 0)
}
test_end();
}
static void test_istream_add_missing_eoh(void)
{
static const struct {
const char *input;
const char *output;
unsigned int extra;
} tests[] = {
{ "From: foo", "From: foo\n\n", 1 },
{ "From: foo\n", "From: foo\n\n", 1 },
{ "From: foo\n\n", "From: foo\n\n", 1 },
{ "From: foo\n\nbar", "From: foo\n\nbar", 0 },
{ "From: foo\r\n", "From: foo\r\n\r\n", 1 },
{ "From: foo\r\n\r\n", "From: foo\r\n\r\n", 0 },
{ "From: foo\r\n\r\nbar", "From: foo\r\n\r\nbar", 0 }
};
unsigned int i;
test_begin("i_stream_create_header_filter: add missing EOH");
for (i = 0; i < N_ELEMENTS(tests); i++) {
}
test_end();
}
static void test_istream_hide_body(void)
{
static const struct {
const char *input;
const char *output;
int extra;
} tests[] = {
{ "From: foo", "From: foo", 0 },
{ "From: foo\n", "From: foo\n", 0 },
{ "From: foo\n\n", "From: foo\n\n", 1 },
{ "From: foo\n\nbar", "From: foo\n\n", -2 },
{ "From: foo\r\n", "From: foo\r\n", 0 },
{ "From: foo\r\n\r\n", "From: foo\r\n\r\n", 0 },
{ "From: foo\r\n\r\nbar", "From: foo\r\n\r\n", -3 }
};
unsigned int i;
test_begin("i_stream_create_header_filter: hide body");
for (i = 0; i < N_ELEMENTS(tests); i++) {
}
test_end();
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
}
static void test_istream_strip_eoh(void)
{
const char *input = "From: foo\nTo: bar\n\nhello world\n";
const char *output = "From: foo\nTo: bar\nhello world\n";
test_begin("i_stream_create_header_filter: strip_eoh");
test_end();
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
const char *new_hdr = "Subject: added\n\n";
}
}
static void test_istream_missing_eoh_callback(void)
{
const char *input = "From: foo\nTo: bar\n";
const char *output = "From: foo\nTo: bar\nSubject: added\n\n";
test_begin("i_stream_create_header_filter: add headers when EOH is missing");
test_end();
}
static void test_istream_empty_missing_eoh_callback(void)
{
const char *input = "";
const char *output = "Subject: added\n\n";
test_begin("i_stream_create_header_filter: add headers when mail is empty");
test_end();
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}