/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "istream.h"
#include "message-parser.h"
#include "test-common.h"
static const char test_msg[] =
"Return-Path: <test@example.org>\n"
"Subject: Hello world\n"
"From: Test User <test@example.org>\n"
"To: Another User <test2@example.org>\n"
"Message-Id: <1.2.3.4@example>\n"
"Mime-Version: 1.0\n"
"Date: Sun, 23 May 2007 04:58:08 +0300\n"
" protocol=\"application/pgp-signature\";\n"
" boundary=\"=-GNQXLhuj24Pl1aCkk4/d\"\n"
"\n"
"--=-GNQXLhuj24Pl1aCkk4/d\n"
"Content-Transfer-Encoding: quoted-printable\n"
"\n"
"There was a day=20\n"
"a happy=20day\n"
"\n"
"--=-GNQXLhuj24Pl1aCkk4/d\n"
"Content-Type: application/pgp-signature; name=signature.asc\n"
"\n"
"-----BEGIN PGP SIGNATURE-----\n"
"\n"
"invalid\n"
"-----END PGP SIGNATURE-----\n"
"\n"
"--=-GNQXLhuj24Pl1aCkk4/d--\n"
"\n"
"\n";
{
return FALSE;
return FALSE;
return FALSE;
}
return FALSE;
}
return TRUE;
}
{
const char *error;
int ret;
i_stream_seek(input, 0);
i_unreached();
if (i > TEST_MSG_LEN*2)
&block)) > 0) ;
}
}
static void test_message_parser_small_blocks(void)
{
unsigned int i, end_of_headers_idx;
const char *error;
int ret;
test_begin("message parser in small blocks");
/* full parsing */
}
test_assert(ret < 0);
/* parsing in small blocks */
i_stream_seek(input, 0);
if (i > TEST_MSG_LEN*2)
&block)) > 0) ;
}
/* parsing in small blocks from preparsed parts */
i_stream_seek(input, 0);
if (i > TEST_MSG_LEN*2)
&block)) > 0) ;
}
pool_unref(&pool);
test_end();
}
static void test_message_parser_truncated_mime_headers(void)
{
static const char input_msg[] =
"\n"
"--:foo\n"
"--:foo\n"
"--:foo\n"
"--:foo\n"
"--:foo--\n";
int ret;
test_begin("message parser truncated mime headers");
test_assert(ret < 0);
}
pool_unref(&pool);
test_end();
}
static void test_message_parser_truncated_mime_headers2(void)
{
static const char input_msg[] =
"\n"
"--ab\n"
"\n"
"--ab\n"
"\n"
"--a\n\n";
int ret;
test_begin("message parser truncated mime headers 2");
test_assert(ret < 0);
pool_unref(&pool);
test_end();
}
static void test_message_parser_truncated_mime_headers3(void)
{
static const char input_msg[] =
int ret;
test_begin("message parser truncated mime headers 3");
test_assert(ret < 0);
pool_unref(&pool);
test_end();
}
static void test_message_parser_empty_multipart(void)
{
static const char input_msg[] =
"\n"
"body\n";
int ret;
test_begin("message parser empty multipart");
test_assert(ret < 0);
pool_unref(&pool);
test_end();
}
static void test_message_parser_duplicate_mime_boundary(void)
{
static const char input_msg[] =
"\n"
"--a\n"
"\n"
"--a\n"
"\n"
"body\n";
int ret;
test_begin("message parser duplicate mime boundary");
test_assert(ret < 0);
test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
pool_unref(&pool);
test_end();
}
static void test_message_parser_garbage_suffix_mime_boundary(void)
{
static const char input_msg[] =
"\n"
"--ab\n"
"\n"
"--ac\n"
"\n"
"body\n";
int ret;
test_begin("message parser garbage suffix mime boundary");
test_assert(ret < 0);
test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
pool_unref(&pool);
test_end();
}
static void test_message_parser_continuing_mime_boundary(void)
{
static const char input_msg[] =
"\n"
"--a\n"
"\n"
"--ab\n"
"\n"
"body\n";
int ret;
test_begin("message parser continuing mime boundary");
test_assert(ret < 0);
test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
pool_unref(&pool);
test_end();
}
static void test_message_parser_continuing_truncated_mime_boundary(void)
{
static const char input_msg[] =
"\n"
"--a\n"
"MIME-Version: 1.0\n"
"--ab\n"
"\n"
"--ab--\n"
"--a--\n\n";
int ret;
test_begin("message parser continuing truncated mime boundary");
test_assert(ret < 0);
/* this will not be a child, since the header was truncated. I guess
we could make it, but it would complicate the message-parser even
more. */
pool_unref(&pool);
test_end();
}
static void test_message_parser_no_eoh(void)
{
test_begin("message parser no EOH");
pool_unref(&pool);
test_end();
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}