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 #ifndef IMAP_MODEL_MEMORYCACHE_H 0024 #define IMAP_MODEL_MEMORYCACHE_H 0025 0026 #include "Cache.h" 0027 #include <QMap> 0028 0029 /** @short Namespace for IMAP interaction */ 0030 namespace Imap 0031 { 0032 0033 /** @short Classes for handling of mailboxes and connections */ 0034 namespace Mailbox 0035 { 0036 0037 /** @short A cache implementation that uses in-memory cache 0038 0039 It also has an optional feature to dump the data to a local file and read 0040 it back in. Is isn't suitable for real production use, but it's a good start. 0041 */ 0042 class MemoryCache : public AbstractCache 0043 { 0044 public: 0045 QList<MailboxMetadata> childMailboxes(const QString &mailbox) const override; 0046 bool childMailboxesFresh(const QString &mailbox) const override; 0047 void setChildMailboxes(const QString &mailbox, const QList<MailboxMetadata> &data) override; 0048 0049 SyncState mailboxSyncState(const QString &mailbox) const override; 0050 void setMailboxSyncState(const QString &mailbox, const SyncState &state) override; 0051 0052 void setUidMapping(const QString &mailbox, const Imap::Uids &mapping) override; 0053 void clearUidMapping(const QString &mailbox) override; 0054 Imap::Uids uidMapping(const QString &mailbox) const override; 0055 0056 void clearAllMessages(const QString &mailbox) override; 0057 void clearMessage(const QString mailbox, const uint uid) override; 0058 0059 MessageDataBundle messageMetadata(const QString &mailbox, const uint uid) const override; 0060 void setMessageMetadata(const QString &mailbox, const uint uid, const MessageDataBundle &metadata) override; 0061 0062 QStringList msgFlags(const QString &mailbox, const uint uid) const override; 0063 void setMsgFlags(const QString &mailbox, const uint uid, const QStringList &newFlags) override; 0064 0065 QByteArray messagePart(const QString &mailbox, const uint uid, const QByteArray &partId) const override; 0066 void setMsgPart(const QString &mailbox, const uint uid, const QByteArray &partId, const QByteArray &data) override; 0067 void forgetMessagePart(const QString &mailbox, const uint uid, const QByteArray &partId) override; 0068 0069 QVector<Imap::Responses::ThreadingNode> messageThreading(const QString &mailbox) override; 0070 void setMessageThreading(const QString &mailbox, const QVector<Imap::Responses::ThreadingNode> &threading) override; 0071 0072 void setRenewalThreshold(const int days) override; 0073 0074 private: 0075 QMap<QString, QList<MailboxMetadata> > mailboxes; 0076 QMap<QString, SyncState> syncState; 0077 QMap<QString, Imap::Uids> seqToUid; 0078 QMap<QString, QMap<uint,QStringList> > flags; 0079 QMap<QString, QMap<uint, MessageDataBundle> > msgMetadata; 0080 QMap<QString, QMap<uint, QMap<QByteArray, QByteArray> > > parts; 0081 QMap<QString, QVector<Imap::Responses::ThreadingNode> > threads; 0082 }; 0083 0084 } 0085 0086 } 0087 0088 #endif /* IMAP_MODEL_MEMORYCACHE_H */