Changeset View
Changeset View
Standalone View
Standalone View
src/sessionthread.cpp
Show All 21 Lines | |||||
22 | #include "session.h" | 22 | #include "session.h" | ||
23 | #include "session_p.h" | 23 | #include "session_p.h" | ||
24 | #include "ksmtp_debug.h" | 24 | #include "ksmtp_debug.h" | ||
25 | 25 | | |||
26 | #include <QTimer> | 26 | #include <QTimer> | ||
27 | #include <QUrl> | 27 | #include <QUrl> | ||
28 | #include <QFile> | 28 | #include <QFile> | ||
29 | #include <QCoreApplication> | 29 | #include <QCoreApplication> | ||
30 | #include <QNetworkProxy> | ||||
30 | 31 | | |||
31 | using namespace KSmtp; | 32 | using namespace KSmtp; | ||
32 | 33 | | |||
33 | SessionThread::SessionThread(const QString &hostName, quint16 port, Session *session) | 34 | SessionThread::SessionThread(const QString &hostName, quint16 port, Session *session) | ||
34 | : QThread(), | 35 | : QThread(), | ||
35 | m_socket(nullptr), | 36 | m_socket(nullptr), | ||
36 | m_logFile(nullptr), | 37 | m_logFile(nullptr), | ||
37 | m_parentSession(session), | 38 | m_parentSession(session), | ||
38 | m_hostName(hostName), | 39 | m_hostName(hostName), | ||
39 | m_port(port) | 40 | m_port(port), | ||
41 | m_useProxy(false) | ||||
40 | { | 42 | { | ||
41 | moveToThread(this); | 43 | moveToThread(this); | ||
42 | 44 | | |||
43 | const auto logfile = qgetenv("KSMTP_SESSION_LOG"); | 45 | const auto logfile = qgetenv("KSMTP_SESSION_LOG"); | ||
44 | if (!logfile.isEmpty()) { | 46 | if (!logfile.isEmpty()) { | ||
45 | static uint sSessionCount = 0; | 47 | static uint sSessionCount = 0; | ||
46 | const QString filename = QStringLiteral("%1.%2.%3").arg(QString::fromUtf8(logfile)) | 48 | const QString filename = QStringLiteral("%1.%2.%3").arg(QString::fromUtf8(logfile)) | ||
47 | .arg(qApp->applicationPid()) | 49 | .arg(qApp->applicationPid()) | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | |||||
127 | 129 | | |||
128 | void SessionThread::reconnect() | 130 | void SessionThread::reconnect() | ||
129 | { | 131 | { | ||
130 | QMutexLocker locker(&m_mutex); | 132 | QMutexLocker locker(&m_mutex); | ||
131 | 133 | | |||
132 | if (m_socket->state() != KTcpSocket::ConnectedState && | 134 | if (m_socket->state() != KTcpSocket::ConnectedState && | ||
133 | m_socket->state() != KTcpSocket::ConnectingState) { | 135 | m_socket->state() != KTcpSocket::ConnectingState) { | ||
134 | 136 | | |||
137 | if (!m_useProxy) { | ||||
138 | qCDebug(KSMTP_LOG) << "using no proxy"; | ||||
139 | | ||||
140 | QNetworkProxy proxy; | ||||
141 | proxy.setType(QNetworkProxy::NoProxy); | ||||
142 | m_socket->setProxy(proxy); | ||||
143 | } else { | ||||
144 | qCDebug(KSMTP_LOG) << "using default system proxy"; | ||||
145 | } | ||||
146 | | ||||
135 | m_socket->connectToHost(hostName(), port()); | 147 | m_socket->connectToHost(hostName(), port()); | ||
136 | } | 148 | } | ||
137 | } | 149 | } | ||
138 | 150 | | |||
139 | void SessionThread::run() | 151 | void SessionThread::run() | ||
140 | { | 152 | { | ||
141 | m_socket = new KTcpSocket; | 153 | m_socket = new KTcpSocket; | ||
142 | 154 | | |||
Show All 15 Lines | |||||
158 | connect(this, &SessionThread::responseReceived, | 170 | connect(this, &SessionThread::responseReceived, | ||
159 | m_parentSession->d, &SessionPrivate::responseReceived); | 171 | m_parentSession->d, &SessionPrivate::responseReceived); | ||
160 | 172 | | |||
161 | exec(); | 173 | exec(); | ||
162 | 174 | | |||
163 | delete m_socket; | 175 | delete m_socket; | ||
164 | } | 176 | } | ||
165 | 177 | | |||
178 | | ||||
179 | void SessionThread::setUseNetworkProxy(bool useProxy) | ||||
180 | { | ||||
181 | m_useProxy = useProxy; | ||||
182 | } | ||||
183 | | ||||
184 | | ||||
166 | ServerResponse SessionThread::parseResponse(const QByteArray &resp) | 185 | ServerResponse SessionThread::parseResponse(const QByteArray &resp) | ||
167 | { | 186 | { | ||
168 | QByteArray response(resp); | 187 | QByteArray response(resp); | ||
169 | 188 | | |||
170 | // Remove useless CRLF | 189 | // Remove useless CRLF | ||
171 | int indexOfCR = response.indexOf("\r"); | 190 | int indexOfCR = response.indexOf("\r"); | ||
172 | int indexOfLF = response.indexOf("\n"); | 191 | int indexOfLF = response.indexOf("\n"); | ||
173 | 192 | | |||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |