File indexing completed on 2024-05-12 05:17:25

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_P_H
0022 #define KIMAP2_SESSION_P_H
0023 
0024 #include "session.h"
0025 
0026 #include <QtNetwork/QSslSocket>
0027 
0028 #include <QtCore/QObject>
0029 #include <QtCore/QQueue>
0030 #include <QtCore/QString>
0031 #include <QtCore/QTimer>
0032 #include <QtCore/QTime>
0033 
0034 class KJob;
0035 
0036 namespace KIMAP2
0037 {
0038 
0039 class Job;
0040 struct Message;
0041 class SessionLogger;
0042 class ImapStreamParser;
0043 
0044 class KIMAP2_EXPORT SessionPrivate : public QObject
0045 {
0046     Q_OBJECT
0047 
0048     friend class Session;
0049 
0050 public:
0051     explicit SessionPrivate(Session *session);
0052     virtual ~SessionPrivate();
0053 
0054     void addJob(Job *job);
0055     QByteArray sendCommand(const QByteArray &command, const QByteArray &args = QByteArray());
0056     void startSsl(QSsl::SslProtocol version);
0057     void sendData(const QByteArray &data);
0058 
0059     void setSocketTimeout(int ms);
0060     int socketTimeout() const;
0061 
0062 Q_SIGNALS:
0063     void encryptionNegotiationResult(bool);
0064 
0065 private Q_SLOTS:
0066     void onSocketTimeout();
0067     void onSocketProgressTimeout();
0068 
0069     void doStartNext();
0070     void jobDone(KJob *);
0071     void jobDestroyed(QObject *);
0072 
0073     void socketConnected();
0074     void socketDisconnected();
0075     void socketError(QAbstractSocket::SocketError);
0076     void socketActivity();
0077     void handleSslErrors(const QList<QSslError> &errors);
0078 
0079     void closeSocket();
0080     void readMessage();
0081     void writeDataQueue();
0082     void sslConnected();
0083 
0084 private:
0085     void responseReceived(const KIMAP2::Message &);
0086     void startNext();
0087     void clearJobQueue();
0088     void setState(Session::State state);
0089 
0090     void startSocketTimer();
0091     void stopSocketTimer();
0092     void restartSocketTimer();
0093     QString getStateName() const;
0094 
0095     Session *const q;
0096 
0097     bool isSocketConnected;
0098     Session::State state;
0099     bool hostLookupInProgress;
0100 
0101     QScopedPointer<SessionLogger> logger;
0102 
0103     bool jobRunning;
0104     Job *currentJob;
0105     QQueue<Job *> queue;
0106 
0107     QByteArray authTag;
0108     QByteArray selectTag;
0109     QByteArray closeTag;
0110 
0111     QString userName;
0112     QByteArray greeting;
0113     QByteArray currentMailBox;
0114     QByteArray upcomingMailBox;
0115     quint16 tagCount;
0116 
0117     int socketTimerInterval;
0118     QTimer socketTimer;
0119     int socketProgressInterval;
0120     QTimer socketProgressTimer;
0121 
0122     QString hostName;
0123     quint16 port;
0124 
0125     QScopedPointer<QSslSocket> socket;
0126     QScopedPointer<ImapStreamParser> stream;
0127 
0128     QQueue<QByteArray> dataQueue;
0129 
0130     QTime time;
0131     qint64 accumulatedWaitTime;
0132     qint64 accumulatedProcessingTime;
0133     bool trackTime;
0134     bool dumpTraffic;
0135 };
0136 
0137 }
0138 
0139 #endif