File indexing completed on 2024-09-22 04:52:49
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 #ifndef IMAP_LOWLEVELPARSER_H 0023 #define IMAP_LOWLEVELPARSER_H 0024 0025 #include <QList> 0026 #include <QPair> 0027 #include <QVariant> 0028 #include "Imap/Parser/Uids.h" 0029 0030 namespace Imap 0031 { 0032 0033 /** @short Low-level parsing of IMAP data 0034 * 0035 * This namespace contains functions for extracting low-level stuff like atoms, 0036 * integers or strings from a raw data that server sent us. 0037 * 0038 * All functions share a similar API -- first argument, a QByteArray instance, 0039 * holds *complete* line including trailing CRLF, second argument is offset 0040 * where the parsing should start. It's a non-const reference to int as it gets 0041 * changed after the requested item is read. 0042 * 0043 * All functions assume that all {size}-based literals are already prefetched, 0044 * ie. there's no interaction with the Imap::Parser's methods for retrieving 0045 * further data. 0046 * */ 0047 namespace LowLevelParser 0048 { 0049 0050 enum ParsedAs { 0051 ATOM /**< @short Parsed as RFC3501 "atom" data type */, 0052 ASTRING, /**< @short "atom" with "resp-specials" */ 0053 QUOTED /**< @short Quoted string (enclosed in single pair of double quotes */, 0054 LITERAL /**< @short String literal, ie. the {size}-form */, 0055 LITERAL8 /**< @short The literal8 syntax from BINARY */, 0056 NIL /**< @short A special-case atom NIL */ 0057 }; 0058 0059 /** @short Read an unsigned integer from input */ 0060 uint getUInt(const QByteArray &line, int &start); 0061 0062 /** @short Read a 64bit unsigned integer from input */ 0063 quint64 getUInt64(const QByteArray &line, int &start); 0064 0065 /** @short Read an ATOM */ 0066 QByteArray getAtom(const QByteArray &line, int &start); 0067 QByteArray getPossiblyBackslashedAtom(const QByteArray &line, int &start); 0068 0069 /** @short Read a quoted string or literal */ 0070 QPair<QByteArray,ParsedAs> getString(const QByteArray &line, int &start); 0071 0072 /** @short Read atom or string */ 0073 QPair<QByteArray,ParsedAs> getAString(const QByteArray &line, int &start); 0074 0075 /** @short Read NIL or a string */ 0076 QPair<QByteArray,ParsedAs> getNString(const QByteArray &line, int &start); 0077 0078 /** @short Retrieve mailbox name */ 0079 QString getMailbox(const QByteArray &line, int &start); 0080 0081 /** @short Parse parenthesized list 0082 * 0083 * Parenthesized lists is defined as a sequence of space-separated strings 0084 * enclosed between "open" and "close" characters. 0085 * 0086 * @param open, close -- enclosing parentheses 0087 * @param line, start -- full line data and starting offset 0088 * 0089 * We need to support parsing of nested lists (as found in the envelope data 0090 * structure), that's why we deal with QVariant here. 0091 * */ 0092 QVariantList parseList(const char open, const char close, 0093 const QByteArray &line, int &start); 0094 0095 /** @short Read one item from input, store it in a most-appropriate form */ 0096 QVariant getAnything(const QByteArray &line, int &start); 0097 0098 /** @short Parse a sequence set from the input */ 0099 Imap::Uids getSequence(const QByteArray &line, int &start); 0100 0101 /** @short Parse RFC2822-like formatted date 0102 * 0103 * Code for this class was lobotomized from KDE's KDateTime. 0104 * */ 0105 QDateTime parseRFC2822DateTime(const QByteArray &input); 0106 0107 /** @short Eat spaces as long as we can */ 0108 void eatSpaces(const QByteArray &line, int &start); 0109 } 0110 } 0111 0112 #endif /* IMAP_LOWLEVELPARSER_H */