KIMAP Library
imapstreamparser.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KIMAP_IMAPSTREAMPARSER_P_H
00022 #define KIMAP_IMAPSTREAMPARSER_P_H
00023
00024 #include "kimap_export.h"
00025
00026 #include <exception>
00027
00028 #include <QtCore/QByteArray>
00029 #include <QtCore/QList>
00030 #include <QtCore/QString>
00031
00032 class QIODevice;
00033
00034 namespace KIMAP {
00035
00036 class ImapParserException : public std::exception
00037 {
00038 public:
00039 ImapParserException( const char *what ) throw() : mWhat( what ) {}
00040 ImapParserException( const QByteArray &what ) throw() : mWhat( what ) {}
00041 ImapParserException( const QString &what ) throw() : mWhat( what.toUtf8() ) {}
00042 ImapParserException( const ImapParserException &other ) throw() : mWhat( other.what() ) {}
00043 virtual ~ImapParserException() throw() {}
00044 const char *what() const throw() { return mWhat.constData(); }
00045 virtual const char *type() const throw() { return "ImapParserException"; }
00046 private:
00047 QByteArray mWhat;
00048 };
00049
00053 class KIMAP_EXPORT ImapStreamParser
00054 {
00055 public:
00060 ImapStreamParser( QIODevice* socket);
00061
00065 ~ImapStreamParser();
00066
00072 QString readUtf8String();
00073
00078 QByteArray readString();
00079
00085 QList<QByteArray> readParenthesizedList();
00086
00087
00093 qint64 readNumber( bool * ok = 0 );
00094
00099 bool hasString();
00100
00107 bool hasLiteral();
00108
00128 QByteArray readLiteralPart();
00129
00134 bool atLiteralEnd() const;
00135
00140 bool hasList();
00141
00146 bool atListEnd();
00147
00152 bool hasResponseCode();
00153
00158 bool atResponseCodeEnd();
00159
00164 bool atCommandEnd();
00165
00170 QByteArray readUntilCommandEnd();
00171
00176 QByteArray readRemainingData();
00177
00178 int availableDataSize() const;
00179
00180 void setData( const QByteArray &data );
00181
00182
00183 private:
00184 void stripLeadingSpaces();
00185 QByteArray parseQuotedString();
00186
00193 bool waitForMoreData( bool wait);
00194
00198 void sendContinuationResponse();
00199
00200 QIODevice *m_socket;
00201 QByteArray m_data;
00202 int m_position;
00203 qint64 m_literalSize;
00204 qint64 m_continuationSize;
00205 };
00206
00207 }
00208
00209 #endif