aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/body.cpp43
-rw-r--r--tests/parser/bodyPartTest.cpp2
2 files changed, 42 insertions, 3 deletions
diff --git a/src/body.cpp b/src/body.cpp
index 13dff6b4..738d3e71 100644
--- a/src/body.cpp
+++ b/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>();
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index 12c4f74b..df2bf851 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -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;