use original headerField.cpp to avoid whitespace differences

This commit is contained in:
bmagistro 2017-02-27 11:12:12 -05:00
parent 68fd4e1e42
commit 8fb7b007f9

View File

@ -103,33 +103,33 @@ shared_ptr <headerField> headerField::parseNext
return null; return null;
} }
// This line may be a field description // This line may be a field description
if (!parserHelpers::isSpace(c)) if (!parserHelpers::isSpace(c))
{ {
const size_t nameStart = pos; // remember the start position of the line const size_t nameStart = pos; // remember the start position of the line
while (pos < end && (buffer[pos] != ':' && !parserHelpers::isSpace(buffer[pos]))) while (pos < end && (buffer[pos] != ':' && !parserHelpers::isSpace(buffer[pos])))
++pos;
const size_t nameEnd = pos;
while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t'))
++pos; ++pos;
const size_t nameEnd = pos; if (buffer[pos] != ':')
{
while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) switch (ctx.getHeaderParseErrorRecoveryMethod()) {
++pos;
if (buffer[pos] != ':')
{
switch (ctx.getHeaderParseErrorRecoveryMethod()) {
case vmime::headerParseRecoveryMethod::SKIP_LINE: case vmime::headerParseRecoveryMethod::SKIP_LINE:
// Humm...does not seem to be a valid header line. // Humm...does not seem to be a valid header line.
// Skip this error and advance to the next line // Skip this error and advance to the next line
pos = nameStart; pos = nameStart;
while (pos < end && buffer[pos] != '\n') while (pos < end && buffer[pos] != '\n')
++pos; ++pos;
if (pos < end && buffer[pos] == '\n') if (pos < end && buffer[pos] == '\n')
++pos; ++pos;
break; break;
// case vmime::headerParseRecoveryMethod::APPEND_TO_PREVIOUS_LINE: // case vmime::headerParseRecoveryMethod::APPEND_TO_PREVIOUS_LINE:
// // TODO Implement this... // // TODO Implement this...
@ -139,93 +139,93 @@ shared_ptr <headerField> headerField::parseNext
return null; return null;
break; break;
} }
} }
else else
{ {
// Extract the field name // Extract the field name
const string name(buffer.begin() + nameStart, const string name(buffer.begin() + nameStart,
buffer.begin() + nameEnd); buffer.begin() + nameEnd);
// Skip ':' character // Skip ':' character
while (pos < end && buffer[pos] == ':') while (pos < end && buffer[pos] == ':')
++pos; ++pos;
// Skip spaces between ':' and the field contents // Skip spaces between ':' and the field contents
while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t'))
++pos; ++pos;
const size_t contentsStart = pos; const size_t contentsStart = pos;
size_t contentsEnd = 0; size_t contentsEnd = 0;
bool firstLine = true; bool firstLine = true;
// Parse field value, taking care of line folding (value on multiple lines) // Parse field value, taking care of line folding (value on multiple lines)
for (size_t eol = 0 ; parserHelpers::findEOL(buffer, pos, end, &eol) ; pos = eol) for (size_t eol = 0 ; parserHelpers::findEOL(buffer, pos, end, &eol) ; pos = eol)
{ {
// If the line does not start with a folding indicator (SPACE or TAB), // If the line does not start with a folding indicator (SPACE or TAB),
// and this is not the first line, then stop parsing lines // and this is not the first line, then stop parsing lines
if (!firstLine && !(buffer[pos] == ' ' || buffer[pos] == '\t')) if (!firstLine && !(buffer[pos] == ' ' || buffer[pos] == '\t'))
break; break;
contentsEnd = eol; contentsEnd = eol;
firstLine = false; firstLine = false;
} }
if (pos == end && contentsEnd == 0) if (pos == end && contentsEnd == 0)
{ {
// End of data, and no CRLF was found at the end // End of data, and no CRLF was found at the end
contentsEnd = end; contentsEnd = end;
} }
// Strip spaces from end of header lines // Strip spaces from end of header lines
while (contentsEnd > contentsStart && while (contentsEnd > contentsStart &&
(buffer[contentsEnd - 1] == ' ' || buffer[contentsEnd - 1] == '\t' || (buffer[contentsEnd - 1] == ' ' || buffer[contentsEnd - 1] == '\t' ||
buffer[contentsEnd - 1] == '\r' || buffer[contentsEnd - 1] == '\n')) buffer[contentsEnd - 1] == '\r' || buffer[contentsEnd - 1] == '\n'))
{ {
contentsEnd--; contentsEnd--;
} }
// Return a new field // Return a new field
shared_ptr <headerField> field = headerFieldFactory::getInstance()->create(name); shared_ptr <headerField> field = headerFieldFactory::getInstance()->create(name);
field->parse(ctx, buffer, contentsStart, contentsEnd, NULL); field->parse(ctx, buffer, contentsStart, contentsEnd, NULL);
field->setParsedBounds(nameStart, pos); field->setParsedBounds(nameStart, pos);
if (newPosition) if (newPosition)
*newPosition = pos; *newPosition = pos;
return (field); return (field);
} }
} }
else else
{ {
// If the line contains only space characters, we assume it is // If the line contains only space characters, we assume it is
// the end of the headers. // the end of the headers.
while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t'))
++pos; ++pos;
if (pos < end && buffer[pos] == '\n') if (pos < end && buffer[pos] == '\n')
{ {
if (newPosition) if (newPosition)
*newPosition = pos + 1; // LF: illegal *newPosition = pos + 1; // LF: illegal
return null; return null;
} }
else if (pos + 1 < end && buffer[pos] == '\r' && buffer[pos + 1] == '\n') else if (pos + 1 < end && buffer[pos] == '\r' && buffer[pos + 1] == '\n')
{ {
if (newPosition) if (newPosition)
*newPosition = pos + 2; // CR+LF *newPosition = pos + 2; // CR+LF
return null; return null;
} }
// Skip this error and advance to the next line // Skip this error and advance to the next line
while (pos < end && buffer[pos] != '\n') while (pos < end && buffer[pos] != '\n')
++pos; ++pos;
if (buffer[pos] == '\n') if (buffer[pos] == '\n')
++pos; ++pos;
} }
} }
if (newPosition) if (newPosition)