From a55c574436973c354d731fffa81afabac98c1cfd Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sat, 25 Jun 2011 17:07:53 +0000 Subject: [PATCH] Fixed parsing of empty body parts (thanks to John van der Kamp, from Zarafa). --- src/body.cpp | 5 +++++ tests/parser/bodyPartTest.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/body.cpp b/src/body.cpp index 85968330..9d7d57f9 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -197,6 +197,11 @@ void body::parse(const string& buffer, const string::size_type position, { ref part = vmime::create (); + // 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; diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp index b129913d..075b8f9a 100644 --- a/tests/parser/bodyPartTest.cpp +++ b/tests/parser/bodyPartTest.cpp @@ -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