Commit 38a4c094 authored by Volker Krause's avatar Volker Krause
Browse files

Move establishing the TLS connection to Session

This means we now also enable TLS when not having a LoginJob, ie. on
servers not requiring authentication.

Doing the same for STARTTLS is the next step then.

CCBUG: 423423
parent c0771e38
Pipeline #81976 passed with stage
in 3 minutes and 28 seconds
......@@ -122,8 +122,6 @@ void LoginJob::doStart()
if (!d->authenticate()) {
emitResult();
}
} else if (d->m_session->encryptionMode() == Session::TLS) {
d->sessionInternal()->startSsl();
} else if (d->m_session->encryptionMode() == Session::STARTTLS) {
if (session()->allowsTls()) {
sendCommand(QByteArrayLiteral("STARTTLS"));
......
......@@ -193,6 +193,7 @@ QString Session::customHostname() const
void Session::open()
{
d->m_thread->setConnectWithTls(d->m_encryptionMode == Session::TLS);
QTimer::singleShot(0, d->m_thread, &SessionThread::reconnect);
d->startSocketTimer();
}
......@@ -278,17 +279,6 @@ void SessionPrivate::socketConnected()
{
stopSocketTimer();
setState(Session::Ready);
bool useSsl = false;
if (!m_queue.isEmpty()) {
if (qobject_cast<LoginJob *>(m_queue.first())) {
useSsl = m_encryptionMode == Session::TLS;
}
}
if (q->state() == Session::Ready && useSsl) {
startNext();
}
}
void SessionPrivate::socketDisconnected()
......
......@@ -27,7 +27,6 @@ SessionThread::SessionThread(const QString &hostName, quint16 port, Session *ses
, m_parentSession(session)
, m_hostName(hostName)
, m_port(port)
, m_useProxy(false)
{
moveToThread(this);
......@@ -125,7 +124,11 @@ void SessionThread::reconnect()
qCDebug(KSMTP_LOG) << "Using the default system proxy to connect to the SMTP server.";
}
m_socket->connectToHost(hostName(), port());
if (m_useTls) {
m_socket->connectToHostEncrypted(hostName(), port());
} else {
m_socket->connectToHost(hostName(), port());
}
}
}
......@@ -156,6 +159,12 @@ void SessionThread::setUseNetworkProxy(bool useProxy)
m_useProxy = useProxy;
}
void SessionThread::setConnectWithTls(bool useTls)
{
QMutexLocker locker(&m_mutex);
m_useTls = useTls;
}
ServerResponse SessionThread::parseResponse(const QByteArray &resp)
{
QByteArray response(resp);
......
......@@ -33,6 +33,7 @@ public:
Q_REQUIRED_RESULT quint16 port() const;
void setUseNetworkProxy(bool useProxy);
void setConnectWithTls(bool useTls);
void handleSslErrorResponse(bool ignoreError);
......@@ -69,6 +70,7 @@ private:
QString m_hostName;
quint16 m_port;
bool m_useProxy = false;
bool m_useTls = false;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment