|
|
|
@ -58,9 +58,8 @@ namespace
@@ -58,9 +58,8 @@ namespace
|
|
|
|
|
QByteArray hmacMD5(QByteArray key, const QByteArray &msg) |
|
|
|
|
{ |
|
|
|
|
const int blockSize = 64; // HMAC-MD5 block size
|
|
|
|
|
if (key.length() > blockSize) { // if key is longer than block size (64), reduce key length with MD5 compression
|
|
|
|
|
if (key.length() > blockSize) // if key is longer than block size (64), reduce key length with MD5 compression
|
|
|
|
|
key = QCryptographicHash::hash(key, QCryptographicHash::Md5); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QByteArray innerPadding(blockSize, char(0x36)); // initialize inner padding with char "6"
|
|
|
|
|
QByteArray outerPadding(blockSize, char(0x5c)); // initialize outer padding with char "\"
|
|
|
|
@ -133,7 +132,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
@@ -133,7 +132,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
|
|
|
|
|
+ "\r\n"; |
|
|
|
|
// Encode the body in base64
|
|
|
|
|
QString crlf_body = body; |
|
|
|
|
QByteArray b = crlf_body.replace("\n","\r\n").toUtf8().toBase64(); |
|
|
|
|
QByteArray b = crlf_body.replace("\n", "\r\n").toUtf8().toBase64(); |
|
|
|
|
int ct = b.length(); |
|
|
|
|
for (int i = 0; i < ct; i += 78) |
|
|
|
|
m_message += b.mid(i, 78); |
|
|
|
@ -156,7 +155,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
@@ -156,7 +155,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
|
|
|
|
|
m_socket->connectToHost(pref->getMailNotificationSMTP(), DEFAULT_PORT); |
|
|
|
|
m_useSsl = false; |
|
|
|
|
#ifndef QT_NO_OPENSSL |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -185,7 +184,7 @@ void Smtp::readyRead()
@@ -185,7 +184,7 @@ void Smtp::readyRead()
|
|
|
|
|
ehlo(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
logError("Connection failed, unrecognized reply: "+line); |
|
|
|
|
logError("Connection failed, unrecognized reply: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -222,7 +221,7 @@ void Smtp::readyRead()
@@ -222,7 +221,7 @@ void Smtp::readyRead()
|
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// Authentication failed!
|
|
|
|
|
logError("Authentication failed, msg: "+line); |
|
|
|
|
logError("Authentication failed, msg: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -233,7 +232,7 @@ void Smtp::readyRead()
@@ -233,7 +232,7 @@ void Smtp::readyRead()
|
|
|
|
|
m_state = Data; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
logError("<mail from> was rejected by server, msg: "+line); |
|
|
|
|
logError("<mail from> was rejected by server, msg: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -244,7 +243,7 @@ void Smtp::readyRead()
@@ -244,7 +243,7 @@ void Smtp::readyRead()
|
|
|
|
|
m_state = Body; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
logError("<Rcpt to> was rejected by server, msg: "+line); |
|
|
|
|
logError("<Rcpt to> was rejected by server, msg: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -255,7 +254,7 @@ void Smtp::readyRead()
@@ -255,7 +254,7 @@ void Smtp::readyRead()
|
|
|
|
|
m_state = Quit; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
logError("<data> was rejected by server, msg: "+line); |
|
|
|
|
logError("<data> was rejected by server, msg: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -267,7 +266,7 @@ void Smtp::readyRead()
@@ -267,7 +266,7 @@ void Smtp::readyRead()
|
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
logError("Message was rejected by the server, error: "+line); |
|
|
|
|
logError("Message was rejected by the server, error: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -346,7 +345,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, bool continued, const QStri
@@ -346,7 +345,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, bool continued, const QStri
|
|
|
|
|
else { |
|
|
|
|
// Both EHLO and HELO failed, chances are this is NOT
|
|
|
|
|
// a SMTP server
|
|
|
|
|
logError("Both EHLO and HELO failed, msg: "+line); |
|
|
|
|
logError("Both EHLO and HELO failed, msg: " + line); |
|
|
|
|
m_state = Close; |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
@ -361,7 +360,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, bool continued, const QStri
@@ -361,7 +360,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, bool continued, const QStri
|
|
|
|
|
else { |
|
|
|
|
// greeting followed by extensions
|
|
|
|
|
m_state = EhloGreetReceived; |
|
|
|
|
qDebug () << "EHLO greet received"; |
|
|
|
|
qDebug() << "EHLO greet received"; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -418,7 +417,7 @@ void Smtp::authenticate()
@@ -418,7 +417,7 @@ void Smtp::authenticate()
|
|
|
|
|
// Skip authentication
|
|
|
|
|
logError("The SMTP server does not seem to support any of the authentications modes " |
|
|
|
|
"we support [CRAM-MD5|PLAIN|LOGIN], skipping authentication, " |
|
|
|
|
"knowing it is likely to fail... Server Auth Modes: "+auth.join("|")); |
|
|
|
|
"knowing it is likely to fail... Server Auth Modes: " + auth.join("|")); |
|
|
|
|
m_state = Authenticated; |
|
|
|
|
// At this point the server will not send any response
|
|
|
|
|
// So fill the buffer with a fake one to pass the tests
|
|
|
|
@ -469,7 +468,7 @@ void Smtp::authPlain()
@@ -469,7 +468,7 @@ void Smtp::authPlain()
|
|
|
|
|
auth += m_password.toLatin1(); |
|
|
|
|
qDebug() << "password: " << m_password.toLatin1(); |
|
|
|
|
// Send it
|
|
|
|
|
m_socket->write("auth plain "+ auth.toBase64() + "\r\n"); |
|
|
|
|
m_socket->write("auth plain " + auth.toBase64() + "\r\n"); |
|
|
|
|
m_socket->flush(); |
|
|
|
|
m_state = AuthSent; |
|
|
|
|
} |
|
|
|
|