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 #include "MailboxMetadata.h"
23 #include <QDataStream>
24
25 namespace Imap
26 {
27 namespace Mailbox
28 {
29
30
SyncState()31 SyncState::SyncState():
32 m_exists(0), m_recent(0), m_unSeenCount(0), m_unSeenOffset(0), m_uidNext(0), m_uidValidity(0), m_highestModSeq(0),
33 m_hasExists(false), m_hasRecent(false), m_hasUnSeenCount(false), m_hasUnSeenOffset(false),
34 m_hasUidNext(false), m_hasUidValidity(false), m_hasHighestModSeq(false), m_hasFlags(false),
35 m_hasPermanentFlags(false)
36 {
37 }
38
isUsableForNumbers() const39 bool SyncState::isUsableForNumbers() const
40 {
41 return m_hasExists && m_hasRecent && m_hasUnSeenCount;
42 }
43
isUsableForSyncing() const44 bool SyncState::isUsableForSyncing() const
45 {
46 return m_hasExists && m_hasUidNext && m_hasUidValidity;
47 }
48
isUsableForSyncingWithoutUidNext() const49 bool SyncState::isUsableForSyncingWithoutUidNext() const
50 {
51 return m_hasExists && m_hasUidValidity;
52 }
53
isUsableForCondstore() const54 bool SyncState::isUsableForCondstore() const
55 {
56 return m_hasHighestModSeq && highestModSeq() > 0 && isUsableForSyncing();
57 }
58
exists() const59 uint SyncState::exists() const
60 {
61 return m_exists;
62 }
63
setExists(const uint exists)64 void SyncState::setExists(const uint exists)
65 {
66 m_exists = exists;
67 m_hasExists = true;
68 }
69
flags() const70 QStringList SyncState::flags() const
71 {
72 return m_flags;
73 }
74
setFlags(const QStringList & flags)75 void SyncState::setFlags(const QStringList &flags)
76 {
77 m_flags = flags;
78 m_hasFlags = true;
79 }
80
permanentFlags() const81 QStringList SyncState::permanentFlags() const
82 {
83 return m_permanentFlags;
84 }
85
setPermanentFlags(const QStringList & permanentFlags)86 void SyncState::setPermanentFlags(const QStringList &permanentFlags)
87 {
88 m_permanentFlags = permanentFlags;
89 m_hasPermanentFlags = true;
90 }
91
recent() const92 uint SyncState::recent() const
93 {
94 return m_recent;
95 }
96
setRecent(const uint recent)97 void SyncState::setRecent(const uint recent)
98 {
99 m_recent = recent;
100 m_hasRecent = true;
101 }
102
uidNext() const103 uint SyncState::uidNext() const
104 {
105 return m_uidNext;
106 }
107
setUidNext(const uint uidNext)108 void SyncState::setUidNext(const uint uidNext)
109 {
110 m_uidNext = uidNext;
111 m_hasUidNext = true;
112 }
113
uidValidity() const114 uint SyncState::uidValidity() const
115 {
116 return m_uidValidity;
117 }
118
setUidValidity(const uint uidValidity)119 void SyncState::setUidValidity(const uint uidValidity)
120 {
121 m_uidValidity = uidValidity;
122 m_hasUidValidity = true;
123 }
124
unSeenCount() const125 uint SyncState::unSeenCount() const
126 {
127 return m_unSeenCount;
128 }
129
setUnSeenCount(const uint unSeen)130 void SyncState::setUnSeenCount(const uint unSeen)
131 {
132 m_unSeenCount = unSeen;
133 m_hasUnSeenCount = true;
134 }
135
unSeenOffset() const136 uint SyncState::unSeenOffset() const
137 {
138 return m_unSeenOffset;
139 }
140
setUnSeenOffset(const uint unSeen)141 void SyncState::setUnSeenOffset(const uint unSeen)
142 {
143 m_unSeenOffset = unSeen;
144 m_hasUnSeenOffset = true;
145 }
146
highestModSeq() const147 quint64 SyncState::highestModSeq() const
148 {
149 return m_highestModSeq;
150 }
151
setHighestModSeq(const quint64 highestModSeq)152 void SyncState::setHighestModSeq(const quint64 highestModSeq)
153 {
154 m_highestModSeq = highestModSeq;
155 m_hasHighestModSeq = true;
156 }
157
completelyEqualTo(const SyncState & other) const158 bool SyncState::completelyEqualTo(const SyncState &other) const
159 {
160 return m_exists == other.m_exists && m_recent == other.m_recent && m_unSeenCount == other.m_unSeenCount &&
161 m_unSeenOffset == other.m_unSeenOffset && m_uidNext == other.m_uidNext && m_uidValidity == other.m_uidValidity &&
162 m_highestModSeq == other.m_highestModSeq && m_flags == other.m_flags && m_permanentFlags == other.m_permanentFlags &&
163 m_hasExists == other.m_hasExists && m_hasRecent == other.m_hasRecent && m_hasUnSeenCount == other.m_hasUnSeenCount &&
164 m_hasUnSeenOffset == other.m_hasUnSeenOffset && m_hasUidNext == other.m_hasUidNext &&
165 m_hasUidValidity == other.m_hasUidValidity && m_hasHighestModSeq == other.m_hasHighestModSeq &&
166 m_hasFlags == other.m_hasFlags && m_hasPermanentFlags == other.m_hasPermanentFlags;
167 }
168
operator <<(QDebug dbg,const Imap::Mailbox::SyncState & state)169 QDebug operator<<(QDebug dbg, const Imap::Mailbox::SyncState &state)
170 {
171 dbg << "UIDVALIDITY";
172 if (state.m_hasUidValidity)
173 dbg << state.uidValidity();
174 else
175 dbg << "n/a";
176 dbg << "UIDNEXT";
177 if (state.m_hasUidNext)
178 dbg << state.uidNext();
179 else
180 dbg << "n/a";
181 dbg << "EXISTS";
182 if (state.m_hasExists)
183 dbg << state.exists();
184 else
185 dbg << "n/a";
186 dbg << "HIGHESTMODSEQ";
187 if (state.m_hasHighestModSeq)
188 dbg << state.highestModSeq();
189 else
190 dbg << "n/a";
191 dbg << "UNSEEN-count";
192 if (state.m_hasUnSeenCount)
193 dbg << state.unSeenCount();
194 else
195 dbg << "n/a";
196 dbg << "UNSEEN-offset";
197 if (state.m_hasUnSeenOffset)
198 dbg << state.unSeenOffset();
199 else
200 dbg << "n/a";
201 dbg << "RECENT";
202 if (state.m_hasRecent)
203 dbg << state.recent();
204 else
205 dbg << "n/a";
206 dbg << "PERMANENTFLAGS";
207 if (state.m_hasPermanentFlags)
208 dbg << state.permanentFlags();
209 else
210 dbg << "n/a";
211 return dbg;
212 }
213
214 }
215 }
216
217
operator <<(QDebug dbg,const Imap::Mailbox::MailboxMetadata & metadata)218 QDebug operator<<(QDebug dbg, const Imap::Mailbox::MailboxMetadata &metadata)
219 {
220 return dbg << metadata.mailbox << metadata.separator << metadata.flags;
221 }
222
operator >>(QDataStream & stream,Imap::Mailbox::SyncState & ss)223 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::SyncState &ss)
224 {
225 uint i;
226 quint64 i64;
227 QStringList list;
228 stream >> i; ss.setExists(i);
229 stream >> list; ss.setFlags(list);
230 stream >> list; ss.setPermanentFlags(list);
231 stream >> i; ss.setRecent(i);
232 stream >> i; ss.setUidNext(i);
233 stream >> i; ss.setUidValidity(i);
234 stream >> i64; ss.setHighestModSeq(i64);
235 stream >> i; ss.setUnSeenCount(i);
236 stream >> i; ss.setUnSeenOffset(i);
237 return stream;
238 }
239
operator <<(QDataStream & stream,const Imap::Mailbox::SyncState & ss)240 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::SyncState &ss)
241 {
242 return stream << ss.exists() << ss.flags() << ss.permanentFlags() <<
243 ss.recent() << ss.uidNext() << ss.uidValidity() << ss.highestModSeq() << ss.unSeenCount() << ss.unSeenOffset();
244 }
245
operator >>(QDataStream & stream,Imap::Mailbox::MailboxMetadata & mm)246 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::MailboxMetadata &mm)
247 {
248 return stream >> mm.flags >> mm.mailbox >> mm.separator;
249 }
250
operator <<(QDataStream & stream,const Imap::Mailbox::MailboxMetadata & mm)251 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::MailboxMetadata &mm)
252 {
253 return stream << mm.flags << mm.mailbox << mm.separator;
254 }
255
256