KIMAP

imapstreamparser.h
1 /*
2  SPDX-FileCopyrightText: 2006-2007 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KIMAP_IMAPSTREAMPARSER_P_H
9 #define KIMAP_IMAPSTREAMPARSER_P_H
10 
11 #include "kimap_export.h"
12 
13 #include <exception>
14 
15 #include <QByteArray>
16 #include <QList>
17 #include <QString>
18 
19 class QIODevice;
20 
21 namespace KIMAP
22 {
23 
24 class ImapParserException : public std::exception
25 {
26 public:
27  explicit ImapParserException(const char *what) throw() : mWhat(what) {}
28  explicit ImapParserException(const QByteArray &what) throw() : mWhat(what) {}
29  explicit ImapParserException(const QString &what) throw() : mWhat(what.toUtf8()) {}
30  ImapParserException(const ImapParserException &other) throw() : std::exception(other), mWhat(other.what()) {}
31  virtual ~ImapParserException() throw() {}
32  const char *what() const throw() override
33  {
34  return mWhat.constData();
35  }
36  virtual const char *type() const throw()
37  {
38  return "ImapParserException";
39  }
40 private:
41  QByteArray mWhat;
42 };
43 
47 class KIMAP_EXPORT ImapStreamParser
48 {
49 public:
56  explicit ImapStreamParser(QIODevice *socket, bool serverModeEnabled = false);
57 
63  QString readUtf8String();
64 
69  QByteArray readString();
70 
76  QList<QByteArray> readParenthesizedList();
77 
83  qint64 readNumber(bool *ok = nullptr);
84 
89  bool hasString();
90 
97  bool hasLiteral();
98 
118  QByteArray readLiteralPart();
119 
124  bool atLiteralEnd() const;
125 
130  bool hasList();
131 
136  bool atListEnd();
137 
142  bool hasResponseCode();
143 
148  bool atResponseCodeEnd();
149 
154  bool atCommandEnd();
155 
160  QByteArray readUntilCommandEnd();
161 
166  QByteArray readRemainingData();
167 
168  int availableDataSize() const;
169 
170  void setData(const QByteArray &data);
171 
172 private:
173  void stripLeadingSpaces();
174  QByteArray parseQuotedString();
175 
182  bool waitForMoreData(bool wait);
183 
187  void sendContinuationResponse(qint64 size);
188 
192  void trimBuffer();
193 
194  QIODevice *m_socket = nullptr;
195  bool m_isServerModeEnabled = false;
196  QByteArray m_data;
197  int m_position = -1;
198  qint64 m_literalSize = -1;
199 };
200 
201 }
202 
203 #endif
Parser for IMAP messages that operates on a local socket stream.
Type type(const QSqlDatabase &db)
Definition: acl.cpp:12
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Oct 24 2020 23:16:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.