MailTransport

servertest.h
1/*
2 SPDX-FileCopyrightText: 2007 KovoKs <info@kovoks.nl>
3 SPDX-FileCopyrightText: 2008 Thomas McGuire <thomas.mcguire@gmx.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "mailtransport_export.h"
11#include "transport.h"
12
13#include <QList>
14#include <QObject>
15
16#include <memory>
17
18class QProgressBar;
19
20namespace MailTransport
21{
22class ServerTestPrivate;
23
24/**
25 * @class ServerTest
26 * This class can be used to test certain server to see if they support stuff.
27 * @author Tom Albers <tomalbers@kde.nl>
28 */
29class MAILTRANSPORT_EXPORT ServerTest : public QObject
30{
31 Q_OBJECT
32 Q_PROPERTY(QString server READ server WRITE setServer)
33 Q_PROPERTY(QString protocol READ protocol WRITE setProtocol)
34 Q_PROPERTY(QProgressBar *progressBar READ progressBar WRITE setProgressBar)
35
36public:
37 /**
38 * This enumeration has the special capabilities a server might
39 * support. This covers only capabilities not related to authentication.
40 * @since 4.1
41 */
43 Pipelining, ///< POP3 only. The server supports pipeplining of commands
44 Top, ///< POP3 only. The server supports fetching only the headers
45 UIDL ///< POP3 only. The server has support for unique identifiers
46 };
47
48 /**
49 * Creates a new server test.
50 *
51 * @param parent The parent widget.
52 */
53 explicit ServerTest(QObject *parent = nullptr);
54
55 /**
56 * Destroys the server test.
57 */
58 ~ServerTest() override;
59
60 /**
61 * Sets the server to test.
62 */
63 void setServer(const QString &server);
64
65 /**
66 * Returns the server to test.
67 */
68 [[nodiscard]] QString server() const;
69
70 /**
71 * Set a custom port to use.
72 *
73 * Each encryption mode (no encryption or SSL) has a different port.
74 * TLS uses the same port as no encryption, because TLS is invoked during
75 * a normal session.
76 *
77 * If this function is never called, the default port is used, which is:
78 * (normal first, then SSL)
79 * SMTP: 587 (falls back to 25), 465
80 * POP: 110, 995
81 * IMAP: 143, 993
82 * NNTP: 119, 563
83 *
84 * @param encryptionMode the port will only be used in this encryption mode.
85 * Valid values for this are only 'None' and 'SSL'.
86 * @param port the port to use
87 *
88 * @since 4.1
89 */
90 void setPort(Transport::EnumEncryption encryptionMode, uint port);
91
92 /**
93 * @param encryptionMode the port of this encryption mode is returned.
94 * Can only be 'None' and 'SSL'
95 *
96 * @return the port set by @ref setPort or -1 if @ref setPort() was never
97 * called for this encryption mode.
98 *
99 * @since 4.1
100 */
101 [[nodiscard]] int port(Transport::EnumEncryption encryptionMode) const;
102
103 /**
104 * Sets a fake hostname for the test. This is currently only used when
105 * testing a SMTP server; there, the command for testing the capabilities
106 * (called EHLO) needs to have the hostname of the client included.
107 * The user can however choose to send a fake hostname instead of the
108 * local hostname to work around various problems. This fake hostname needs
109 * to be set here.
110 *
111 * @param fakeHostname the fake hostname to send
112 */
113 void setFakeHostname(const QString &fakeHostname);
114
115 /**
116 * @return the fake hostname, as set before with @ref setFakeHostname
117 */
118 [[nodiscard]] QString fakeHostname() const;
119
120 /**
121 * Makes @p pb the progressbar to use. This class will call show()
122 * and hide() and will count down. It does not take ownership of
123 * the progressbar.
124 */
125 void setProgressBar(QProgressBar *pb);
126
127 /**
128 * Returns the used progress bar.
129 */
130 QProgressBar *progressBar() const;
131
132 /**
133 * Sets @p protocol the protocol to test, currently supported are
134 * "smtp", "pop", "imap", and "nntp".
135 */
136 void setProtocol(const QString &protocol);
137
138 /**
139 * Returns the protocol.
140 */
141 [[nodiscard]] QString protocol() const;
142
143 /**
144 * Starts the test. Will emit finished() when done.
145 */
146 void start();
147
148 /**
149 * Get the protocols for the normal connections.. Call this only
150 * after the finished() signals has been sent.
151 * @return an enum of the type Transport::EnumAuthenticationType
152 */
153 [[nodiscard]] QList<int> normalProtocols() const;
154
155 /**
156 * tells you if the normal server is available
157 * @since 4.5
158 */
159 [[nodiscard]] bool isNormalPossible() const;
160
161 /**
162 * Get the protocols for the TLS connections. Call this only
163 * after the finished() signals has been sent.
164 * @return an enum of the type Transport::EnumAuthenticationType
165 * @since 4.1
166 */
167 [[nodiscard]] QList<int> tlsProtocols() const;
168
169 /**
170 * Get the protocols for the SSL connections. Call this only
171 * after the finished() signals has been sent.
172 * @return an enum of the type Transport::EnumAuthenticationType
173 */
174 [[nodiscard]] QList<int> secureProtocols() const;
175
176 /**
177 * tells you if the ssl server is available
178 * @since 4.5
179 */
180 [[nodiscard]] bool isSecurePossible() const;
181
182 /**
183 * Get the special capabilities of the server.
184 * Call this only after the finished() signals has been sent.
185 *
186 * @return the list of special capabilities of the server.
187 * @since 4.1
188 */
189 [[nodiscard]] QList<Capability> capabilities() const;
190
191Q_SIGNALS:
192 /**
193 * This will be emitted when the test is done. It will contain
194 * the values from the enum EnumEncryption which are possible.
195 */
196 void finished(const QList<int> &);
197
198private:
199 Q_DECLARE_PRIVATE(ServerTest)
200 std::unique_ptr<ServerTestPrivate> const d;
201
202 Q_PRIVATE_SLOT(d, void slotNormalPossible())
203 Q_PRIVATE_SLOT(d, void slotTlsDone())
204 Q_PRIVATE_SLOT(d, void slotSslPossible())
205 Q_PRIVATE_SLOT(d, void slotReadNormal(const QString &text))
206 Q_PRIVATE_SLOT(d, void slotReadSecure(const QString &text))
207 Q_PRIVATE_SLOT(d, void slotNormalNotPossible())
208 Q_PRIVATE_SLOT(d, void slotSslNotPossible())
209 Q_PRIVATE_SLOT(d, void slotUpdateProgress())
210};
211} // namespace MailTransport
This class can be used to test certain server to see if they support stuff.
Definition servertest.h:30
void finished(const QList< int > &)
This will be emitted when the test is done.
~ServerTest() override
Destroys the server test.
Capability
This enumeration has the special capabilities a server might support.
Definition servertest.h:42
@ Pipelining
POP3 only. The server supports pipeplining of commands.
Definition servertest.h:43
@ Top
POP3 only. The server supports fetching only the headers.
Definition servertest.h:44
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.