Fixed parsing of empty body parts (thanks to John van der Kamp, from Zarafa).

This commit is contained in:
Vincent Richard 2011-06-25 17:07:53 +00:00
parent 72e6a18483
commit a55c574436
2 changed files with 24 additions and 0 deletions

View File

@ -197,6 +197,11 @@ void body::parse(const string& buffer, const string::size_type position,
{
ref <bodyPart> part = vmime::create <bodyPart>();
// End before start may happen on empty bodyparts (directly
// successive boundaries without even a line-break)
if (partEnd < partStart)
std::swap(partStart, partEnd);
part->parse(buffer, partStart, partEnd, NULL);
part->m_parent = m_part;

View File

@ -36,6 +36,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testParseMissingLastBoundary)
VMIME_TEST(testPrologEpilog)
VMIME_TEST(testPrologEncoding)
VMIME_TEST(testSuccessiveBoundaries)
VMIME_TEST_LIST_END
@ -181,5 +182,23 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("epilog", "Epilog text", msg->getBody()->getEpilogText());
}
void testSuccessiveBoundaries()
{
vmime::string str =
"Content-Type: multipart/mixed; boundary=\"MY-BOUNDARY\""
"\r\n\r\n"
"--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1\r\n"
"--MY-BOUNDARY\r\n"
"--MY-BOUNDARY--\r\n";
vmime::bodyPart p;
p.parse(str);
VASSERT_EQ("count", 2, p.getBody()->getPartCount());
VASSERT_EQ("part1-body", "BODY1", extractContents(p.getBody()->getPartAt(0)->getBody()->getContents()));
VASSERT_EQ("part2-body", "", extractContents(p.getBody()->getPartAt(1)->getBody()->getContents()));
}
VMIME_TEST_SUITE_END