aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2006-05-05 20:44:17 +0000
committerVincent Richard <[email protected]>2006-05-05 20:44:17 +0000
commit4579f8f95abbe799c78254d3d141d5229d1124a2 (patch)
tree173a01441206e75022f00c517e53b43443194777
parentReset timeout before reading response. (diff)
downloadvmime-4579f8f95abbe799c78254d3d141d5229d1124a2.tar.gz
vmime-4579f8f95abbe799c78254d3d141d5229d1124a2.zip
Fixed CRLF response parsing + intermediate replies.
-rw-r--r--src/net/smtp/SMTPResponse.cpp20
1 files 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);
}