diff options
author | Vincent Richard <[email protected]> | 2005-03-12 16:58:59 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2005-03-12 16:58:59 +0000 |
commit | 836c80565f76f5d7b1470ea3341ae939a9846262 (patch) | |
tree | da24a4f57b572cadeb514a52c7a99958c13cbb0c /src/header.cpp | |
parent | Changed first argument of copy_vector() to 'const', to avoid mistakes. (diff) | |
download | vmime-836c80565f76f5d7b1470ea3341ae939a9846262.tar.gz vmime-836c80565f76f5d7b1470ea3341ae939a9846262.zip |
Moved header field parsing to 'headerField::parseNext()'.
Diffstat (limited to 'src/header.cpp')
-rw-r--r-- | src/header.cpp | 148 |
1 files changed, 3 insertions, 145 deletions
diff --git a/src/header.cpp b/src/header.cpp index 886283ba..db6c7f89 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -64,152 +64,10 @@ void header::parse(const string& buffer, const string::size_type position, while (pos < end) { - char_t c = buffer[pos]; + headerField* field = headerField::parseNext(buffer, pos, end, &pos); + if (field == NULL) break; - // Check for end of headers (empty line): although RFC-822 recommends - // to use CRLF for header/body separator (see 4.1 SYNTAX), here, we - // also check for LF just in case... - if (c == '\n') - { - ++pos; - break; - } - else if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') - { - pos += 2; - break; - } - - // This line may be a field description - if (!parserHelpers::isspace(c)) - { - const string::size_type nameStart = pos; // remember the start position of the line - - while (pos < end && (buffer[pos] != ':' && !parserHelpers::isspace(buffer[pos]))) - ++pos; - - const string::size_type nameEnd = pos; - - while (pos < end && parserHelpers::isspace(buffer[pos])) - ++pos; - - if (buffer[pos] != ':') - { - // 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') - ++pos; - - if (buffer[pos] == '\n') - ++pos; - } - else - { - // Extract the field name - const string name(buffer.begin() + nameStart, - buffer.begin() + nameEnd); - - // Skip ':' character - ++pos; - - // Skip spaces between ':' and the field contents - while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) - ++pos; - - // Extract the field value - string contents; - - while (pos < end) - { - c = buffer[pos]; - - // Check for end of contents - if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') - { - pos += 2; - break; - } - else if (c == '\n') - { - ++pos; - break; - } - - const string::size_type ctsStart = pos; - string::size_type ctsEnd = pos; - - while (pos < end) - { - c = buffer[pos]; - - // Check for end of line - if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') - { - ctsEnd = pos; - pos += 2; - break; - } - else if (c == '\n') - { - ctsEnd = pos; - ++pos; - break; - } - - ++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') - { - // This is a folding white-space: we keep it as is and - // we continue with contents parsing... - } - else - { - // End of this field - break; - } - } - - // Add a new field to list - m_fields.push_back(headerFieldFactory::getInstance()-> - create(name, contents)); - } - } - else - { - // Skip this error and advance to the next line - while (pos < end && buffer[pos] != '\n') - ++pos; - - if (buffer[pos] == '\n') - ++pos; - } - } - - // If we have found the header/body separator, skip it - if (pos < end) - { - if (buffer[pos] == '\n') - { - // This is a LF (illegal but...) - ++pos; - } - else if (buffer[pos] == '\r' && pos + 1 < end) - { - // This is a CRLF - pos += 2; - } + m_fields.push_back(field); } setParsedBounds(position, pos); |