From 4579f8f95abbe799c78254d3d141d5229d1124a2 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 5 May 2006 20:44:17 +0000 Subject: [PATCH] Fixed CRLF response parsing + intermediate replies. --- src/net/smtp/SMTPResponse.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/net/smtp/SMTPResponse.cpp b/src/net/smtp/SMTPResponse.cpp index c39774b1..b27876f6 100644 --- a/src/net/smtp/SMTPResponse.cpp +++ b/src/net/smtp/SMTPResponse.cpp @@ -114,11 +114,16 @@ const string SMTPResponse::readResponseLine() while (true) { // Get a line from the response buffer - string::size_type lineEnd = currentBuffer.find_first_of('\n'); + const string::size_type lineEnd = currentBuffer.find_first_of('\n'); if (lineEnd != string::npos) { - const string line(currentBuffer.begin(), currentBuffer.begin() + lineEnd); + string::size_type actualLineEnd = lineEnd; + + if (actualLineEnd != 0 && currentBuffer[actualLineEnd - 1] == '\r') // CRLF case + actualLineEnd--; + + const string line(currentBuffer.begin(), currentBuffer.begin() + actualLineEnd); currentBuffer.erase(currentBuffer.begin(), currentBuffer.begin() + lineEnd + 1); m_responseBuffer = currentBuffer; @@ -154,19 +159,20 @@ const SMTPResponse::responseLine SMTPResponse::getNextResponse() { string line = readResponseLine(); - // Special case where CRLF occurs after response code - if (line.length() < 4) - line = line + '\n' + readResponseLine(); - const int code = extractResponseCode(line); string text; + // Special case where CRLF occurs after response code + // in "Positive Intermediate replies" (3yz reply) + if (line.length() < 4 && (code / 100) == 3) + line = line + '\n' + readResponseLine(); + m_responseContinues = (line.length() >= 4 && line[3] == '-'); if (line.length() > 4) text = utility::stringUtils::trim(line.substr(4)); else - text = utility::stringUtils::trim(line); + text = ""; return responseLine(code, text); }