Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiline support in mailserver response (220-/250-) #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,40 +577,54 @@ bool ServerPrivate::parseResponseCode(int expectedCode,
Server::SmtpError defaultError,
QByteArray *responseMessage)
{
// Save the server's response
const QByteArray responseText = socket->readLine().trimmed();
qCDebug(SIMPLEMAIL_SERVER) << "Got response" << responseText << "expected" << expectedCode;
while (socket->canReadLine()) {
// Save the server's response
const QByteArray responseText = socket->readLine().trimmed();
qCDebug(SIMPLEMAIL_SERVER) << "Got response" << responseText << "expected" << expectedCode;

// Extract the respose code from the server's responce (first 3 digits)
const int responseCode = responseText.left(3).toInt();
// Extract the respose code from the server's responce (first 3 digits)
const int responseCode = responseText.left(3).toInt();

if (responseCode / 100 == 4) {
failConnection(Server::ServerError, responseCode, QString::fromLatin1(responseText));
return false;
}

if (responseCode / 100 == 5) {
failConnection(Server::ClientError, responseCode, QString::fromLatin1(responseText));
return false;
}
if (responseCode / 100 == 4) {
failConnection(Server::ServerError, responseCode, QString::fromLatin1(responseText));
return false;
}

if (responseText[3] == ' ') {
if (responseCode != expectedCode) {
const QString lastError = QString::fromLatin1(responseText);
qCWarning(SIMPLEMAIL_SERVER)
<< "Unexpected server response" << lastError << expectedCode;
failConnection(defaultError, responseCode, lastError);
if (responseCode / 100 == 5) {
failConnection(Server::ClientError, responseCode, QString::fromLatin1(responseText));
return false;
}
if (responseMessage) {
*responseMessage = responseText.mid(4);

if (responseText[3] == '-') {
if (responseCode != expectedCode) {
const QString lastError = QString::fromLatin1(responseText);
qCWarning(SIMPLEMAIL_SERVER)
<< "Unexpected server response" << lastError << expectedCode;
failConnection(defaultError, responseCode, lastError);
return false;
}
continue;
}

if (responseText[3] == ' ') {
if (responseCode != expectedCode) {
const QString lastError = QString::fromLatin1(responseText);
qCWarning(SIMPLEMAIL_SERVER)
<< "Unexpected server response" << lastError << expectedCode;
failConnection(defaultError, responseCode, lastError);
return false;
}
if (responseMessage) {
*responseMessage = responseText.mid(4);
}
return true;
}
return true;
}

const QString lastError = QString::fromLatin1(responseText);
qCWarning(SIMPLEMAIL_SERVER) << "Unexpected server response" << lastError << expectedCode;
failConnection(defaultError, responseCode, lastError);
const QString lastError = QString::fromLatin1(responseText);
qCWarning(SIMPLEMAIL_SERVER) << "Unexpected server response" << lastError << expectedCode;
failConnection(defaultError, responseCode, lastError);
return false;
}
return false;
}

Expand Down
Loading