Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f6b366e8 authored by Jonathan Marten's avatar Jonathan Marten

Settings for SMTP network proxy option

CCBUG: 379539

Differential Revision: https://phabricator.kde.org/D10940
parent e35b2c1b
......@@ -131,6 +131,11 @@ Session::~Session()
{
}
void Session::setUseNetworkProxy(bool useProxy)
{
d->m_thread->setUseNetworkProxy(useProxy);
}
void Session::setUiProxy(const SessionUiProxy::Ptr &uiProxy)
{
d->m_uiProxy = uiProxy;
......
......@@ -48,8 +48,9 @@ public:
Q_ENUM(State)
/**
Creates a new Smtp session to the specified host and port.
After creating the session, you should call either open() or openAndWait() to open the connection.
Creates a new SMTP session to the specified host and port.
After creating the session, call setUseProxy() if necessary
and then either open() or openAndWait() to open the connection.
@sa open(), openAndWait()
*/
explicit Session(const QString &hostName, quint16 port, QObject *parent = nullptr);
......@@ -58,6 +59,13 @@ public:
void setUiProxy(const SessionUiProxy::Ptr &uiProxy);
SessionUiProxy::Ptr uiProxy() const;
/**
Sets whether the SMTP network connection should use the system proxy settings
The default is to not use the proxy.
*/
void setUseNetworkProxy(bool useProxy);
/**
Returns the host name that has been provided in the Session's constructor
@sa port()
......@@ -124,7 +132,7 @@ public:
/**
Requests the server to quit the connection.
This sends "QUIT" command to the server and will not close the connection until
This sends a "QUIT" command to the server and will not close the connection until
it receives a response. That means you should not delete this object right after
calling close, instead wait for stateChanged() to change to Disconnected, or use
quitAndWait().
......
......@@ -27,6 +27,7 @@
#include <QUrl>
#include <QFile>
#include <QCoreApplication>
#include <QNetworkProxy>
using namespace KSmtp;
......@@ -36,7 +37,8 @@ SessionThread::SessionThread(const QString &hostName, quint16 port, Session *ses
m_logFile(nullptr),
m_parentSession(session),
m_hostName(hostName),
m_port(port)
m_port(port),
m_useProxy(false)
{
moveToThread(this);
......@@ -132,6 +134,16 @@ void SessionThread::reconnect()
if (m_socket->state() != KTcpSocket::ConnectedState &&
m_socket->state() != KTcpSocket::ConnectingState) {
if (!m_useProxy) {
qCDebug(KSMTP_LOG) << "using no proxy";
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::NoProxy);
m_socket->setProxy(proxy);
} else {
qCDebug(KSMTP_LOG) << "using default system proxy";
}
m_socket->connectToHost(hostName(), port());
}
}
......@@ -163,6 +175,13 @@ void SessionThread::run()
delete m_socket;
}
void SessionThread::setUseNetworkProxy(bool useProxy)
{
m_useProxy = useProxy;
}
ServerResponse SessionThread::parseResponse(const QByteArray &resp)
{
QByteArray response(resp);
......
......@@ -44,6 +44,8 @@ public:
QString hostName() const;
quint16 port() const;
void setUseNetworkProxy(bool useProxy);
void handleSslErrorResponse(bool ignoreError);
public Q_SLOTS:
......@@ -78,6 +80,7 @@ private:
Session *m_parentSession = nullptr;
QString m_hostName;
quint16 m_port;
bool m_useProxy;
};
}
......
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