File indexing completed on 2024-05-19 05:17:44

0001 /*
0002     Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
0003     Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
0004 
0005     This library is free software; you can redistribute it and/or modify it
0006     under the terms of the GNU Library General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or (at your
0008     option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful, but WITHOUT
0011     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0012     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0013     License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to the
0017     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018     02110-1301, USA.
0019 */
0020 
0021 #ifndef KIMAP2_SESSION_H
0022 #define KIMAP2_SESSION_H
0023 
0024 #include "kimap2_export.h"
0025 
0026 #include <QtCore/QObject>
0027 #include <QtNetwork/QSsl>
0028 #include <QtNetwork/QSslSocket>
0029 
0030 namespace KIMAP2
0031 {
0032 
0033 class SessionPrivate;
0034 class JobPrivate;
0035 struct Message;
0036 
0037 class KIMAP2_EXPORT Session : public QObject
0038 {
0039     Q_OBJECT
0040     Q_ENUMS(State)
0041 
0042     friend class JobPrivate;
0043 
0044 public:
0045     enum State { Disconnected = 0, NotAuthenticated, Authenticated, Selected };
0046 
0047     Session(const QString &hostName, quint16 port, QObject *parent = Q_NULLPTR);
0048     ~Session();
0049 
0050     QString hostName() const;
0051     quint16 port() const;
0052     State state() const;
0053     /**
0054      * Returns true if the session is in either Authenticated or Selected state
0055      */
0056     bool isConnected() const;
0057 
0058     /**
0059      * Returns the name that has been set with LoginJob::setUserName()
0060      * The user name is useful to uniquely identify an IMAP resource, in combination with the host name
0061      * @note If the Session was pre-authenticated, userName() will return an empty string
0062      */
0063     QString userName() const;
0064 
0065     QByteArray serverGreeting() const;
0066 
0067     void setErrorHandler();
0068 
0069     /**
0070      * Set the session timeout. The default is 30 seconds.
0071      * @param timeout The socket timeout in seconds, negative values disable the timeout.
0072      */
0073     void setTimeout(int timeout);
0074 
0075     /**
0076      * Returns the session timeout.
0077      */
0078     int timeout() const;
0079 
0080     /**
0081      * Returns the currently selected mailbox.
0082      */
0083     QString selectedMailBox() const;
0084 
0085     int jobQueueSize() const;
0086 
0087     void close();
0088 
0089     /**
0090      * Use to ignore specific ssl errrs.
0091      *
0092      * Use in conjunction with @see sslErrors
0093      */
0094     void ignoreErrors(const QList<QSslError> &errors);
0095 
0096 Q_SIGNALS:
0097     void jobQueueSizeChanged(int queueSize);
0098 
0099     /**
0100      * Emitted when ssl errors occur.
0101      *
0102      * Use in conjunction with  @see ignoreErrors to ignore an error as it appears.
0103      * Note that ignore errors must be called synchronously directly in the callback.
0104      */
0105     void sslErrors(const QList<QSslError> &errors);
0106 
0107     /**
0108       Emitted when the Session couldn't connect to the host.
0109 
0110       Likely reasons: invalid host address, no internet connectivity, firewall blocking rules,
0111       etc...
0112 
0113       Pending jobs in the queue will be deleted, and the first job in the queue will be failed. (ie:
0114       it will have its result signal emitted with a non-zero error code.)
0115     */
0116     void connectionFailed();
0117 
0118     /**
0119       Emitted when the session's state changes.
0120 
0121       You can use this signal to detect a connection loss (ie: stateChanged is emitted with newState
0122       == KIMAP2::Session::Disconnected)
0123 
0124       If you want to receive the stateChanged arguments in your slot, you must register the State
0125       enum with @c Q_DECLARE_METATYPE(KIMAP2::Session::State) and @c qRegisterMetaType<KIMAP2::Session::State>();
0126     */
0127     void stateChanged(KIMAP2::Session::State newState, KIMAP2::Session::State oldState);
0128 
0129 private:
0130     friend class SessionPrivate;
0131     SessionPrivate *const d;
0132 };
0133 
0134 }
0135 
0136 #endif