File indexing completed on 2024-06-23 05:15:11
0001 /* 0002 SPDX-FileCopyrightText: 2007 KovoKs <info@kovoks.nl> 0003 SPDX-FileCopyrightText: 2008 Thomas McGuire <thomas.mcguire@gmx.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "mailtransport_export.h" 0011 #include "transport.h" 0012 0013 #include <QList> 0014 #include <QObject> 0015 0016 #include <memory> 0017 0018 class QProgressBar; 0019 0020 namespace MailTransport 0021 { 0022 class ServerTestPrivate; 0023 0024 /** 0025 * @class ServerTest 0026 * This class can be used to test certain server to see if they support stuff. 0027 * @author Tom Albers <tomalbers@kde.nl> 0028 */ 0029 class MAILTRANSPORT_EXPORT ServerTest : public QObject 0030 { 0031 Q_OBJECT 0032 Q_PROPERTY(QString server READ server WRITE setServer) 0033 Q_PROPERTY(QString protocol READ protocol WRITE setProtocol) 0034 Q_PROPERTY(QProgressBar *progressBar READ progressBar WRITE setProgressBar) 0035 0036 public: 0037 /** 0038 * This enumeration has the special capabilities a server might 0039 * support. This covers only capabilities not related to authentication. 0040 * @since 4.1 0041 */ 0042 enum Capability { 0043 Pipelining, ///< POP3 only. The server supports pipeplining of commands 0044 Top, ///< POP3 only. The server supports fetching only the headers 0045 UIDL ///< POP3 only. The server has support for unique identifiers 0046 }; 0047 0048 /** 0049 * Creates a new server test. 0050 * 0051 * @param parent The parent widget. 0052 */ 0053 explicit ServerTest(QObject *parent = nullptr); 0054 0055 /** 0056 * Destroys the server test. 0057 */ 0058 ~ServerTest() override; 0059 0060 /** 0061 * Sets the server to test. 0062 */ 0063 void setServer(const QString &server); 0064 0065 /** 0066 * Returns the server to test. 0067 */ 0068 [[nodiscard]] QString server() const; 0069 0070 /** 0071 * Set a custom port to use. 0072 * 0073 * Each encryption mode (no encryption or SSL) has a different port. 0074 * TLS uses the same port as no encryption, because TLS is invoked during 0075 * a normal session. 0076 * 0077 * If this function is never called, the default port is used, which is: 0078 * (normal first, then SSL) 0079 * SMTP: 587 (falls back to 25), 465 0080 * POP: 110, 995 0081 * IMAP: 143, 993 0082 * NNTP: 119, 563 0083 * 0084 * @param encryptionMode the port will only be used in this encryption mode. 0085 * Valid values for this are only 'None' and 'SSL'. 0086 * @param port the port to use 0087 * 0088 * @since 4.1 0089 */ 0090 void setPort(Transport::EnumEncryption encryptionMode, uint port); 0091 0092 /** 0093 * @param encryptionMode the port of this encryption mode is returned. 0094 * Can only be 'None' and 'SSL' 0095 * 0096 * @return the port set by @ref setPort or -1 if @ref setPort() was never 0097 * called for this encryption mode. 0098 * 0099 * @since 4.1 0100 */ 0101 [[nodiscard]] int port(Transport::EnumEncryption encryptionMode) const; 0102 0103 /** 0104 * Sets a fake hostname for the test. This is currently only used when 0105 * testing a SMTP server; there, the command for testing the capabilities 0106 * (called EHLO) needs to have the hostname of the client included. 0107 * The user can however choose to send a fake hostname instead of the 0108 * local hostname to work around various problems. This fake hostname needs 0109 * to be set here. 0110 * 0111 * @param fakeHostname the fake hostname to send 0112 */ 0113 void setFakeHostname(const QString &fakeHostname); 0114 0115 /** 0116 * @return the fake hostname, as set before with @ref setFakeHostname 0117 */ 0118 [[nodiscard]] QString fakeHostname() const; 0119 0120 /** 0121 * Makes @p pb the progressbar to use. This class will call show() 0122 * and hide() and will count down. It does not take ownership of 0123 * the progressbar. 0124 */ 0125 void setProgressBar(QProgressBar *pb); 0126 0127 /** 0128 * Returns the used progress bar. 0129 */ 0130 QProgressBar *progressBar() const; 0131 0132 /** 0133 * Sets @p protocol the protocol to test, currently supported are 0134 * "smtp", "pop", "imap", and "nntp". 0135 */ 0136 void setProtocol(const QString &protocol); 0137 0138 /** 0139 * Returns the protocol. 0140 */ 0141 [[nodiscard]] QString protocol() const; 0142 0143 /** 0144 * Starts the test. Will emit finished() when done. 0145 */ 0146 void start(); 0147 0148 /** 0149 * Get the protocols for the normal connections.. Call this only 0150 * after the finished() signals has been sent. 0151 * @return an enum of the type Transport::EnumAuthenticationType 0152 */ 0153 [[nodiscard]] QList<int> normalProtocols() const; 0154 0155 /** 0156 * tells you if the normal server is available 0157 * @since 4.5 0158 */ 0159 [[nodiscard]] bool isNormalPossible() const; 0160 0161 /** 0162 * Get the protocols for the TLS connections. Call this only 0163 * after the finished() signals has been sent. 0164 * @return an enum of the type Transport::EnumAuthenticationType 0165 * @since 4.1 0166 */ 0167 [[nodiscard]] QList<int> tlsProtocols() const; 0168 0169 /** 0170 * Get the protocols for the SSL connections. Call this only 0171 * after the finished() signals has been sent. 0172 * @return an enum of the type Transport::EnumAuthenticationType 0173 */ 0174 [[nodiscard]] QList<int> secureProtocols() const; 0175 0176 /** 0177 * tells you if the ssl server is available 0178 * @since 4.5 0179 */ 0180 [[nodiscard]] bool isSecurePossible() const; 0181 0182 /** 0183 * Get the special capabilities of the server. 0184 * Call this only after the finished() signals has been sent. 0185 * 0186 * @return the list of special capabilities of the server. 0187 * @since 4.1 0188 */ 0189 [[nodiscard]] QList<Capability> capabilities() const; 0190 0191 Q_SIGNALS: 0192 /** 0193 * This will be emitted when the test is done. It will contain 0194 * the values from the enum EnumEncryption which are possible. 0195 */ 0196 void finished(const QList<int> &); 0197 0198 private: 0199 Q_DECLARE_PRIVATE(ServerTest) 0200 std::unique_ptr<ServerTestPrivate> const d; 0201 0202 Q_PRIVATE_SLOT(d, void slotNormalPossible()) 0203 Q_PRIVATE_SLOT(d, void slotTlsDone()) 0204 Q_PRIVATE_SLOT(d, void slotSslPossible()) 0205 Q_PRIVATE_SLOT(d, void slotReadNormal(const QString &text)) 0206 Q_PRIVATE_SLOT(d, void slotReadSecure(const QString &text)) 0207 Q_PRIVATE_SLOT(d, void slotNormalNotPossible()) 0208 Q_PRIVATE_SLOT(d, void slotSslNotPossible()) 0209 Q_PRIVATE_SLOT(d, void slotUpdateProgress()) 0210 }; 0211 } // namespace MailTransport