mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice
Add lock around deleting arrows for commanding cards Add support for Qt6 w/ Backwards Qt5 Handle Qt5/6 cross compilation better Last cleanups caps matter Fix serv Prevent crash on 6.3.0 Linux & bump to 5.8 min Prevent out of bounds indexing Delete shutdown timer if it exists Fixup ticket comments, remove unneeded guards Try to add support for missing OSes Update .ci/release_template.md Update PR based on comments Update XML name after done and remove Hirsute Address local game crash Address comments from PR (again) Tests don't work on mac, will see if a problem on other OSes make soundengine more consistent across qt versions disable tests on distros that are covered by others Fix Oracle Crash due to bad memory access Update Oracle to use new Qt6 way of adding translations Add support for Qt5/Qt6 compiling of Cockatrice Remove unneeded calls to QtMath/cmath/math.h Update how we handle bitwise comparisons for enums with Tray Icon Change header guards to not duplicate function Leave comment & Fix Path for GHA Qt Update common/server.h Update cockatrice/src/window_main.cpp Rollback change on cmake module path for NSIS check docker image requirements add size limit to ccache put variables in quotes properly set build type on mac avoid names used in cmake fix up cmake module path cmake 3.10 does not recognize prepend Support Tests in FindQtRuntime set ccache size on non debug builds as well immediately return when removing non existing client handle incTxBytes with a signal instead don't set common link libraries in cockatrice/CMakeLists.txt add comments set macos qt version to 6 Try upgrading XCode versions to latest they can be supported on Ensure Qt gets linked add tmate so i can see what's going on Qt6 points two directories further down than Qt5 with regard to the top lib path, so we need to account for this Establish Plugins directory for Qt6 Establish TLS plugins for Qt6 services Minor change for release channel network manager Let windows build in parallel cores Wrong symbols Qt6 patch up for signal add missing qt6 package on deb builds boolean expressions are hard negative indexes should go to the end Intentionally fail cache move size checks to individual zone types Hardcode libs needed for building on Windows, as the regex was annoying Update wording use the --parallel option in all builds clean up the .ci scripts some more tweak fedora build add os parameter to compile.sh I don't really like this but it seems the easiest way I'd prefer if these types of quirks would live in the main configuration file, the yml fixup yml readd appended cache key to vcpkg step fix windows 32 quirk the json hash is already added to the key as well remove os parameter and clean up ci files set name_build.sh to output relative paths set backwards compatible version of xcode and qt on mac set QTDIR for mac builds on qt5 has no effect for qt6 export BUILD_DIR to name_build.sh merge mac build steps merge homebrew steps, set package suffix link qt5 remove brew link set qtdir to qt5 only compile.sh vars need to be empty not 0 fix sets manager search bar on qt 5.12/15 fix oracle subprocess errors being ignored on qt 5 clean up translation loading move en@source translation file so it will not get included in packages NOTE: this needs to be done at transifex as well! Use generator platform over osname Short circuit if not Win defined
This commit is contained in:
parent
accd5e4df7
commit
b02adccf87
114 changed files with 1925 additions and 1603 deletions
|
|
@ -23,39 +23,44 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \class QxtSmtp
|
||||
* \inmodule QxtNetwork
|
||||
* \brief The QxtSmtp class implements the SMTP protocol for sending email
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "qxtsmtp.h"
|
||||
#include "qxtsmtp_p.h"
|
||||
|
||||
#include "qxthmac.h"
|
||||
#include <QStringList>
|
||||
#include <QTcpSocket>
|
||||
#include "qxtsmtp_p.h"
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#include <QSslSocket>
|
||||
#include <QStringList>
|
||||
#include <QTcpSocket>
|
||||
|
||||
QxtSmtpPrivate::QxtSmtpPrivate() : QObject(0)
|
||||
{
|
||||
// empty ctor
|
||||
}
|
||||
|
||||
QxtSmtp::QxtSmtp(QObject* parent) : QObject(parent)
|
||||
QxtSmtp::QxtSmtp(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtSmtp);
|
||||
qxt_d().state = QxtSmtpPrivate::Disconnected;
|
||||
qxt_d().nextID = 0;
|
||||
qxt_d().socket = new QSslSocket(this);
|
||||
QObject::connect(socket(), SIGNAL(encrypted()), this, SIGNAL(encrypted()));
|
||||
//QObject::connect(socket(), SIGNAL(encrypted()), &qxt_d(), SLOT(ehlo()));
|
||||
// QObject::connect(socket(), SIGNAL(encrypted()), &qxt_d(), SLOT(ehlo()));
|
||||
QObject::connect(socket(), SIGNAL(connected()), this, SIGNAL(connected()));
|
||||
QObject::connect(socket(), SIGNAL(disconnected()), this, SIGNAL(disconnected()));
|
||||
QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), &qxt_d(), SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QObject::connect(socket(), SIGNAL(errorOccurred(QAbstractSocket::SocketError)), &qxt_d(),
|
||||
SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#else
|
||||
QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), &qxt_d(),
|
||||
SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#endif
|
||||
QObject::connect(this, SIGNAL(authenticated()), &qxt_d(), SLOT(sendNext()));
|
||||
QObject::connect(socket(), SIGNAL(readyRead()), &qxt_d(), SLOT(socketRead()));
|
||||
}
|
||||
|
|
@ -65,7 +70,7 @@ QByteArray QxtSmtp::username() const
|
|||
return qxt_d().username;
|
||||
}
|
||||
|
||||
void QxtSmtp::setUsername(const QByteArray& username)
|
||||
void QxtSmtp::setUsername(const QByteArray &username)
|
||||
{
|
||||
qxt_d().username = username;
|
||||
}
|
||||
|
|
@ -75,12 +80,12 @@ QByteArray QxtSmtp::password() const
|
|||
return qxt_d().password;
|
||||
}
|
||||
|
||||
void QxtSmtp::setPassword(const QByteArray& password)
|
||||
void QxtSmtp::setPassword(const QByteArray &password)
|
||||
{
|
||||
qxt_d().password = password;
|
||||
}
|
||||
|
||||
int QxtSmtp::send(const QxtMailMessage& message)
|
||||
int QxtSmtp::send(const QxtMailMessage &message)
|
||||
{
|
||||
int messageID = ++qxt_d().nextID;
|
||||
qxt_d().pending.append(qMakePair(messageID, message));
|
||||
|
|
@ -94,19 +99,19 @@ int QxtSmtp::pendingMessages() const
|
|||
return qxt_d().pending.count();
|
||||
}
|
||||
|
||||
QTcpSocket* QxtSmtp::socket() const
|
||||
QTcpSocket *QxtSmtp::socket() const
|
||||
{
|
||||
return qxt_d().socket;
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToHost(const QString& hostName, quint16 port)
|
||||
void QxtSmtp::connectToHost(const QString &hostName, quint16 port)
|
||||
{
|
||||
qxt_d().useSecure = false;
|
||||
qxt_d().state = QxtSmtpPrivate::StartState;
|
||||
socket()->connectToHost(hostName, port);
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToHost(const QHostAddress& address, quint16 port)
|
||||
void QxtSmtp::connectToHost(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
connectToHost(address.toString(), port);
|
||||
}
|
||||
|
|
@ -126,157 +131,141 @@ void QxtSmtp::setStartTlsDisabled(bool disable)
|
|||
qxt_d().disableStartTLS = disable;
|
||||
}
|
||||
|
||||
QSslSocket* QxtSmtp::sslSocket() const
|
||||
QSslSocket *QxtSmtp::sslSocket() const
|
||||
{
|
||||
return qxt_d().socket;
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToSecureHost(const QString& hostName, quint16 port)
|
||||
void QxtSmtp::connectToSecureHost(const QString &hostName, quint16 port)
|
||||
{
|
||||
qxt_d().useSecure = true;
|
||||
qxt_d().state = QxtSmtpPrivate::StartState;
|
||||
sslSocket()->connectToHostEncrypted(hostName, port);
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToSecureHost(const QHostAddress& address, quint16 port)
|
||||
void QxtSmtp::connectToSecureHost(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
connectToSecureHost(address.toString(), port);
|
||||
}
|
||||
|
||||
bool QxtSmtp::hasExtension(const QString& extension)
|
||||
bool QxtSmtp::hasExtension(const QString &extension)
|
||||
{
|
||||
return qxt_d().extensions.contains(extension);
|
||||
}
|
||||
|
||||
QString QxtSmtp::extensionData(const QString& extension)
|
||||
QString QxtSmtp::extensionData(const QString &extension)
|
||||
{
|
||||
return qxt_d().extensions[extension];
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::socketError(QAbstractSocket::SocketError err)
|
||||
{
|
||||
if (err == QAbstractSocket::SslHandshakeFailedError)
|
||||
{
|
||||
if (err == QAbstractSocket::SslHandshakeFailedError) {
|
||||
emit qxt_p().encryptionFailed();
|
||||
emit qxt_p().encryptionFailed( socket->errorString().toLatin1() );
|
||||
}
|
||||
else if (state == StartState)
|
||||
{
|
||||
emit qxt_p().encryptionFailed(socket->errorString().toLatin1());
|
||||
} else if (state == StartState) {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed( socket->errorString().toLatin1() );
|
||||
emit qxt_p().connectionFailed(socket->errorString().toLatin1());
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::socketRead()
|
||||
{
|
||||
buffer += socket->readAll();
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
int pos = buffer.indexOf("\r\n");
|
||||
if (pos < 0) return;
|
||||
if (pos < 0)
|
||||
return;
|
||||
QByteArray line = buffer.left(pos);
|
||||
buffer = buffer.mid(pos + 2);
|
||||
QByteArray code = line.left(3);
|
||||
switch (state)
|
||||
{
|
||||
case StartState:
|
||||
if (code[0] != '2')
|
||||
{
|
||||
socket->disconnectFromHost();
|
||||
}
|
||||
else
|
||||
{
|
||||
ehlo();
|
||||
}
|
||||
break;
|
||||
case HeloSent:
|
||||
case EhloSent:
|
||||
case EhloGreetReceived:
|
||||
parseEhlo(code, (line[3] != ' '), line.mid(4));
|
||||
break;
|
||||
case StartTLSSent:
|
||||
if (code == "220")
|
||||
{
|
||||
socket->startClientEncryption();
|
||||
ehlo();
|
||||
}
|
||||
else
|
||||
{
|
||||
authenticate();
|
||||
}
|
||||
break;
|
||||
case AuthRequestSent:
|
||||
case AuthUsernameSent:
|
||||
if (authType == AuthPlain) authPlain();
|
||||
else if (authType == AuthLogin) authLogin();
|
||||
else authCramMD5(line.mid(4));
|
||||
break;
|
||||
case AuthSent:
|
||||
if (code[0] == '2')
|
||||
{
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
else
|
||||
{
|
||||
state = Disconnected;
|
||||
emit qxt_p().authenticationFailed();
|
||||
emit qxt_p().authenticationFailed( line );
|
||||
emit socket->disconnectFromHost();
|
||||
}
|
||||
break;
|
||||
case MailToSent:
|
||||
case RcptAckPending:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed( pending.first().first, code.toInt() );
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
// pending.removeFirst();
|
||||
// DO NOT remove it, the body sent state needs this message to assigned the next mail failed message that will
|
||||
// the sendNext
|
||||
// a reset will be sent to clear things out
|
||||
switch (state) {
|
||||
case StartState:
|
||||
if (code[0] != '2') {
|
||||
socket->disconnectFromHost();
|
||||
} else {
|
||||
ehlo();
|
||||
}
|
||||
break;
|
||||
case HeloSent:
|
||||
case EhloSent:
|
||||
case EhloGreetReceived:
|
||||
parseEhlo(code, (line[3] != ' '), line.mid(4));
|
||||
break;
|
||||
case StartTLSSent:
|
||||
if (code == "220") {
|
||||
socket->startClientEncryption();
|
||||
ehlo();
|
||||
} else {
|
||||
authenticate();
|
||||
}
|
||||
break;
|
||||
case AuthRequestSent:
|
||||
case AuthUsernameSent:
|
||||
if (authType == AuthPlain)
|
||||
authPlain();
|
||||
else if (authType == AuthLogin)
|
||||
authLogin();
|
||||
else
|
||||
authCramMD5(line.mid(4));
|
||||
break;
|
||||
case AuthSent:
|
||||
if (code[0] == '2') {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
} else {
|
||||
state = Disconnected;
|
||||
emit qxt_p().authenticationFailed();
|
||||
emit qxt_p().authenticationFailed(line);
|
||||
emit socket->disconnectFromHost();
|
||||
}
|
||||
break;
|
||||
case MailToSent:
|
||||
case RcptAckPending:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt());
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
// pending.removeFirst();
|
||||
// DO NOT remove it, the body sent state needs this message to assigned the next mail failed message
|
||||
// that will the sendNext a reset will be sent to clear things out
|
||||
sendNext();
|
||||
state = BodySent;
|
||||
} else
|
||||
sendNextRcpt(code, line);
|
||||
break;
|
||||
case SendingBody:
|
||||
sendBody(code, line);
|
||||
break;
|
||||
case BodySent:
|
||||
if (pending.count()) {
|
||||
// if you removeFirst in RcpActpending/MailToSent on an error, and the queue is now empty,
|
||||
// you will get into this state and then crash because no check is done. CHeck added but shouldnt
|
||||
// be necessary since I commented out the removeFirst
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt());
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
} else
|
||||
emit qxt_p().mailSent(pending.first().first);
|
||||
pending.removeFirst();
|
||||
}
|
||||
sendNext();
|
||||
state = BodySent;
|
||||
}
|
||||
else
|
||||
sendNextRcpt(code, line);
|
||||
break;
|
||||
case SendingBody:
|
||||
sendBody(code, line);
|
||||
break;
|
||||
case BodySent:
|
||||
if ( pending.count() )
|
||||
{
|
||||
// if you removeFirst in RcpActpending/MailToSent on an error, and the queue is now empty,
|
||||
// you will get into this state and then crash because no check is done. CHeck added but shouldnt
|
||||
// be necessary since I commented out the removeFirst
|
||||
if (code[0] != '2')
|
||||
{
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt() );
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
}
|
||||
else
|
||||
emit qxt_p().mailSent(pending.first().first);
|
||||
pending.removeFirst();
|
||||
}
|
||||
sendNext();
|
||||
break;
|
||||
case Resetting:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed( line );
|
||||
}
|
||||
else {
|
||||
state = Waiting;
|
||||
sendNext();
|
||||
}
|
||||
break;
|
||||
case Disconnected:
|
||||
case EhloExtensionsReceived:
|
||||
case EhloDone:
|
||||
case Authenticated:
|
||||
case Waiting:
|
||||
// only to make compiler happy
|
||||
break;
|
||||
break;
|
||||
case Resetting:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed(line);
|
||||
} else {
|
||||
state = Waiting;
|
||||
sendNext();
|
||||
}
|
||||
break;
|
||||
case Disconnected:
|
||||
case EhloExtensionsReceived:
|
||||
case EhloDone:
|
||||
case Authenticated:
|
||||
case Waiting:
|
||||
// only to make compiler happy
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -284,8 +273,7 @@ void QxtSmtpPrivate::socketRead()
|
|||
void QxtSmtpPrivate::ehlo()
|
||||
{
|
||||
QByteArray address = "127.0.0.1";
|
||||
foreach(const QHostAddress& addr, QNetworkInterface::allAddresses())
|
||||
{
|
||||
foreach (const QHostAddress &addr, QNetworkInterface::allAddresses()) {
|
||||
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6)
|
||||
continue;
|
||||
address = addr.toString().toLatin1();
|
||||
|
|
@ -296,53 +284,40 @@ void QxtSmtpPrivate::ehlo()
|
|||
state = EhloSent;
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::parseEhlo(const QByteArray& code, bool cont, const QString& line)
|
||||
void QxtSmtpPrivate::parseEhlo(const QByteArray &code, bool cont, const QString &line)
|
||||
{
|
||||
if (code != "250")
|
||||
{
|
||||
if (code != "250") {
|
||||
// error!
|
||||
if (state != HeloSent)
|
||||
{
|
||||
if (state != HeloSent) {
|
||||
// maybe let's try HELO
|
||||
socket->write("helo\r\n");
|
||||
state = HeloSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// nope
|
||||
socket->write("QUIT\r\n");
|
||||
socket->flush();
|
||||
socket->disconnectFromHost();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (state != EhloGreetReceived)
|
||||
{
|
||||
if (!cont)
|
||||
{
|
||||
} else if (state != EhloGreetReceived) {
|
||||
if (!cont) {
|
||||
// greeting only, no extensions
|
||||
state = EhloDone;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// greeting followed by extensions
|
||||
state = EhloGreetReceived;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
extensions[line.section(' ', 0, 0).toUpper()] = line.section(' ', 1);
|
||||
if (!cont)
|
||||
state = EhloDone;
|
||||
}
|
||||
if (state != EhloDone) return;
|
||||
if (extensions.contains("STARTTLS") && !disableStartTLS)
|
||||
{
|
||||
if (state != EhloDone)
|
||||
return;
|
||||
if (extensions.contains("STARTTLS") && !disableStartTLS) {
|
||||
startTLS();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
authenticate();
|
||||
}
|
||||
}
|
||||
|
|
@ -355,48 +330,35 @@ void QxtSmtpPrivate::startTLS()
|
|||
|
||||
void QxtSmtpPrivate::authenticate()
|
||||
{
|
||||
if (!extensions.contains("AUTH") || username.isEmpty() || password.isEmpty())
|
||||
{
|
||||
if (!extensions.contains("AUTH") || username.isEmpty() || password.isEmpty()) {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList auth = extensions["AUTH"].toUpper().split(' ', Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList auth = extensions["AUTH"].toUpper().split(' ', QString::SkipEmptyParts);
|
||||
#endif
|
||||
if (auth.contains("CRAM-MD5"))
|
||||
{
|
||||
if (auth.contains("CRAM-MD5")) {
|
||||
authCramMD5();
|
||||
}
|
||||
else if (auth.contains("PLAIN"))
|
||||
{
|
||||
} else if (auth.contains("PLAIN")) {
|
||||
authPlain();
|
||||
}
|
||||
else if (auth.contains("LOGIN"))
|
||||
{
|
||||
} else if (auth.contains("LOGIN")) {
|
||||
authLogin();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::authCramMD5(const QByteArray& challenge)
|
||||
void QxtSmtpPrivate::authCramMD5(const QByteArray &challenge)
|
||||
{
|
||||
if (state != AuthRequestSent)
|
||||
{
|
||||
if (state != AuthRequestSent) {
|
||||
socket->write("auth cram-md5\r\n");
|
||||
authType = AuthCramMD5;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QxtHmac hmac(QCryptographicHash::Md5);
|
||||
hmac.setKey(password);
|
||||
hmac.addData(QByteArray::fromBase64(challenge));
|
||||
|
|
@ -408,14 +370,11 @@ void QxtSmtpPrivate::authCramMD5(const QByteArray& challenge)
|
|||
|
||||
void QxtSmtpPrivate::authPlain()
|
||||
{
|
||||
if (state != AuthRequestSent)
|
||||
{
|
||||
if (state != AuthRequestSent) {
|
||||
socket->write("auth plain\r\n");
|
||||
authType = AuthPlain;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QByteArray auth;
|
||||
auth += '\0';
|
||||
auth += username;
|
||||
|
|
@ -428,60 +387,44 @@ void QxtSmtpPrivate::authPlain()
|
|||
|
||||
void QxtSmtpPrivate::authLogin()
|
||||
{
|
||||
if (state != AuthRequestSent && state != AuthUsernameSent)
|
||||
{
|
||||
if (state != AuthRequestSent && state != AuthUsernameSent) {
|
||||
socket->write("auth login\r\n");
|
||||
authType = AuthLogin;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else if (state == AuthRequestSent)
|
||||
{
|
||||
} else if (state == AuthRequestSent) {
|
||||
socket->write(username.toBase64() + "\r\n");
|
||||
state = AuthUsernameSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
socket->write(password.toBase64() + "\r\n");
|
||||
state = AuthSent;
|
||||
}
|
||||
}
|
||||
|
||||
static QByteArray qxt_extract_address(const QString& address)
|
||||
static QByteArray qxt_extract_address(const QString &address)
|
||||
{
|
||||
int parenDepth = 0;
|
||||
int addrStart = -1;
|
||||
bool inQuote = false;
|
||||
int ct = address.length();
|
||||
|
||||
for (int i = 0; i < ct; i++)
|
||||
{
|
||||
for (int i = 0; i < ct; i++) {
|
||||
QChar ch = address[i];
|
||||
if (inQuote)
|
||||
{
|
||||
if (inQuote) {
|
||||
if (ch == '"')
|
||||
inQuote = false;
|
||||
}
|
||||
else if (addrStart != -1)
|
||||
{
|
||||
} else if (addrStart != -1) {
|
||||
if (ch == '>')
|
||||
return address.mid(addrStart, (i - addrStart)).toLatin1();
|
||||
}
|
||||
else if (ch == '(')
|
||||
{
|
||||
} else if (ch == '(') {
|
||||
parenDepth++;
|
||||
}
|
||||
else if (ch == ')')
|
||||
{
|
||||
} else if (ch == ')') {
|
||||
parenDepth--;
|
||||
if (parenDepth < 0) parenDepth = 0;
|
||||
}
|
||||
else if (ch == '"')
|
||||
{
|
||||
if (parenDepth < 0)
|
||||
parenDepth = 0;
|
||||
} else if (ch == '"') {
|
||||
if (parenDepth == 0)
|
||||
inQuote = true;
|
||||
}
|
||||
else if (ch == '<')
|
||||
{
|
||||
} else if (ch == '<') {
|
||||
if (!inQuote && parenDepth == 0)
|
||||
addrStart = i + 1;
|
||||
}
|
||||
|
|
@ -491,35 +434,31 @@ static QByteArray qxt_extract_address(const QString& address)
|
|||
|
||||
void QxtSmtpPrivate::sendNext()
|
||||
{
|
||||
if (state == Disconnected)
|
||||
{
|
||||
if (state == Disconnected) {
|
||||
// leave the mail in the queue if not ready to send
|
||||
return;
|
||||
}
|
||||
|
||||
if (pending.isEmpty())
|
||||
{
|
||||
if (pending.isEmpty()) {
|
||||
// if there are no additional mails to send, finish up
|
||||
state = Waiting;
|
||||
emit qxt_p().finished();
|
||||
return;
|
||||
}
|
||||
|
||||
if(state != Waiting) {
|
||||
if (state != Waiting) {
|
||||
state = Resetting;
|
||||
socket->write("rset\r\n");
|
||||
return;
|
||||
}
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
rcptNumber = rcptAck = mailAck = 0;
|
||||
recipients = msg.recipients(QxtMailMessage::To) +
|
||||
msg.recipients(QxtMailMessage::Cc) +
|
||||
msg.recipients(QxtMailMessage::Bcc);
|
||||
if (recipients.count() == 0)
|
||||
{
|
||||
recipients =
|
||||
msg.recipients(QxtMailMessage::To) + msg.recipients(QxtMailMessage::Cc) + msg.recipients(QxtMailMessage::Bcc);
|
||||
if (recipients.count() == 0) {
|
||||
// can't send an e-mail with no recipients
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients );
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients, QByteArray( "e-mail has no recipients" ) );
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients);
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients, QByteArray("e-mail has no recipients"));
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
return;
|
||||
|
|
@ -528,87 +467,67 @@ void QxtSmtpPrivate::sendNext()
|
|||
// interprets any string starting with an uppercase R as a request
|
||||
// to renegotiate the SSL connection.
|
||||
socket->write("mail from:<" + qxt_extract_address(msg.sender()) + ">\r\n");
|
||||
if (extensions.contains("PIPELINING")) // almost all do nowadays
|
||||
if (extensions.contains("PIPELINING")) // almost all do nowadays
|
||||
{
|
||||
foreach(const QString& rcpt, recipients)
|
||||
{
|
||||
foreach (const QString &rcpt, recipients) {
|
||||
socket->write("rcpt to:<" + qxt_extract_address(rcpt) + ">\r\n");
|
||||
}
|
||||
state = RcptAckPending;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = MailToSent;
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::sendNextRcpt(const QByteArray& code, const QByteArray&line)
|
||||
void QxtSmtpPrivate::sendNextRcpt(const QByteArray &code, const QByteArray &line)
|
||||
{
|
||||
int messageID = pending.first().first;
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
|
||||
if (code[0] != '2')
|
||||
{
|
||||
if (code[0] != '2') {
|
||||
// on failure, emit a warning signal
|
||||
if (!mailAck)
|
||||
{
|
||||
if (!mailAck) {
|
||||
emit qxt_p().senderRejected(messageID, msg.sender());
|
||||
emit qxt_p().senderRejected(messageID, msg.sender(), line );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit qxt_p().senderRejected(messageID, msg.sender(), line);
|
||||
} else {
|
||||
emit qxt_p().recipientRejected(messageID, msg.sender());
|
||||
emit qxt_p().recipientRejected(messageID, msg.sender(), line);
|
||||
}
|
||||
}
|
||||
else if (!mailAck)
|
||||
{
|
||||
} else if (!mailAck) {
|
||||
mailAck = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rcptAck++;
|
||||
}
|
||||
|
||||
if (rcptNumber == recipients.count())
|
||||
{
|
||||
if (rcptNumber == recipients.count()) {
|
||||
// all recipients have been sent
|
||||
if (rcptAck == 0)
|
||||
{
|
||||
if (rcptAck == 0) {
|
||||
// no recipients were considered valid
|
||||
emit qxt_p().mailFailed(messageID, code.toInt() );
|
||||
emit qxt_p().mailFailed(messageID, code.toInt());
|
||||
emit qxt_p().mailFailed(messageID, code.toInt(), line);
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// at least one recipient was acknowledged, send mail body
|
||||
socket->write("data\r\n");
|
||||
state = SendingBody;
|
||||
}
|
||||
}
|
||||
else if (state != RcptAckPending)
|
||||
{
|
||||
} else if (state != RcptAckPending) {
|
||||
// send the next recipient unless we're only waiting on acks
|
||||
socket->write("rcpt to:<" + qxt_extract_address(recipients[rcptNumber]) + ">\r\n");
|
||||
rcptNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// If we're only waiting on acks, just count them
|
||||
rcptNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::sendBody(const QByteArray& code, const QByteArray & line)
|
||||
void QxtSmtpPrivate::sendBody(const QByteArray &code, const QByteArray &line)
|
||||
{
|
||||
int messageID = pending.first().first;
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
|
||||
if (code[0] != '3')
|
||||
{
|
||||
emit qxt_p().mailFailed(messageID, code.toInt() );
|
||||
if (code[0] != '3') {
|
||||
emit qxt_p().mailFailed(messageID, code.toInt());
|
||||
emit qxt_p().mailFailed(messageID, code.toInt(), line);
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue