diff --git a/src/bincimapmime/mime-parsefull.cc b/src/bincimapmime/mime-parsefull.cc index 43e91e26..050cf498 100644 --- a/src/bincimapmime/mime-parsefull.cc +++ b/src/bincimapmime/mime-parsefull.cc @@ -339,8 +339,10 @@ static bool skipUntilBoundary(const string &delimiter, if (!delimiterqueue) continue; - delimiterqueue[delimiterpos++ % endpos] = c; - + delimiterqueue[delimiterpos++] = c; + if (delimiterpos == endpos) + delimiterpos = 0; + if (compareStringToQueue(delimiterStr, delimiterqueue, delimiterpos, endpos)) { foundBoundary = true; @@ -535,7 +537,6 @@ static void parseSinglePart(const string &toboundary, boundaryqueue = new char[endpos]; memset(boundaryqueue, 0, endpos); } - int boundarypos = 0; *boundarysize = 0; @@ -543,6 +544,7 @@ static void parseSinglePart(const string &toboundary, string line; bool toboundaryIsEmpty = (toboundary == ""); char c; + int boundarypos = 0; while (mimeSource->getChar(&c)) { if (c == '\n') { ++*nbodylines; ++*nlines; } @@ -550,7 +552,9 @@ static void parseSinglePart(const string &toboundary, continue; // find boundary - boundaryqueue[boundarypos++ % endpos] = c; + boundaryqueue[boundarypos++] = c; + if (boundarypos == endpos) + boundarypos = 0; if (compareStringToQueue(_toboundaryStr, boundaryqueue, boundarypos, endpos)) { diff --git a/src/bincimapmime/mime-printbody.cc b/src/bincimapmime/mime-printbody.cc index 66472bba..d46acb0b 100644 --- a/src/bincimapmime/mime-printbody.cc +++ b/src/bincimapmime/mime-printbody.cc @@ -93,7 +93,7 @@ void Binc::MimePart::getBody(string &s, { mimeSource->reset(); mimeSource->seek(bodystartoffsetcrlf + startoffset); - + s.reserve(length); if (startoffset + length > bodylength) length = bodylength - startoffset; diff --git a/src/bincimapmime/mime-utils.h b/src/bincimapmime/mime-utils.h index eec6bb09..19b10b63 100644 --- a/src/bincimapmime/mime-utils.h +++ b/src/bincimapmime/mime-utils.h @@ -42,9 +42,12 @@ using namespace ::std; inline bool compareStringToQueue(const char *s_in, char *bqueue, int pos, int size) { - for (int i = 0; i < size; ++i) - if (s_in[i] != bqueue[(pos + i) % size]) + for (int i = 0; i < size; ++i) { + if (s_in[i] != bqueue[pos]) return false; + if (++pos == size) + pos = 0; + } return true; }