1/*
2 Copyright (C) 2007 KovoKs <info@kovoks.nl>
3 Copyright (c) 2008 Thomas McGuire <thomas.mcguire@gmx.net>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#ifndef MAILTRANSPORT_SERVERTEST_H
22#define MAILTRANSPORT_SERVERTEST_H
23
24#include <mailtransport/mailtransport_export.h>
25#include <mailtransport/transport.h>
26
27#include <QWidget>
28#include <QtCore/QHash>
29
30class QProgressBar;
31
32namespace MailTransport {
33
34class ServerTestPrivate;
35
36/**
37 * @class ServerTest
38 * This class can be used to test certain server to see if they support stuff.
39 * @author Tom Albers <tomalbers@kde.nl>
40 */
41class MAILTRANSPORT_EXPORT ServerTest : public QWidget
42{
43 Q_OBJECT
44 Q_PROPERTY( QString server READ server WRITE setServer )
45 Q_PROPERTY( QString protocol READ protocol WRITE setProtocol )
46 Q_PROPERTY( QProgressBar *progressBar READ progressBar WRITE setProgressBar )
47
48 public:
49
50 /**
51 * This enumeration has the special capabilities a server might
52 * support. This covers only capabilities not related to authentication.
53 * @since 4.1
54 */
55 enum Capability {
56 Pipelining, ///< POP3 only. The server supports pipeplining of commands
57 Top, ///< POP3 only. The server supports fetching only the headers
58 UIDL ///< POP3 only. The server has support for unique identifiers
59 };
60
61 /**
62 * Creates a new server test.
63 *
64 * @param parent The parent widget.
65 */
66 ServerTest( QWidget *parent = 0 );
67
68 /**
69 * Destroys the server test.
70 */
71 ~ServerTest();
72
73 /**
74 * Sets the server to test.
75 */
76 void setServer( const QString &server );
77
78 /**
79 * Returns the server to test.
80 */
81 QString server();
82
83 /**
84 * Set a custom port to use.
85 *
86 * Each encryption mode (no encryption or SSL) has a different port.
87 * TLS uses the same port as no encryption, because TLS is invoked during
88 * a normal session.
89 *
90 * If this function is never called, the default port is used, which is:
91 * (normal first, then SSL)
92 * SMTP: 25, 465
93 * POP: 110, 995
94 * IMAP: 143, 993
95 *
96 * @param encryptionMode the port will only be used in this encryption mode.
97 * Valid values for this are only 'None' and 'SSL'.
98 * @param port the port to use
99 *
100 * @since 4.1
101 */
102 void setPort( Transport::EnumEncryption::type encryptionMode, uint port );
103
104 /**
105 * @param encryptionMode the port of this encryption mode is returned.
106 * Can only be 'None' and 'SSL'
107 *
108 * @return the port set by @ref setPort or -1 if @ref setPort() was never
109 * called for this encryption mode.
110 *
111 * @since 4.1
112 */
113 int port( Transport::EnumEncryption::type encryptionMode );
114
115 /**
116 * Sets a fake hostname for the test. This is currently only used when
117 * testing a SMTP server; there, the command for testing the capabilities
118 * (called EHLO) needs to have the hostname of the client included.
119 * The user can however choose to send a fake hostname instead of the
120 * local hostname to work around various problems. This fake hostname needs
121 * to be set here.
122 *
123 * @param fakeHostname the fake hostname to send
124 */
125 void setFakeHostname( const QString &fakeHostname );
126
127 /**
128 * @return the fake hostname, as set before with @ref setFakeHostname
129 */
130 QString fakeHostname();
131
132 /**
133 * Makes @p pb the progressbar to use. This class will call show()
134 * and hide() and will count down. It does not take ownership of
135 * the progressbar.
136 */
137 void setProgressBar( QProgressBar *pb );
138
139 /**
140 * Returns the used progress bar.
141 */
142 QProgressBar *progressBar();
143
144 /**
145 * Sets @p protocol the protocol to test, currently supported are
146 * "smtp", "pop" and "imap".
147 */
148 void setProtocol( const QString &protocol );
149
150 /**
151 * Returns the protocol.
152 */
153 QString protocol();
154
155 /**
156 * Starts the test. Will emit finished() when done.
157 */
158 void start();
159
160 /**
161 * Get the protocols for the normal connections.. Call this only
162 * after the finished() signals has been sent.
163 * @return an enum of the type Transport::EnumAuthenticationType
164 */
165 QList<int> normalProtocols();
166
167 /**
168 * tells you if the normal server is available
169 * @since 4.5
170 */
171 bool isNormalPossible();
172
173 /**
174 * Get the protocols for the TLS connections. Call this only
175 * after the finished() signals has been sent.
176 * @return an enum of the type Transport::EnumAuthenticationType
177 * @since 4.1
178 */
179 QList<int> tlsProtocols();
180
181 /**
182 * Get the protocols for the SSL connections. Call this only
183 * after the finished() signals has been sent.
184 * @return an enum of the type Transport::EnumAuthenticationType
185 */
186 QList<int> secureProtocols();
187
188 /**
189 * tells you if the ssl server is available
190 * @since 4.5
191 */
192 bool isSecurePossible();
193
194 /**
195 * Get the special capabilities of the server.
196 * Call this only after the finished() signals has been sent.
197 *
198 * @return the list of special capabilities of the server.
199 * @since 4.1
200 */
201 QList<Capability> capabilities() const;
202
203 Q_SIGNALS:
204 /**
205 * This will be emitted when the test is done. It will contain
206 * the values from the enum EnumEncryption which are possible.
207 */
208 void finished( QList<int> );
209
210 private:
211 Q_DECLARE_PRIVATE( ServerTest )
212 ServerTestPrivate *const d;
213
214 Q_PRIVATE_SLOT( d, void slotNormalPossible() )
215 Q_PRIVATE_SLOT( d, void slotTlsDone() )
216 Q_PRIVATE_SLOT( d, void slotSslPossible() )
217 Q_PRIVATE_SLOT( d, void slotReadNormal( const QString &text ) )
218 Q_PRIVATE_SLOT( d, void slotReadSecure( const QString &text ) )
219 Q_PRIVATE_SLOT( d, void slotNormalNotPossible() )
220 Q_PRIVATE_SLOT( d, void slotSslNotPossible() )
221 Q_PRIVATE_SLOT( d, void slotUpdateProgress() )
222};
223
224} // namespace MailTransport
225
226#endif // MAILTRANSPORT_SERVERTEST_H
227