This commit is contained in:
Vincent Richard 2017-03-29 21:28:45 +02:00
commit 8e6db1c7a6
4 changed files with 60 additions and 14 deletions

View File

@ -128,7 +128,7 @@ size_t body::findNextBoundaryPosition
void body::parseImpl void body::parseImpl
(const parsingContext& /* ctx */, (const parsingContext& ctx,
shared_ptr <utility::parserInputStreamAdapter> parser, shared_ptr <utility::parserInputStreamAdapter> parser,
const size_t position, const size_t end, size_t* newPosition) const size_t position, const size_t end, size_t* newPosition)
{ {
@ -286,7 +286,7 @@ void body::parseImpl
if (partEnd > partStart) if (partEnd > partStart)
{ {
vmime::text text; vmime::text text;
text.parse(parser, partStart, partEnd); text.parse(ctx, parser, partStart, partEnd);
m_prologText = text.getWholeBuffer(); m_prologText = text.getWholeBuffer();
} }
@ -304,7 +304,7 @@ void body::parseImpl
if (partEnd < partStart) if (partEnd < partStart)
std::swap(partStart, partEnd); std::swap(partStart, partEnd);
part->parse(parser, partStart, partEnd, NULL); part->parse(ctx, parser, partStart, partEnd, NULL);
m_parts.push_back(part); m_parts.push_back(part);
} }
@ -325,7 +325,7 @@ void body::parseImpl
try try
{ {
part->parse(parser, partStart, end); part->parse(ctx, parser, partStart, end);
} }
catch (std::exception&) catch (std::exception&)
{ {
@ -338,7 +338,7 @@ void body::parseImpl
else if (partStart < end) else if (partStart < end)
{ {
vmime::text text; vmime::text text;
text.parse(parser, partStart, end); text.parse(ctx, parser, partStart, end);
m_epilogText = text.getWholeBuffer(); m_epilogText = text.getWholeBuffer();
} }

View File

@ -118,15 +118,27 @@ shared_ptr <headerField> headerField::parseNext
if (buffer[pos] != ':') if (buffer[pos] != ':')
{ {
// Humm...does not seem to be a valid header line. switch (ctx.getHeaderParseErrorRecoveryMethod()) {
// Skip this error and advance to the next line case vmime::headerParseRecoveryMethod::SKIP_LINE:
pos = nameStart; // Humm...does not seem to be a valid header line.
// Skip this error and advance to the next line
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;
// case vmime::headerParseRecoveryMethod::APPEND_TO_PREVIOUS_LINE:
// // TODO Implement this...
// break;
case vmime::headerParseRecoveryMethod::ASSUME_END_OF_HEADERS:
return null;
break;
}
} }
else else
{ {

View File

@ -28,13 +28,13 @@ namespace vmime
{ {
parsingContext::parsingContext() parsingContext::parsingContext() : m_headerParseErrorRecovery(vmime::headerParseRecoveryMethod::SKIP_LINE)
{ {
} }
parsingContext::parsingContext(const parsingContext& ctx) parsingContext::parsingContext(const parsingContext& ctx)
: context(ctx) : context(ctx), m_headerParseErrorRecovery(vmime::headerParseRecoveryMethod::SKIP_LINE)
{ {
} }
@ -45,5 +45,16 @@ parsingContext& parsingContext::getDefaultContext()
return ctx; return ctx;
} }
headerParseRecoveryMethod::headerLineError parsingContext::getHeaderParseErrorRecoveryMethod() const
{
return m_headerParseErrorRecovery;
}
void parsingContext::setHeaderParseErrorRecoveryMethod(headerParseRecoveryMethod::headerLineError recoveryMethod)
{
m_headerParseErrorRecovery = recoveryMethod;
}
} // vmime } // vmime

View File

@ -31,6 +31,15 @@
namespace vmime namespace vmime
{ {
/** Provides runtime configurable options to provide flexibility in header parsing
*/
struct headerParseRecoveryMethod {
enum headerLineError {
SKIP_LINE = 0,
/* APPEND_TO_PREVIOUS_LINE = 1, */
ASSUME_END_OF_HEADERS = 2
};
};
/** Holds configuration parameters used for parsing messages. /** Holds configuration parameters used for parsing messages.
*/ */
@ -48,8 +57,22 @@ public:
*/ */
static parsingContext& getDefaultContext(); static parsingContext& getDefaultContext();
/** Sets the recovery method when parsing a header encounters an error such as a failed fold or missing new line.
*
* @param recoveryMethod is one of vmime::headerParseRecoveryMethod. Defaults to vmime::headerParseRecoveryMethod::SKIP_LINE.
*/
void setHeaderParseErrorRecoveryMethod(headerParseRecoveryMethod::headerLineError recoveryMethod);
/** Return the recovery method when parsing a header encounters an error.
*
* @return is an enum from vmime::headerParseRecoveryMethod
*/
headerParseRecoveryMethod::headerLineError getHeaderParseErrorRecoveryMethod() const;
protected: protected:
headerParseRecoveryMethod::headerLineError m_headerParseErrorRecovery;
}; };