File indexing completed on 2024-11-24 04:53:08
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_CACHE_H 0024 #define IMAP_MODEL_CACHE_H 0025 0026 #include <functional> 0027 #include <QUrl> 0028 #include "MailboxMetadata.h" 0029 #include "Imap/Parser/Message.h" 0030 #include "Imap/Parser/ThreadingNode.h" 0031 #include "Imap/Parser/Uids.h" 0032 0033 /** @short Namespace for IMAP interaction */ 0034 namespace Imap 0035 { 0036 0037 /** @short Classes for handling of mailboxes and connections */ 0038 namespace Mailbox 0039 { 0040 0041 /** @short An abstract parent for all IMAP cache implementations */ 0042 class AbstractCache 0043 { 0044 public: 0045 0046 /** @short Helper for retrieving all data about a particular message from the cache */ 0047 struct MessageDataBundle { 0048 /** @short The UID of the message */ 0049 uint uid; 0050 /** @short Envelope */ 0051 Imap::Message::Envelope envelope; 0052 /** @short The IMAP's INTERNALDATE */ 0053 QDateTime internalDate; 0054 /** @short RFC822.SIZE */ 0055 quint64 size; 0056 /** @short Serialized form of BODYSTRUCTURE 0057 0058 Due to the complex nature of BODYSTRUCTURE and the way we use, simly 0059 archiving the resulting object is far from trivial. The simplest way is 0060 offered by Imap::Message::AbstractMessage::fromList. Therefore, this item 0061 contains a QVariantList as serialized by QDataStream. 0062 */ 0063 QByteArray serializedBodyStructure; 0064 0065 /** @short Parsed form of the References RFC5322 header */ 0066 QList<QByteArray> hdrReferences; 0067 0068 /** @short The List-Post from RFC 2368 */ 0069 QList<QUrl> hdrListPost; 0070 /** @short Is the List-Post set to "NO"? */ 0071 bool hdrListPostNo; 0072 0073 MessageDataBundle(); 0074 MessageDataBundle(const uint uid, const Imap::Message::Envelope &envelope, const QDateTime &internalDate, 0075 const quint64 size, const QByteArray &serializedBodyStructure, const QList<QByteArray> &hdrReferences, 0076 const QList<QUrl> &hdrListPost, const bool hdrListPostNo); 0077 0078 bool operator==(const MessageDataBundle &other) const 0079 { 0080 return uid == other.uid && envelope == other.envelope && internalDate == other.internalDate && 0081 serializedBodyStructure == other.serializedBodyStructure && size == other.size && 0082 hdrReferences == other.hdrReferences && hdrListPost == other.hdrListPost && 0083 hdrListPostNo == other.hdrListPostNo; 0084 } 0085 }; 0086 0087 virtual ~AbstractCache(); 0088 0089 /** @short Return a list of all known child mailboxes */ 0090 virtual QList<MailboxMetadata> childMailboxes(const QString &mailbox) const = 0; 0091 /** @short Is the result of childMailboxes() fresh enough? */ 0092 virtual bool childMailboxesFresh(const QString &mailbox) const = 0; 0093 /** @short Update cache info about the state of child mailboxes */ 0094 virtual void setChildMailboxes(const QString &mailbox, const QList<MailboxMetadata> &data) = 0; 0095 0096 /** @short Return previous known state of a mailbox */ 0097 virtual SyncState mailboxSyncState(const QString &mailbox) const = 0; 0098 /** @short Set current syncing state */ 0099 virtual void setMailboxSyncState(const QString &mailbox, const SyncState &state) = 0; 0100 0101 /** @short Store the mapping of sequence numbers to UIDs */ 0102 virtual void setUidMapping(const QString &mailbox, const Imap::Uids &seqToUid) = 0; 0103 /** @short Forget the cached seq->UID mapping for given mailbox */ 0104 virtual void clearUidMapping(const QString &mailbox) = 0; 0105 /** @short Retrieve sequence to UID mapping */ 0106 virtual Imap::Uids uidMapping(const QString &mailbox) const = 0; 0107 0108 /** @short Remove all messages in given mailbox from the cache */ 0109 virtual void clearAllMessages(const QString &mailbox) = 0; 0110 /** @short Remove all info for given message in the mailbox from cache */ 0111 virtual void clearMessage(const QString mailbox, const uint uid) = 0; 0112 0113 /** @short Returns all known data for a message in the given mailbox (except real parts data) */ 0114 virtual MessageDataBundle messageMetadata(const QString &mailbox, uint uid) const = 0; 0115 virtual void setMessageMetadata(const QString &mailbox, const uint uid, const MessageDataBundle &metadata) = 0; 0116 0117 /** @short Retrieve flags for one message in a mailbox */ 0118 virtual QStringList msgFlags(const QString &mailbox, const uint uid) const = 0; 0119 /** @short Save flags for one message in mailbox */ 0120 virtual void setMsgFlags(const QString &mailbox, const uint uid, const QStringList &flags) = 0; 0121 0122 /** @short Return part data or a null QByteArray if none available */ 0123 virtual QByteArray messagePart(const QString &mailbox, const uint uid, const QByteArray &partId) const = 0; 0124 /** @short Save data for one message part */ 0125 virtual void setMsgPart(const QString &mailbox, const uint uid, const QByteArray &partId, const QByteArray &data) = 0; 0126 /** @short Drop the data for a message part which is no longer needed */ 0127 virtual void forgetMessagePart(const QString &mailbox, const uint uid, const QByteArray &partId) = 0; 0128 0129 /** @short Return cached threading info for a given mailbox */ 0130 virtual QVector<Imap::Responses::ThreadingNode> messageThreading(const QString &mailbox) = 0; 0131 /** @short Save information about how messages are threaded */ 0132 virtual void setMessageThreading(const QString &mailbox, const QVector<Imap::Responses::ThreadingNode> &threading) = 0; 0133 0134 /** @short How many days is it OK not to mark entries as accessed? */ 0135 virtual void setRenewalThreshold(const int days) = 0; 0136 0137 /** @short Inform about runtime failures */ 0138 void setErrorHandler(const std::function<void(const QString &)> &handler); 0139 0140 protected: 0141 std::function<void(const QString&)> m_errorHandler; 0142 }; 0143 0144 } 0145 0146 } 0147 0148 #endif /* IMAP_MODEL_CACHE_H */