diff --git a/src/headerField.cpp b/src/headerField.cpp index 59b10e76..7d23ce84 100644 --- a/src/headerField.cpp +++ b/src/headerField.cpp @@ -142,7 +142,7 @@ ref headerField::parseNext ++pos; const string::size_type contentsStart = pos; - string::size_type contentsEnd = 0; + string::size_type contentsEnd = end; // Extract the field value while (pos < end) diff --git a/tests/parser/headerFieldTest.cpp b/tests/parser/headerFieldTest.cpp index c152690f..9d8f9dfa 100644 --- a/tests/parser/headerFieldTest.cpp +++ b/tests/parser/headerFieldTest.cpp @@ -28,6 +28,7 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest) VMIME_TEST_LIST_BEGIN VMIME_TEST(testBadValueType) + VMIME_TEST(testValueOnNextLine) VMIME_TEST_LIST_END @@ -49,4 +50,20 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest) custom->setValue(vmime::text("field value text"))); } + void testValueOnNextLine() + { + vmime::parsingContext ctx; + + const vmime::string buffer = "Field: \r\n\tfield data"; + + vmime::ref hfield = + vmime::headerField::parseNext(ctx, buffer, 0, buffer.size()); + + vmime::ref hvalue = + hfield->getValue().dynamicCast (); + + VASSERT_EQ("Field name", "Field", hfield->getName()); + VASSERT_EQ("Field value", "field data", hvalue->getWholeBuffer()); + } + VMIME_TEST_SUITE_END diff --git a/vmime/headerField.hpp b/vmime/headerField.hpp index 72d639c9..a6e80e32 100644 --- a/vmime/headerField.hpp +++ b/vmime/headerField.hpp @@ -124,6 +124,23 @@ public: void setValue(const string& value); + /** Parse a header field from a buffer. + * + * @param ctx parsing context + * @param buffer input buffer + * @param position current position in the input buffer + * @param end end position in the input buffer + * @param newPosition will receive the new position in the input buffer + * @return parsed header field, or NULL if no more header field can be parsed + * in the input buffer + */ + static ref parseNext + (const parsingContext& ctx, + const string& buffer, + const string::size_type position, + const string::size_type end, + string::size_type* newPosition = NULL); + protected: void parseImpl @@ -140,14 +157,6 @@ protected: string::size_type* newLinePos = NULL) const; - static ref parseNext - (const parsingContext& ctx, - const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); - - string m_name; ref m_value; };