1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
2 
3    This file is part of the Trojita Qt IMAP e-mail client,
4    http://trojita.flaska.net/
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2 of
9    the License or (at your option) version 3 or any later version
10    accepted by the membership of KDE e.V. (or its successor approved
11    by the membership of KDE e.V.), which shall act as a proxy
12    defined in Section 14 of version 3 of the license.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef IMAP_MODEL_MAILBOXMETADATA_H
24 #define IMAP_MODEL_MAILBOXMETADATA_H
25 
26 #include <QDebug>
27 #include <QStringList>
28 
29 namespace Imap
30 {
31 namespace Mailbox
32 {
33 
34 struct MailboxMetadata {
35     QString mailbox;
36     QString separator;
37     QStringList flags;
38 
MailboxMetadataMailboxMetadata39     MailboxMetadata(const QString &mailbox, const QString &separator, const QStringList &flags):
40         mailbox(mailbox), separator(separator), flags(flags) {}
MailboxMetadataMailboxMetadata41     MailboxMetadata() {}
42 };
43 
44 inline bool operator==(const MailboxMetadata &a, const MailboxMetadata &b)
45 {
46     return a.mailbox == b.mailbox && a.separator == b.separator && a.flags == b.flags;
47 }
48 
49 inline bool operator!=(const MailboxMetadata &a, const MailboxMetadata &b)
50 {
51     return ! (a == b);
52 }
53 
54 /** @short Class for keeping track of information from the SELECT command */
55 class SyncState
56 {
57     uint m_exists, m_recent, m_unSeenCount, m_unSeenOffset, m_uidNext, m_uidValidity;
58     quint64 m_highestModSeq;
59     QStringList m_flags, m_permanentFlags;
60 
61     bool m_hasExists, m_hasRecent, m_hasUnSeenCount, m_hasUnSeenOffset, m_hasUidNext, m_hasUidValidity,
62          m_hasHighestModSeq, m_hasFlags, m_hasPermanentFlags;
63 
64     friend QDebug operator<<(QDebug dbg, const Imap::Mailbox::SyncState &state);
65 public:
66     SyncState();
67     uint exists() const;
68     uint recent() const;
69     uint unSeenCount() const;
70     uint unSeenOffset() const;
71     uint uidNext() const;
72     uint uidValidity() const;
73     quint64 highestModSeq() const;
74     QStringList flags() const;
75     QStringList permanentFlags() const;
76 
77     void setExists(const uint exists);
78     void setRecent(const uint recent);
79     void setUnSeenCount(const uint unSeenCount);
80     void setUnSeenOffset(const uint unSeenOffset);
81     void setUidNext(const uint uidNext);
82     void setUidValidity(const uint uidValidity);
83     void setHighestModSeq(const quint64 highestModSeq);
84     void setFlags(const QStringList &flags);
85     void setPermanentFlags(const QStringList &permanentFlags);
86 
87     /** @short Return true if the record contains all items needed to display message numbers
88 
89       Ie. check for EXISTS, RECENT and UNSEEN.
90     */
91     bool isUsableForNumbers() const;
92     /** @short Return true if all items really required for re-sync are available
93 
94       These fields are just UIDNEXT, UIDVALIDITY and EXISTS. We don't care about
95       crap like RECENT.
96     */
97     bool isUsableForSyncing() const;
98     bool isUsableForSyncingWithoutUidNext() const;
99 
100     bool isUsableForCondstore() const;
101 
102     /** @short Compare all members (including the hidden ones) with other */
103     bool completelyEqualTo(const SyncState &other) const;
104 };
105 
106 QDebug operator<<(QDebug dbg, const Imap::Mailbox::SyncState &state);
107 
108 }
109 }
110 
111 QDebug operator<<(QDebug dbg, const Imap::Mailbox::MailboxMetadata &metadata);
112 
113 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::SyncState &ss);
114 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::SyncState &ss);
115 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::MailboxMetadata &mm);
116 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::MailboxMetadata &mm);
117 
118 #endif
119