Fixed boundary parsing (thanks to John van der Kamp, Zarafa).

This commit is contained in:
Vincent Richard 2010-12-10 16:54:38 +00:00
parent 90ad8c9154
commit 9e4867b641
2 changed files with 42 additions and 3 deletions

View File

@ -127,10 +127,30 @@ void body::parse(const string& buffer, const string::size_type position,
const string boundarySep("--" + boundary);
string::size_type partStart = position;
string::size_type pos = buffer.find(boundarySep, position);
string::size_type pos = position;
bool lastPart = false;
while (pos != string::npos && pos < end)
{
pos = buffer.find(boundarySep, pos);
if (pos == string::npos ||
((pos == 0 || buffer[pos - 1] == '\n') &&
(buffer[pos + boundarySep.length()] == '\r' ||
buffer[pos + boundarySep.length()] == '\n' ||
buffer[pos + boundarySep.length()] == '-'
)
)
)
{
break;
}
// boundary not a beginning of line, or just a prefix of another, continue the search.
pos++;
}
if (pos != string::npos && pos < end)
{
m_prologText = string(buffer.begin() + position, buffer.begin() + pos);
@ -181,7 +201,26 @@ void body::parse(const string& buffer, const string::size_type position,
}
partStart = pos;
pos = buffer.find(boundarySep, partStart);
while (pos != string::npos && pos < end)
{
pos = buffer.find(boundarySep, pos);
if (pos == string::npos ||
((pos == 0 || buffer[pos - 1] == '\n') &&
(buffer[pos + boundarySep.length()] == '\r' ||
buffer[pos + boundarySep.length()] == '\n' ||
buffer[pos + boundarySep.length()] == '-'
)
)
)
{
break;
}
// boundary not a beginning of line, or just a prefix of another, continue the search.
pos++;
}
}
m_contents = vmime::create <emptyContentHandler>();

View File

@ -84,7 +84,7 @@ VMIME_TEST_SUITE_BEGIN
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\nHEADER1\r\n\r\nBODY1\r\n"
"--MY-BOUNDARY\r\nHEADER2\r\n\r\nBODY2";
vmime::bodyPart p;