File indexing completed on 2024-11-24 04:53:11
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 #include "MemoryCache.h" 0024 #include <QDebug> 0025 #include <QFile> 0026 0027 //#define CACHE_DEBUG 0028 0029 namespace Imap 0030 { 0031 namespace Mailbox 0032 { 0033 0034 QList<MailboxMetadata> MemoryCache::childMailboxes(const QString &mailbox) const 0035 { 0036 return mailboxes[ mailbox ]; 0037 } 0038 0039 bool MemoryCache::childMailboxesFresh(const QString &mailbox) const 0040 { 0041 return mailboxes.contains(mailbox); 0042 } 0043 0044 void MemoryCache::setChildMailboxes(const QString &mailbox, const QList<MailboxMetadata> &data) 0045 { 0046 #ifdef CACHE_DEBUG 0047 qDebug() << "setting child mailboxes for" << mailbox << "to" << data; 0048 #endif 0049 mailboxes[mailbox] = data; 0050 } 0051 0052 SyncState MemoryCache::mailboxSyncState(const QString &mailbox) const 0053 { 0054 return syncState[mailbox]; 0055 } 0056 0057 void MemoryCache::setMailboxSyncState(const QString &mailbox, const SyncState &state) 0058 { 0059 #ifdef CACHE_DEBUG 0060 qDebug() << "setting mailbox sync state of" << mailbox << "to" << state; 0061 #endif 0062 syncState[mailbox] = state; 0063 } 0064 0065 void MemoryCache::setUidMapping(const QString &mailbox, const Imap::Uids &mapping) 0066 { 0067 #ifdef CACHE_DEBUG 0068 qDebug() << "saving UID mapping for" << mailbox << "to" << mapping; 0069 #endif 0070 seqToUid[mailbox] = mapping; 0071 } 0072 0073 void MemoryCache::clearUidMapping(const QString &mailbox) 0074 { 0075 #ifdef CACHE_DEBUG 0076 qDebug() << "clearing UID mapping for" << mailbox; 0077 #endif 0078 seqToUid.remove(mailbox); 0079 } 0080 0081 void MemoryCache::clearAllMessages(const QString &mailbox) 0082 { 0083 #ifdef CACHE_DEBUG 0084 qDebug() << "pruging all info for mailbox" << mailbox; 0085 #endif 0086 flags.remove(mailbox); 0087 msgMetadata.remove(mailbox); 0088 parts.remove(mailbox); 0089 threads.remove(mailbox); 0090 } 0091 0092 void MemoryCache::clearMessage(const QString mailbox, const uint uid) 0093 { 0094 #ifdef CACHE_DEBUG 0095 qDebug() << "pruging all info for message" << mailbox << uid; 0096 #endif 0097 if (flags.contains(mailbox)) 0098 flags[mailbox].remove(uid); 0099 if (msgMetadata.contains(mailbox)) 0100 msgMetadata[mailbox].remove(uid); 0101 if (parts.contains(mailbox)) 0102 parts[mailbox].remove(uid); 0103 } 0104 0105 void MemoryCache::setMsgPart(const QString &mailbox, const uint uid, const QByteArray &partId, const QByteArray &data) 0106 { 0107 #ifdef CACHE_DEBUG 0108 qDebug() << "set message part" << mailbox << uid << partId << data.size(); 0109 #endif 0110 parts[mailbox][uid][partId] = data; 0111 } 0112 0113 void MemoryCache::forgetMessagePart(const QString &mailbox, const uint uid, const QByteArray &partId) 0114 { 0115 #ifdef CACHE_DEBUG 0116 qDebug() << "forget message part" << mailbox << uid << partId; 0117 #endif 0118 parts[mailbox][uid].remove(partId); 0119 0120 } 0121 0122 void MemoryCache::setMsgFlags(const QString &mailbox, uint uid, const QStringList &newFlags) 0123 { 0124 #ifdef CACHE_DEBUG 0125 qDebug() << "set FLAGS for" << mailbox << uid << newFlags; 0126 #endif 0127 flags[mailbox][uid] = newFlags; 0128 } 0129 0130 QStringList MemoryCache::msgFlags(const QString &mailbox, const uint uid) const 0131 { 0132 return flags[mailbox][uid]; 0133 } 0134 0135 Imap::Uids MemoryCache::uidMapping(const QString &mailbox) const 0136 { 0137 return seqToUid[mailbox]; 0138 } 0139 0140 void MemoryCache::setMessageMetadata(const QString &mailbox, const uint uid, const MessageDataBundle &metadata) 0141 { 0142 msgMetadata[mailbox][uid] = metadata; 0143 } 0144 0145 MemoryCache::MessageDataBundle MemoryCache::messageMetadata(const QString &mailbox, const uint uid) const 0146 { 0147 const QMap<uint, MessageDataBundle> &firstLevel = msgMetadata[ mailbox ]; 0148 QMap<uint, MessageDataBundle>::const_iterator it = firstLevel.find(uid); 0149 if (it == firstLevel.end()) { 0150 return MessageDataBundle(); 0151 } 0152 return *it; 0153 } 0154 0155 QByteArray MemoryCache::messagePart(const QString &mailbox, const uint uid, const QByteArray &partId) const 0156 { 0157 if (! parts.contains(mailbox)) 0158 return QByteArray(); 0159 const auto & mailboxParts = parts[mailbox]; 0160 if (! mailboxParts.contains(uid)) 0161 return QByteArray(); 0162 const auto & messageParts = mailboxParts[uid]; 0163 if (! messageParts.contains(partId)) 0164 return QByteArray(); 0165 return messageParts[ partId ]; 0166 } 0167 0168 QVector<Imap::Responses::ThreadingNode> MemoryCache::messageThreading(const QString &mailbox) 0169 { 0170 return threads[mailbox]; 0171 } 0172 0173 void MemoryCache::setMessageThreading(const QString &mailbox, const QVector<Imap::Responses::ThreadingNode> &threading) 0174 { 0175 threads[mailbox] = threading; 0176 } 0177 0178 void MemoryCache::setRenewalThreshold(const int days) 0179 { 0180 Q_UNUSED(days); 0181 } 0182 0183 } 0184 }