File indexing completed on 2024-11-24 04:53:09
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 #include "MailboxMetadata.h" 0023 #include <QDataStream> 0024 0025 namespace Imap 0026 { 0027 namespace Mailbox 0028 { 0029 0030 0031 SyncState::SyncState(): 0032 m_exists(0), m_recent(0), m_unSeenCount(0), m_unSeenOffset(0), m_uidNext(0), m_uidValidity(0), m_highestModSeq(0), 0033 m_hasExists(false), m_hasRecent(false), m_hasUnSeenCount(false), m_hasUnSeenOffset(false), 0034 m_hasUidNext(false), m_hasUidValidity(false), m_hasHighestModSeq(false), m_hasFlags(false), 0035 m_hasPermanentFlags(false) 0036 { 0037 } 0038 0039 bool SyncState::isUsableForNumbers() const 0040 { 0041 return m_hasExists && m_hasRecent && m_hasUnSeenCount; 0042 } 0043 0044 bool SyncState::isUsableForSyncing() const 0045 { 0046 return m_hasExists && m_hasUidNext && m_hasUidValidity; 0047 } 0048 0049 bool SyncState::isUsableForSyncingWithoutUidNext() const 0050 { 0051 return m_hasExists && m_hasUidValidity; 0052 } 0053 0054 bool SyncState::isUsableForCondstore() const 0055 { 0056 return m_hasHighestModSeq && highestModSeq() > 0 && isUsableForSyncing(); 0057 } 0058 0059 uint SyncState::exists() const 0060 { 0061 return m_exists; 0062 } 0063 0064 void SyncState::setExists(const uint exists) 0065 { 0066 m_exists = exists; 0067 m_hasExists = true; 0068 } 0069 0070 QStringList SyncState::flags() const 0071 { 0072 return m_flags; 0073 } 0074 0075 void SyncState::setFlags(const QStringList &flags) 0076 { 0077 m_flags = flags; 0078 m_hasFlags = true; 0079 } 0080 0081 QStringList SyncState::permanentFlags() const 0082 { 0083 return m_permanentFlags; 0084 } 0085 0086 void SyncState::setPermanentFlags(const QStringList &permanentFlags) 0087 { 0088 m_permanentFlags = permanentFlags; 0089 m_hasPermanentFlags = true; 0090 } 0091 0092 uint SyncState::recent() const 0093 { 0094 return m_recent; 0095 } 0096 0097 void SyncState::setRecent(const uint recent) 0098 { 0099 m_recent = recent; 0100 m_hasRecent = true; 0101 } 0102 0103 uint SyncState::uidNext() const 0104 { 0105 return m_uidNext; 0106 } 0107 0108 void SyncState::setUidNext(const uint uidNext) 0109 { 0110 m_uidNext = uidNext; 0111 m_hasUidNext = true; 0112 } 0113 0114 uint SyncState::uidValidity() const 0115 { 0116 return m_uidValidity; 0117 } 0118 0119 void SyncState::setUidValidity(const uint uidValidity) 0120 { 0121 m_uidValidity = uidValidity; 0122 m_hasUidValidity = true; 0123 } 0124 0125 uint SyncState::unSeenCount() const 0126 { 0127 return m_unSeenCount; 0128 } 0129 0130 void SyncState::setUnSeenCount(const uint unSeen) 0131 { 0132 m_unSeenCount = unSeen; 0133 m_hasUnSeenCount = true; 0134 } 0135 0136 uint SyncState::unSeenOffset() const 0137 { 0138 return m_unSeenOffset; 0139 } 0140 0141 void SyncState::setUnSeenOffset(const uint unSeen) 0142 { 0143 m_unSeenOffset = unSeen; 0144 m_hasUnSeenOffset = true; 0145 } 0146 0147 quint64 SyncState::highestModSeq() const 0148 { 0149 return m_highestModSeq; 0150 } 0151 0152 void SyncState::setHighestModSeq(const quint64 highestModSeq) 0153 { 0154 m_highestModSeq = highestModSeq; 0155 m_hasHighestModSeq = true; 0156 } 0157 0158 bool SyncState::completelyEqualTo(const SyncState &other) const 0159 { 0160 return m_exists == other.m_exists && m_recent == other.m_recent && m_unSeenCount == other.m_unSeenCount && 0161 m_unSeenOffset == other.m_unSeenOffset && m_uidNext == other.m_uidNext && m_uidValidity == other.m_uidValidity && 0162 m_highestModSeq == other.m_highestModSeq && m_flags == other.m_flags && m_permanentFlags == other.m_permanentFlags && 0163 m_hasExists == other.m_hasExists && m_hasRecent == other.m_hasRecent && m_hasUnSeenCount == other.m_hasUnSeenCount && 0164 m_hasUnSeenOffset == other.m_hasUnSeenOffset && m_hasUidNext == other.m_hasUidNext && 0165 m_hasUidValidity == other.m_hasUidValidity && m_hasHighestModSeq == other.m_hasHighestModSeq && 0166 m_hasFlags == other.m_hasFlags && m_hasPermanentFlags == other.m_hasPermanentFlags; 0167 } 0168 0169 QDebug operator<<(QDebug dbg, const Imap::Mailbox::SyncState &state) 0170 { 0171 dbg << "UIDVALIDITY"; 0172 if (state.m_hasUidValidity) 0173 dbg << state.uidValidity(); 0174 else 0175 dbg << "n/a"; 0176 dbg << "UIDNEXT"; 0177 if (state.m_hasUidNext) 0178 dbg << state.uidNext(); 0179 else 0180 dbg << "n/a"; 0181 dbg << "EXISTS"; 0182 if (state.m_hasExists) 0183 dbg << state.exists(); 0184 else 0185 dbg << "n/a"; 0186 dbg << "HIGHESTMODSEQ"; 0187 if (state.m_hasHighestModSeq) 0188 dbg << state.highestModSeq(); 0189 else 0190 dbg << "n/a"; 0191 dbg << "UNSEEN-count"; 0192 if (state.m_hasUnSeenCount) 0193 dbg << state.unSeenCount(); 0194 else 0195 dbg << "n/a"; 0196 dbg << "UNSEEN-offset"; 0197 if (state.m_hasUnSeenOffset) 0198 dbg << state.unSeenOffset(); 0199 else 0200 dbg << "n/a"; 0201 dbg << "RECENT"; 0202 if (state.m_hasRecent) 0203 dbg << state.recent(); 0204 else 0205 dbg << "n/a"; 0206 dbg << "PERMANENTFLAGS"; 0207 if (state.m_hasPermanentFlags) 0208 dbg << state.permanentFlags(); 0209 else 0210 dbg << "n/a"; 0211 return dbg; 0212 } 0213 0214 } 0215 } 0216 0217 0218 QDebug operator<<(QDebug dbg, const Imap::Mailbox::MailboxMetadata &metadata) 0219 { 0220 return dbg << metadata.mailbox << metadata.separator << metadata.flags; 0221 } 0222 0223 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::SyncState &ss) 0224 { 0225 uint i; 0226 quint64 i64; 0227 QStringList list; 0228 stream >> i; ss.setExists(i); 0229 stream >> list; ss.setFlags(list); 0230 stream >> list; ss.setPermanentFlags(list); 0231 stream >> i; ss.setRecent(i); 0232 stream >> i; ss.setUidNext(i); 0233 stream >> i; ss.setUidValidity(i); 0234 stream >> i64; ss.setHighestModSeq(i64); 0235 stream >> i; ss.setUnSeenCount(i); 0236 stream >> i; ss.setUnSeenOffset(i); 0237 return stream; 0238 } 0239 0240 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::SyncState &ss) 0241 { 0242 return stream << ss.exists() << ss.flags() << ss.permanentFlags() << 0243 ss.recent() << ss.uidNext() << ss.uidValidity() << ss.highestModSeq() << ss.unSeenCount() << ss.unSeenOffset(); 0244 } 0245 0246 QDataStream &operator>>(QDataStream &stream, Imap::Mailbox::MailboxMetadata &mm) 0247 { 0248 return stream >> mm.flags >> mm.mailbox >> mm.separator; 0249 } 0250 0251 QDataStream &operator<<(QDataStream &stream, const Imap::Mailbox::MailboxMetadata &mm) 0252 { 0253 return stream << mm.flags << mm.mailbox << mm.separator; 0254 } 0255