From 4493a7f801bcbf3dff648b7f89432660ea69c2fd Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 15 Mar 2005 17:31:26 +0000 Subject: [PATCH] Fixed parsing bounds for header fields and values. --- src/address.cpp | 2 ++ src/headerField.cpp | 23 ++++++++--------------- src/mailboxField.cpp | 2 ++ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/address.cpp b/src/address.cpp index 14786d54..cf13a007 100644 --- a/src/address.cpp +++ b/src/address.cpp @@ -178,6 +178,8 @@ address* address::parseNext(const string& buffer, const string::size_type positi try { parsedAddress->parse(buffer, start, pos, NULL); + parsedAddress->setParsedBounds(start, pos); + return (parsedAddress); } catch (std::exception&) diff --git a/src/headerField.cpp b/src/headerField.cpp index 7c8562da..5fe7a389 100644 --- a/src/headerField.cpp +++ b/src/headerField.cpp @@ -134,9 +134,10 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) ++pos; - // Extract the field value - string contents; + const string::size_type contentsStart = pos; + string::size_type contentsEnd = 0; + // Extract the field value while (pos < end) { c = buffer[pos]; @@ -144,18 +145,17 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ // Check for end of contents if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') { + contentsEnd = pos; pos += 2; break; } else if (c == '\n') { + contentsEnd = pos; ++pos; break; } - const string::size_type ctsStart = pos; - string::size_type ctsEnd = pos; - while (pos < end) { c = buffer[pos]; @@ -163,13 +163,13 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ // Check for end of line if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') { - ctsEnd = pos; + contentsEnd = pos; pos += 2; break; } else if (c == '\n') { - ctsEnd = pos; + contentsEnd = pos; ++pos; break; } @@ -177,13 +177,6 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ ++pos; } - if (ctsEnd != ctsStart) - { - // Append this line to contents - contents.append(buffer.begin() + ctsStart, - buffer.begin() + ctsEnd); - } - // Handle the case of folded lines if (buffer[pos] == ' ' || buffer[pos] == '\t') { @@ -200,7 +193,7 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ // Return a new field headerField* field = headerFieldFactory::getInstance()->create(name); - field->parse(contents); // TODO: fix incorrect parsed bounds... + field->parse(buffer, contentsStart, contentsEnd, NULL); field->setParsedBounds(nameStart, pos); if (newPosition) diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp index 3fe023c0..af220c50 100644 --- a/src/mailboxField.cpp +++ b/src/mailboxField.cpp @@ -66,6 +66,8 @@ void mailboxField::parse(const string& buffer, const string::size_type position, delete (parsedAddress); + getValue().setParsedBounds(position, end); + setParsedBounds(position, end); if (newPosition)