diff options
| author | Vincent Richard <[email protected]> | 2010-12-10 16:54:38 +0000 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2010-12-10 16:54:38 +0000 |
| commit | 9e4867b641a54e316dd1264c9b62489885185fa3 (patch) | |
| tree | 9810189bef2f52db7e0575bb969452970ecb9b9f /src | |
| parent | Fixed unit test after bug fix. (diff) | |
| download | vmime-9e4867b641a54e316dd1264c9b62489885185fa3.tar.gz vmime-9e4867b641a54e316dd1264c9b62489885185fa3.zip | |
Fixed boundary parsing (thanks to John van der Kamp, Zarafa).
Diffstat (limited to 'src')
| -rw-r--r-- | src/body.cpp | 43 |
1 files changed, 41 insertions, 2 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>(); |
