Skip to content
Permalink
Browse files

Reduce indent by 3 levels in findNextBoundary

  • Loading branch information...
jengelh committed Oct 4, 2019
1 parent 6de75f0 commit c9119effd784055d27b71a567c3fbd0d6e7b03b0
Showing with 39 additions and 37 deletions.
  1. +39 −37 src/vmime/body.cpp
@@ -65,68 +65,70 @@ size_t body::findNextBoundaryPosition(

size_t pos = position;

while (pos != npos && pos < end) {
for (; pos != npos && pos < end; ++pos) {

pos = parser->findNext(boundary, pos);

if (pos == npos) {
break; // not found
}

if (pos != 0) {
if (pos == 0) {
// Boundary is a prefix of another, continue the search (same for the other "continue"s)
continue;
}

// Skip transport padding bytes (SPACE or HTAB), if any
size_t advance = 0;
// Skip transport padding bytes (SPACE or HTAB), if any
size_t advance = 0;

while (pos != 0) {
while (pos != 0) {

parser->seek(pos - advance - 1);
parser->seek(pos - advance - 1);

const byte_t c = parser->peekByte();
const byte_t c = parser->peekByte();

if (c == ' ' || c == '\t') {
++advance;
} else {
break;
}
if (c == ' ' || c == '\t') {
++advance;
} else {
break;
}
}

// Ensure the bytes before boundary are "[LF]--": boundary should be
// at the beginning of a line, and should start with "--"
if (pos - advance >= 3) {

parser->seek(pos - advance - 3);

if (parser->matchBytes("\n--", 3)) {
// Ensure the bytes before boundary are "[LF]--": boundary should be
// at the beginning of a line, and should start with "--"
if (pos - advance < 3) {
continue;
}

parser->seek(pos + boundary.length());
parser->seek(pos - advance - 3);

const byte_t next = parser->peekByte();
if (!parser->matchBytes("\n--", 3)) {
continue;
}

// Boundary should be followed by a new line or a dash
if (next == '\r' || next == '\n' || next == '-') {
parser->seek(pos + boundary.length());

// Get rid of the "[CR]" just before "[LF]--", if any
if (pos - advance >= 4) {
const byte_t next = parser->peekByte();

parser->seek(pos - advance - 4);
// Boundary should be followed by a new line or a dash
if (next != '\r' && next != '\n' && next != '-') {
continue;
}

if (parser->peekByte() == '\r') {
advance++;
}
}
// Get rid of the "[CR]" just before "[LF]--", if any
if (pos - advance >= 4) {

*boundaryStart = pos - advance - 3;
*boundaryEnd = pos + boundary.length();
parser->seek(pos - advance - 4);

return pos;
}
}
if (parser->peekByte() == '\r') {
advance++;
}
}

// Boundary is a prefix of another, continue the search
pos++;
*boundaryStart = pos - advance - 3;
*boundaryEnd = pos + boundary.length();

return pos;
}

return pos;

0 comments on commit c9119ef

Please sign in to comment.
You can’t perform that action at this time.