File indexing completed on 2024-05-19 05:21:50
0001 /* 0002 SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com> 0003 SPDX-FileContributor: Christophe Laveault <christophe@betterinbox.com> 0004 SPDX-FileContributor: Gregory Schlomoff <gregory.schlomoff@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QMutex> 0012 #include <QQueue> 0013 #include <QSslSocket> 0014 #include <QThread> 0015 0016 #include <ksslerroruidata.h> 0017 0018 class QFile; 0019 namespace KSmtp 0020 { 0021 class ServerResponse; 0022 class Session; 0023 0024 class SessionThread : public QThread 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit SessionThread(const QString &hostName, quint16 port, Session *session); 0030 ~SessionThread() override; 0031 0032 [[nodiscard]] QString hostName() const; 0033 [[nodiscard]] quint16 port() const; 0034 0035 void setUseNetworkProxy(bool useProxy); 0036 void setConnectWithTls(bool useTls); 0037 0038 void handleSslErrorResponse(bool ignoreError); 0039 0040 public Q_SLOTS: 0041 void reconnect(); 0042 void closeSocket(); 0043 void startSsl(); 0044 void sendData(const QByteArray &payload); 0045 0046 Q_SIGNALS: 0047 void encryptionNegotiationResult(bool encrypted, QSsl::SslProtocol protocol); 0048 void responseReceived(const KSmtp::ServerResponse &response); 0049 void sslError(const KSslErrorUiData &); 0050 0051 protected: 0052 void run() override; 0053 0054 private Q_SLOTS: 0055 void sslConnected(); 0056 void writeDataQueue(); 0057 void readResponse(); 0058 void doCloseSocket(); 0059 void doHandleSslErrorResponse(bool ignoreError); 0060 0061 private: 0062 ServerResponse parseResponse(const QByteArray &response); 0063 0064 std::unique_ptr<QSslSocket> m_socket; 0065 QMutex m_mutex; 0066 QQueue<QByteArray> m_dataQueue; 0067 std::unique_ptr<QFile> m_logFile; 0068 0069 Session *m_parentSession = nullptr; 0070 QString m_hostName; 0071 quint16 m_port; 0072 bool m_useProxy = false; 0073 bool m_useTls = false; 0074 }; 0075 }