test-message-parser.c revision 12e5ac049bd74f8b98d9dc62adcb0bf3217beef6
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic const char test_msg[] =
146f9076cd456ea1e9b3f8536456d9d3c962fadbStephan Bosch"Return-Path: <test@example.org>\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"Subject: Hello world\n"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen"From: Test User <test@example.org>\n"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen"To: Another User <test2@example.org>\n"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen"Message-Id: <1.2.3.4@example>\n"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen"Mime-Version: 1.0\n"
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen"Date: Sun, 23 May 2007 04:58:08 +0300\n"
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen"Content-Type: multipart/signed; micalg=pgp-sha1;\n"
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen" protocol=\"application/pgp-signature\";\n"
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainen" boundary=\"=-GNQXLhuj24Pl1aCkk4/d\"\n"
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d\n"
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen"Content-Type: text/plain\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"Content-Transfer-Encoding: quoted-printable\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"There was a day=20\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"a happy=20day\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d\n"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen"Content-Type: application/pgp-signature; name=signature.asc\n"
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen"-----BEGIN PGP SIGNATURE-----\n"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen"Version: GnuPG v1.2.4 (GNU/Linux)\n"
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen"-----END PGP SIGNATURE-----\n"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen"--=-GNQXLhuj24Pl1aCkk4/d--\n"
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic bool msg_parts_cmp(struct message_part *p1, struct message_part *p2)
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen if ((p1->children != NULL) != (p2->children != NULL))
857c471c13ca215f4be9dd4b336b742b8d434e31Timo Sirainen if (!msg_parts_cmp(p1->children, p2->children))
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen p1->header_size.physical_size != p2->header_size.physical_size ||
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen p1->header_size.virtual_size != p2->header_size.virtual_size ||
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen p1->header_size.lines != p2->header_size.lines ||
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen p1->body_size.physical_size != p2->body_size.physical_size ||
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen p1->body_size.virtual_size != p2->body_size.virtual_size ||
dfaefeabae939803ceb8c503101e86b5496541d1Timo Sirainenstatic void test_message_parser_small_blocks(void)
9847ec56efa15fa063eea9988eee2d4ed9ec7d58Timo Sirainen unsigned int i, end_of_headers_idx;
d1e843e77f4760e303c53d9fce10123fc8d230a1Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
291ce16fffca75e8598a8c9dceb08613413dcb07Timo Sirainen /* full parsing */
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek parser = message_parser_init(pool, input, 0,
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS |
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) {
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen test_assert(strcmp(test_msg, str_c(output)) == 0);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen /* parsing in small blocks */
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen while ((ret = message_parser_parse_next_block(parser,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen test_assert((ret == 0 && i <= TEST_MSG_LEN*2) ||
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* parsing in small blocks from preparsed parts */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen end_of_headers_idx = (strstr(test_msg, "\n-----") - test_msg);
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen parser = message_parser_init_from_parts(parts, input, 0,
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen while ((ret = message_parser_parse_next_block(parser,
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen test_assert((ret == 0 && i/2 <= end_of_headers_idx) ||
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen test_assert(message_parser_deinit_from_parts(&parser, &parts2, &error) == 0);
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainenstatic void test_message_parser_truncated_mime_headers(void)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic const char input_msg[] =
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainen"Content-Type: multipart/mixed; boundary=\":foo\"\n"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen"Content-Type: text/plain\n"
c5ab90cfad9cc3e33bcb1baeb30ffc82a7b7053aTimo Sirainen"Content-Type: text/plain\r\n"
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen"Content-Type: text/html\n"
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_begin("message parser truncated mime headers");
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi pool = pool_alloconly_create("message parser", 10240);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert((parts->flags & MESSAGE_PART_FLAG_MULTIPART) != 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->body_size.physical_size == 112);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->body_size.virtual_size == 112+7);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->header_size.physical_size == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->body_size.physical_size == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->body_size.lines == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->header_size.physical_size == 24);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->header_size.virtual_size == 24);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->header_size.lines == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->header_size.physical_size == 24);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->header_size.virtual_size == 24);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->header_size.lines == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->next->header_size.physical_size == 23);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->next->header_size.virtual_size == 23);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(parts->children->next->next->next->header_size.lines == 0);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen for (part = parts->children; part != NULL; part = part->next) {
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen test_assert(part->body_size.physical_size == 0);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen test_assert(part->body_size.virtual_size == 0);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen test_assert(parts->children->next->next->next->next == NULL);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void test_message_parser_truncated_mime_headers2(void)
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainenstatic const char input_msg[] =
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
d3280fe317a4598c0868cc440e7a1191c06d0db3Timo Sirainen"Content-Type: text/plain\n"
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen test_begin("message parser truncated mime headers 2");
bd6a8056771b6150685dea319ab5a94e021d17f1Josef 'Jeff' Sipek pool = pool_alloconly_create("message parser", 10240);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
aa47c9bd1d1fc70cd699c49fd1ca92dbc7615953Timo Sirainen test_assert(parts->header_size.physical_size == 46);
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen test_assert(parts->header_size.virtual_size == 46+2);
aa47c9bd1d1fc70cd699c49fd1ca92dbc7615953Timo Sirainen test_assert(parts->body_size.physical_size == 86);
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen test_assert(parts->body_size.virtual_size == 86+8);
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen test_assert(parts->children->physical_pos == 51);
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen test_assert(parts->children->header_size.lines == 1);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen test_assert(parts->children->header_size.physical_size == 44);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen test_assert(parts->children->header_size.virtual_size == 44+1);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen test_assert(parts->children->body_size.lines == 0);
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen test_assert(parts->children->body_size.physical_size == 0);
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen test_assert(parts->children->children == NULL);
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainen test_assert(parts->children->next->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen test_assert(parts->children->next->physical_pos == 101);
4b41116563110d00330896a568eff1078c382827Timo Sirainen test_assert(parts->children->next->header_size.lines == 2);
4b41116563110d00330896a568eff1078c382827Timo Sirainen test_assert(parts->children->next->header_size.physical_size == 26);
4b41116563110d00330896a568eff1078c382827Timo Sirainen test_assert(parts->children->next->header_size.virtual_size == 26+2);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen test_assert(parts->children->next->body_size.lines == 2);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen test_assert(parts->children->next->body_size.physical_size == 5);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen test_assert(parts->children->next->body_size.virtual_size == 5+2);
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen test_assert(parts->children->next->children == NULL);
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainenstatic void test_message_parser_truncated_mime_headers3(void)
dbe64f3893616a4005c8946be75d2dc8f6823d72Timo Sirainenstatic const char input_msg[] =
8a13b020f90e080570658b18c042e7e352c8b14fTimo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen test_begin("message parser truncated mime headers 3");
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
bd1b2615928a1e8be190cb0405754f0aec8cac2fTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen test_assert(parts->header_size.physical_size == 45);
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen test_assert(parts->header_size.virtual_size == 45+1);
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen test_assert(parts->body_size.physical_size == 0);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainenstatic void test_message_parser_empty_multipart(void)
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainenstatic const char input_msg[] =
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen test_begin("message parser truncated mime headers 3");
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen test_assert(parts->header_size.physical_size == 46);
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen test_assert(parts->header_size.virtual_size == 46+2);
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen test_assert(parts->body_size.physical_size == 5);
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen test_assert(parts->body_size.virtual_size == 5+1);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic void test_message_parser_duplicate_mime_boundary(void)
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainenstatic const char input_msg[] =
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
d938e9e4ec4c0f326dffd5ebe42c1ad893ce7e52Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen"Content-Type: text/plain\n"
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen test_begin("message parser duplicate mime boundary");
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen pool = pool_alloconly_create("message parser", 10240);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
4b41218f9e09386ad5d8f279355aad1dfb64392dTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen test_assert(parts->header_size.physical_size == 45);
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
eb1572d7c44ebc7b0b039d085c3dbab2ef7043ddTimo Sirainen test_assert(parts->body_size.physical_size == 84);
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen test_assert(parts->body_size.virtual_size == 84+7);
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen test_assert(parts->children->physical_pos == 49);
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen test_assert(parts->children->header_size.lines == 2);
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen test_assert(parts->children->header_size.physical_size == 45);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen test_assert(parts->children->header_size.virtual_size == 45+2);
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen test_assert(parts->children->body_size.lines == 4);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen test_assert(parts->children->body_size.physical_size == 35);
42507d758b053bb483de58fba55c73a9eb5d3fbaTimo Sirainen test_assert(parts->children->body_size.virtual_size == 35+4);
c0c346d0e6a76137ba5006857ed03b1227804170Timo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen test_assert(parts->children->children->physical_pos == 98);
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen test_assert(parts->children->children->header_size.lines == 2);
382f23541ce657be87b079abd6784d376fb4eb43Timo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
97a5e150cacf7da9dd200e317b75460352038d65Timo Sirainen test_assert(parts->children->children->body_size.lines == 1);
3743948b65bd079cd6f2502d35bd21666c1a2f5aAki Tuomi test_assert(parts->children->children->body_size.physical_size == 5);
134987bc3b685d7ec71c04e9337f7125cff0698fTimo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
6ae329de09afb7214c906d762320847e05469d53Timo Sirainenstatic void test_message_parser_garbage_suffix_mime_boundary(void)
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainenstatic const char input_msg[] =
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7e2671b295927b461adc8b6c4ed6a1c4761fb323Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
fcfe85637e1ee14a9fc39c41fd6ceca106301542Timo Sirainen"Content-Type: text/plain\n"
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_begin("message parser garbage suffix mime boundary");
4bbd396aa6198c84f3f7763b6e8a63a26e97e141Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen parser = message_parser_init(pool, input, 0, 0);
3f91e60401495a4046c73992fabaa5e77200a451Timo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
f90cbe597c41d5cc91debd371f8648bd8e6ffbc2Timo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
33b469d1ca66dd2cc496d2d990b8b98e72952a29Timo Sirainen test_assert(parts->header_size.physical_size == 45);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
58ba0fe5a6904d3a65cfe268411f4cbb881234eeTimo Sirainen test_assert(parts->body_size.physical_size == 86);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->body_size.virtual_size == 86+7);
6b0d8106ae51ffc6ce45636b34d2e21cbefca7fdTimo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->physical_pos == 50);
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen test_assert(parts->children->header_size.lines == 2);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->header_size.physical_size == 45);
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen test_assert(parts->children->header_size.virtual_size == 45+2);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->body_size.lines == 4);
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen test_assert(parts->children->body_size.physical_size == 36);
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen test_assert(parts->children->body_size.virtual_size == 36+4);
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->children->physical_pos == 100);
b3484b5b1f47e4cf112f0e371478a2d7794b31bbTimo Sirainen test_assert(parts->children->children->header_size.lines == 2);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
d81131d3bbb4f0befb62a661d1785cf8c84a17e2Timo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->children->body_size.lines == 1);
9456a4a3e74929f9d3d5b00b93be6d8eb69bc52aTimo Sirainen test_assert(parts->children->children->body_size.physical_size == 5);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
540555c5b435203e1c26c8e7b924b2643ae07ae3Timo Sirainenstatic void test_message_parser_continuing_mime_boundary(void)
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstatic const char input_msg[] =
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen"Content-Type: multipart/mixed; boundary=\"a\"\n"
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen"Content-Type: multipart/mixed; boundary=\"ab\"\n"
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen"Content-Type: text/plain\n"
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen test_begin("message parser continuing mime boundary");
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen pool = pool_alloconly_create("message parser", 10240);
c0225f7f6b43d34dc58c17d3304f0fd60ab89894Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->header_size.physical_size == 45);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->header_size.virtual_size == 45+2);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->body_size.physical_size == 86);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->body_size.virtual_size == 86+7);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->flags == (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_IS_MIME));
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->physical_pos == 49);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen test_assert(parts->children->header_size.lines == 2);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen test_assert(parts->children->header_size.physical_size == 46);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->header_size.virtual_size == 46+2);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->body_size.lines == 4);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen test_assert(parts->children->body_size.physical_size == 36);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen test_assert(parts->children->body_size.virtual_size == 36+4);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen test_assert(parts->children->children->flags == (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_IS_MIME));
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen test_assert(parts->children->children->physical_pos == 100);
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen test_assert(parts->children->children->header_size.lines == 2);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->children->header_size.physical_size == 26);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->children->header_size.virtual_size == 26+2);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen test_assert(parts->children->children->body_size.lines == 1);
21aaa6affb9f134112b75b5db737309fc35ef1cfMartti Rannanjärvi test_assert(parts->children->children->body_size.physical_size == 5);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen test_assert(parts->children->children->body_size.virtual_size == 5+1);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen pool = pool_alloconly_create("message parser", 10240);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen parser = message_parser_init(pool, input, 0, 0);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen block.hdr != NULL && strcmp(block.hdr->name, "a") == 0 &&
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen block.hdr->value_len == 1 && block.hdr->value[0] == 'b');
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen test_assert(message_parser_parse_next_block(parser, &block) < 0);
5f44975ec6c5755dd74bcd4c47a123a7242ecab3Timo Sirainen static void (*test_functions[])(void) = {