Recover from broken emails without a final boundary (Zarafa).

This commit is contained in:
Vincent Richard 2008-07-11 20:45:17 +00:00
parent 439b2b3e90
commit a68e122354
3 changed files with 53 additions and 1 deletions

View File

@ -8,6 +8,9 @@ Project originator, design, core implementation.
Pierre Thierry <nowhere.man@levallois.eu.org>
Patches for STL algorithms.
Zarafa <http://developer.zarafa.com/VmimePatches>
Miscellaneous patches.
Other contributors:
- Stefan Uhrig <stefanuhrig@gmx.net>

View File

@ -186,9 +186,30 @@ 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
{

View File

@ -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;