Fixed boundary parsing (thanks to John van der Kamp, Zarafa).
This commit is contained in:
parent
90ad8c9154
commit
9e4867b641
43
src/body.cpp
43
src/body.cpp
@ -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>();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user