File indexing completed on 2024-09-22 04:52:51
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 0023 #ifndef IMAP_PARSER_SEQUENCE_H 0024 #define IMAP_PARSER_SEQUENCE_H 0025 0026 #include <QString> 0027 #include "Imap/Parser/Uids.h" 0028 0029 /** @short Namespace for IMAP interaction */ 0030 namespace Imap 0031 { 0032 0033 /** @short Class specifying a set of messagess to access 0034 0035 Although named a sequence, there's no reason for a sequence to contain 0036 only consecutive ranges of numbers. For example, a set of 0037 { 1, 2, 3, 10, 15, 16, 17 } is perfectly valid sequence. 0038 */ 0039 class Sequence 0040 { 0041 uint lo, hi; 0042 Imap::Uids numbers; 0043 enum { DISTINCT, RANGE, UNLIMITED } kind; 0044 public: 0045 /** @short Construct an invalid sequence */ 0046 Sequence(): kind(DISTINCT) {} 0047 0048 /** @short Construct a sequence holding only one number 0049 0050 Such a sequence can be subsequently expanded by using its add() method. 0051 There's no way to turn it into an unlimited sequence, though -- use 0052 the startingAt() for creating sequences that grow to the "infinite". 0053 */ 0054 explicit Sequence(const uint num); 0055 0056 /** @short Construct a sequence holding a set of numbers between upper and lower bound 0057 0058 This sequence can't be expanded ever after. Calling add() on it will 0059 assert(). 0060 */ 0061 Sequence(const uint lo, const uint hi): lo(lo), hi(hi), kind(RANGE) {} 0062 0063 /** @short Create an "unlimited" sequence 0064 0065 That's a sequence that starts at the specified offset and grow to the 0066 current maximal boundary. There's no way to add a distinct item to 0067 this set; doing so via the add() method will assert */ 0068 static Sequence startingAt(const uint lo); 0069 0070 /** @short Add another number to the sequence 0071 0072 Note that you can only add numbers to a sequence created by the 0073 Sequence( const uint num ) constructor. Attempting to do so on other 0074 kinds of sequences will assert(). 0075 */ 0076 Sequence &add(const uint num); 0077 0078 /** @short Converts sequence to a textual representation suitable for sending over the wire */ 0079 QByteArray toByteArray() const; 0080 0081 /** @short Converts sequence to a list of UIDs */ 0082 Imap::Uids toVector() const; 0083 0084 /** @short Create a sequence from a list of numbers */ 0085 static Sequence fromVector(Imap::Uids numbers); 0086 0087 /** @short Return true if the sequence contains at least some items */ 0088 bool isValid() const; 0089 0090 }; 0091 0092 bool operator==(const Sequence &a, const Sequence &b); 0093 0094 } 0095 #endif /* IMAP_PARSER_SEQUENCE_H */