bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Return-Path: <test@example.org>\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Subject: Hello world\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"From: Test User <test@example.org>\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"To: Another User <test2@example.org>\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Message-Id: <1.2.3.4@example>\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Mime-Version: 1.0\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Date: Sun, 23 May 2007 04:58:08 +0300\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Content-Type: multipart/signed; micalg=pgp-sha1;\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen" protocol=\"application/pgp-signature\";\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen" boundary=\"=-GNQXLhuj24Pl1aCkk4/d\"\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Content-Type: text/plain\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Content-Transfer-Encoding: quoted-printable\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"There was a day=20\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"a happy=20day\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Content-Type: application/pgp-signature; name=signature.asc\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"-----BEGIN PGP SIGNATURE-----\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"Version: GnuPG v1.2.4 (GNU/Linux)\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"-----END PGP SIGNATURE-----\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d--\n"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic bool msg_parts_cmp(struct message_part *p1, struct message_part *p2)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen if ((p1->children != NULL) != (p2->children != NULL))
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen if (!msg_parts_cmp(p1->children, p2->children))
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen p1->header_size.physical_size != p2->header_size.physical_size ||
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen p1->header_size.virtual_size != p2->header_size.virtual_size ||
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen p1->header_size.lines != p2->header_size.lines ||
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen p1->body_size.physical_size != p2->body_size.physical_size ||
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen p1->body_size.virtual_size != p2->body_size.virtual_size ||
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainenstatic void test_parsed_parts(struct istream *input, struct message_part *parts)
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen if (i_stream_get_size(input, TRUE, &input_size) < 0)
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen parser = message_parser_init_from_parts(parts, input, 0,
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen while ((ret = message_parser_parse_next_block(parser,
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(message_parser_deinit_from_parts(&parser, &parts2, &error) == 0);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenstatic void test_message_parser_small_blocks(void)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen /* full parsing */
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS |
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) {
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen test_assert(strcmp(test_msg, str_c(output)) == 0);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen /* parsing in small blocks */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen while ((ret = message_parser_parse_next_block(parser,
5f237cf1915127fe143ac4c1d3cb4d1139f3b97dTimo Sirainen test_assert((ret == 0 && i <= TEST_MSG_LEN*2) ||
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen /* parsing in small blocks from preparsed parts */
5f237cf1915127fe143ac4c1d3cb4d1139f3b97dTimo Sirainen end_of_headers_idx = (strstr(test_msg, "\n-----") - test_msg);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen parser = message_parser_init_from_parts(parts, input, 0,
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen while ((ret = message_parser_parse_next_block(parser,
5f237cf1915127fe143ac4c1d3cb4d1139f3b97dTimo Sirainen test_assert((ret == 0 && i/2 <= end_of_headers_idx) ||
12e5ac049bd74f8b98d9dc62adcb0bf3217beef6Martti Rannanjärvi test_assert(message_parser_deinit_from_parts(&parser, &parts2, &error) == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainenstatic void test_message_parser_truncated_mime_headers(void)
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen"Content-Type: multipart/mixed; boundary=\":foo\"\n"
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen"Content-Type: text/plain\n"
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen"Content-Type: text/plain\r\n"
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen"Content-Type: text/html\n"
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_begin("message parser truncated mime headers");
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen pool = pool_alloconly_create("message parser", 10240);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert((parts->flags & MESSAGE_PART_FLAG_MULTIPART) != 0);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->header_size.physical_size == 48);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->header_size.virtual_size == 48+2);
f148466c7b648669b99bf20c651ae7fc81d28659Timo Sirainen test_assert(parts->body_size.physical_size == 112);
f148466c7b648669b99bf20c651ae7fc81d28659Timo Sirainen test_assert(parts->body_size.virtual_size == 112+7);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->children->physical_pos == 55);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->header_size.physical_size == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->body_size.physical_size == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->body_size.lines == 0);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->children->next->physical_pos == 62);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->header_size.physical_size == 24);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->header_size.virtual_size == 24);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->header_size.lines == 0);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->children->next->next->physical_pos == 94);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->header_size.physical_size == 24);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->header_size.virtual_size == 24);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->header_size.lines == 0);
aeaf818613081b9a9ff8c9fd4306e8dbfab4fd86Timo Sirainen test_assert(parts->children->next->next->next->physical_pos == 127);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->next->header_size.physical_size == 23);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->next->header_size.virtual_size == 23);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->next->header_size.lines == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen for (part = parts->children; part != NULL; part = part->next) {
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(part->body_size.physical_size == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(part->body_size.virtual_size == 0);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen test_assert(parts->children->next->next->next->next == NULL);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainenstatic void test_message_parser_truncated_mime_headers2(void)
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen"Content-Type: text/plain\n"
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_begin("message parser truncated mime headers 2");
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen pool = pool_alloconly_create("message parser", 10240);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->header_size.physical_size == 46);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->header_size.virtual_size == 46+2);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->body_size.physical_size == 86);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->body_size.virtual_size == 86+8);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->physical_pos == 51);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->header_size.lines == 1);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->header_size.physical_size == 44);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->header_size.virtual_size == 44+1);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->body_size.lines == 0);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->body_size.physical_size == 0);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->children == NULL);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->physical_pos == 101);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->header_size.lines == 2);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->header_size.physical_size == 26);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->header_size.virtual_size == 26+2);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->body_size.lines == 2);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->body_size.physical_size == 5);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->body_size.virtual_size == 5+2);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->children->next->children == NULL);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainenstatic void test_message_parser_truncated_mime_headers3(void)
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n";
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_begin("message parser truncated mime headers 3");
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen pool = pool_alloconly_create("message parser", 10240);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->header_size.physical_size == 45);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->header_size.virtual_size == 45+1);
6df4a174b4cbdc439ed435a0cdc71d4a0126d54aTimo Sirainen test_assert(parts->body_size.physical_size == 0);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainenstatic void test_message_parser_empty_multipart(void)
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->header_size.physical_size == 46);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->header_size.virtual_size == 46+2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->body_size.physical_size == 5);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->body_size.virtual_size == 5+1);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainenstatic void test_message_parser_duplicate_mime_boundary(void)
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: text/plain\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_begin("message parser duplicate mime boundary");
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->header_size.physical_size == 45);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->body_size.physical_size == 84);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->body_size.virtual_size == 84+7);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->physical_pos == 49);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.lines == 2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.physical_size == 45);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.virtual_size == 45+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.lines == 4);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.physical_size == 35);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.virtual_size == 35+4);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->physical_pos == 98);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.lines == 2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.lines == 1);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.physical_size == 5);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainenstatic void test_message_parser_garbage_suffix_mime_boundary(void)
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen"Content-Type: text/plain\n"
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_begin("message parser garbage suffix mime boundary");
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->header_size.physical_size == 45);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->body_size.physical_size == 86);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->body_size.virtual_size == 86+7);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->physical_pos == 50);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->header_size.lines == 2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->header_size.physical_size == 45);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->header_size.virtual_size == 45+2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->body_size.lines == 4);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->body_size.physical_size == 36);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->body_size.virtual_size == 36+4);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->physical_pos == 100);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->header_size.lines == 2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->body_size.lines == 1);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->body_size.physical_size == 5);
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainenstatic void test_message_parser_continuing_mime_boundary(void)
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen"Content-Type: text/plain\n"
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_begin("message parser continuing mime boundary");
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->header_size.physical_size == 45);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->body_size.physical_size == 86);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->body_size.virtual_size == 86+7);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->physical_pos == 49);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.lines == 2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.physical_size == 46);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->header_size.virtual_size == 46+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.lines == 4);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.physical_size == 36);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->body_size.virtual_size == 36+4);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->physical_pos == 100);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.lines == 2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.lines == 1);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.physical_size == 5);
7a12331c6360968b141a0888e0bf04dd24145f23Timo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainenstatic void test_message_parser_continuing_truncated_mime_boundary(void)
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen"MIME-Version: 1.0\n"
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen"Content-Type: text/plain\n"
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_begin("message parser continuing truncated mime boundary");
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.physical_size == 45);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.virtual_size == 45+2);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->body_size.physical_size == 112);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->body_size.virtual_size == 112+9);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.physical_size == 45+17);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.virtual_size == 45+17+1);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->body_size.physical_size == 0);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen /* this will not be a child, since the header was truncated. I guess
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen we could make it, but it would complicate the message-parser even
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.physical_size == 25);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.virtual_size == 25+1);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->body_size.physical_size == 0);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->header_size.physical_size == 0);
12fd7a30563f3256642070ef9528dda0d089cb41Timo Sirainen test_assert(part->body_size.physical_size == 0);
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen block.hdr != NULL && strcmp(block.hdr->name, "a") == 0 &&
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen block.hdr->value_len == 1 && block.hdr->value[0] == 'b');
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) < 0);
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {
7195d775e5e943af90d24a615847c733a104e3d4Timo Sirainen test_message_parser_garbage_suffix_mime_boundary,