aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2008-07-11 20:45:17 +0000
committerVincent Richard <[email protected]>2008-07-11 20:45:17 +0000
commita68e12235430901f71982ad2593268f38ea4b85b (patch)
tree46494db4846a38e837f01ff3ca52081e90e65e24
parentFixed extra space in subject (see https://sourceforge.net/forum/message.php?m... (diff)
downloadvmime-a68e12235430901f71982ad2593268f38ea4b85b.tar.gz
vmime-a68e12235430901f71982ad2593268f38ea4b85b.zip
Recover from broken emails without a final boundary (Zarafa).
-rw-r--r--AUTHORS3
-rw-r--r--src/body.cpp23
-rw-r--r--tests/parser/bodyPartTest.cpp28
3 files changed, 53 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 0a94013c..da6f0875 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -8,6 +8,9 @@ Project originator, design, core implementation.
Pierre Thierry <[email protected]>
Patches for STL algorithms.
+Zarafa <http://developer.zarafa.com/VmimePatches>
+Miscellaneous patches.
+
Other contributors:
- Stefan Uhrig <[email protected]>
diff --git a/src/body.cpp b/src/body.cpp
index a6b74a76..b9180d74 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -186,8 +186,29 @@ void body::parse(const string& buffer, const string::size_type position,
m_contents = vmime::create <emptyContentHandler>();
- if (partStart < end)
+ // Last part was not found: recover from missing boundary
+ if (!lastPart && pos == string::npos)
+ {
+ ref <bodyPart> part = vmime::create <bodyPart>();
+
+ try
+ {
+ part->parse(buffer, partStart, end);
+ }
+ catch (std::exception&)
+ {
+ throw;
+ }
+
+ part->m_parent = m_part;
+
+ m_parts.push_back(part);
+ }
+ // Treat remaining text as epilog
+ else if (partStart < end)
+ {
m_epilogText = string(buffer.begin() + partStart, buffer.begin() + end);
+ }
}
// Treat the contents as 'simple' data
else
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index 31c18879..d6fff5e8 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -33,6 +33,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testParse)
VMIME_TEST(testGenerate)
+ VMIME_TEST(testParseMissingLastBoundary)
VMIME_TEST_LIST_END
@@ -43,6 +44,16 @@ VMIME_TEST_SUITE_BEGIN
buffer.begin() + c.getParsedOffset() + c.getParsedLength());
}
+ static const vmime::string extractContents(const vmime::ref <const vmime::contentHandler> cts)
+ {
+ std::ostringstream oss;
+ vmime::utility::outputStreamAdapter os(oss);
+
+ cts->extract(os);
+
+ return oss.str();
+ }
+
void testParse()
{
@@ -68,6 +79,23 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("6", "BODY", extractComponentString(str3, *p3.getBody()));
}
+ void testParseMissingLastBoundary()
+ {
+ vmime::string str =
+ "Content-Type: multipart/mixed; boundary=\"MY-BOUNDARY\""
+ "\r\n\r\n"
+ "--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1"
+ "--MY-BOUNDARY\r\nHEADER2\r\n\r\nBODY2";
+
+ 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", "BODY2", extractContents(p.getBody()->getPartAt(1)->getBody()->getContents()));
+ }
+
void testGenerate()
{
vmime::bodyPart p1;