diff --git a/src/session.h b/src/session.h --- a/src/session.h +++ b/src/session.h @@ -48,16 +48,24 @@ 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); ~Session() override; 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 @@ /** 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(). diff --git a/src/session.cpp b/src/session.cpp --- a/src/session.cpp +++ b/src/session.cpp @@ -131,6 +131,11 @@ { } +void Session::setUseNetworkProxy(bool useProxy) +{ + d->m_thread->setUseNetworkProxy(useProxy); +} + void Session::setUiProxy(const SessionUiProxy::Ptr &uiProxy) { d->m_uiProxy = uiProxy; diff --git a/src/sessionthread.cpp b/src/sessionthread.cpp --- a/src/sessionthread.cpp +++ b/src/sessionthread.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using namespace KSmtp; @@ -36,7 +37,8 @@ m_logFile(nullptr), m_parentSession(session), m_hostName(hostName), - m_port(port) + m_port(port), + m_useProxy(false) { moveToThread(this); @@ -132,6 +134,16 @@ 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 @@ delete m_socket; } + +void SessionThread::setUseNetworkProxy(bool useProxy) +{ + m_useProxy = useProxy; +} + + ServerResponse SessionThread::parseResponse(const QByteArray &resp) { QByteArray response(resp); diff --git a/src/sessionthread_p.h b/src/sessionthread_p.h --- a/src/sessionthread_p.h +++ b/src/sessionthread_p.h @@ -44,6 +44,8 @@ QString hostName() const; quint16 port() const; + void setUseNetworkProxy(bool useProxy); + void handleSslErrorResponse(bool ignoreError); public Q_SLOTS: @@ -78,6 +80,7 @@ Session *m_parentSession = nullptr; QString m_hostName; quint16 m_port; + bool m_useProxy; }; }