File indexing completed on 2025-02-16 04:59:01
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 "CombinedCache.h" 0024 #include "DiskPartCache.h" 0025 #include "SQLCache.h" 0026 0027 namespace Imap 0028 { 0029 namespace Mailbox 0030 { 0031 0032 CombinedCache::CombinedCache(const QString &name, const QString &cacheDir) 0033 : name(name) 0034 , cacheDir(cacheDir) 0035 , sqlCache(new SQLCache()) 0036 , diskPartCache(new DiskPartCache(cacheDir)) 0037 { 0038 sqlCache->setErrorHandler([this](const QString &e) { this->m_errorHandler(e); }); 0039 diskPartCache->setErrorHandler([this](const QString &e) { this->m_errorHandler(e); }); 0040 } 0041 0042 CombinedCache::~CombinedCache() 0043 { 0044 } 0045 0046 bool CombinedCache::open() 0047 { 0048 return sqlCache->open(name, cacheDir + QLatin1String("/imap.cache.sqlite")); 0049 } 0050 0051 QList<MailboxMetadata> CombinedCache::childMailboxes(const QString &mailbox) const 0052 { 0053 return sqlCache->childMailboxes(mailbox); 0054 } 0055 0056 bool CombinedCache::childMailboxesFresh(const QString &mailbox) const 0057 { 0058 return sqlCache->childMailboxesFresh(mailbox); 0059 } 0060 0061 void CombinedCache::setChildMailboxes(const QString &mailbox, const QList<MailboxMetadata> &data) 0062 { 0063 sqlCache->setChildMailboxes(mailbox, data); 0064 } 0065 0066 SyncState CombinedCache::mailboxSyncState(const QString &mailbox) const 0067 { 0068 return sqlCache->mailboxSyncState(mailbox); 0069 } 0070 0071 void CombinedCache::setMailboxSyncState(const QString &mailbox, const SyncState &state) 0072 { 0073 sqlCache->setMailboxSyncState(mailbox, state); 0074 } 0075 0076 Imap::Uids CombinedCache::uidMapping(const QString &mailbox) const 0077 { 0078 return sqlCache->uidMapping(mailbox); 0079 } 0080 0081 void CombinedCache::setUidMapping(const QString &mailbox, const Imap::Uids &seqToUid) 0082 { 0083 sqlCache->setUidMapping(mailbox, seqToUid); 0084 } 0085 0086 void CombinedCache::clearUidMapping(const QString &mailbox) 0087 { 0088 sqlCache->clearUidMapping(mailbox); 0089 } 0090 0091 void CombinedCache::clearAllMessages(const QString &mailbox) 0092 { 0093 sqlCache->clearAllMessages(mailbox); 0094 diskPartCache->clearAllMessages(mailbox); 0095 } 0096 0097 void CombinedCache::clearMessage(const QString mailbox, const uint uid) 0098 { 0099 sqlCache->clearMessage(mailbox, uid); 0100 diskPartCache->clearMessage(mailbox, uid); 0101 } 0102 0103 QStringList CombinedCache::msgFlags(const QString &mailbox, const uint uid) const 0104 { 0105 return sqlCache->msgFlags(mailbox, uid); 0106 } 0107 0108 void CombinedCache::setMsgFlags(const QString &mailbox, const uint uid, const QStringList &flags) 0109 { 0110 sqlCache->setMsgFlags(mailbox, uid, flags); 0111 } 0112 0113 AbstractCache::MessageDataBundle CombinedCache::messageMetadata(const QString &mailbox, const uint uid) const 0114 { 0115 return sqlCache->messageMetadata(mailbox, uid); 0116 } 0117 0118 void CombinedCache::setMessageMetadata(const QString &mailbox, const uint uid, const MessageDataBundle &metadata) 0119 { 0120 sqlCache->setMessageMetadata(mailbox, uid, metadata); 0121 } 0122 0123 QByteArray CombinedCache::messagePart(const QString &mailbox, const uint uid, const QByteArray &partId) const 0124 { 0125 QByteArray res = sqlCache->messagePart(mailbox, uid, partId); 0126 if (res.isEmpty()) { 0127 res = diskPartCache->messagePart(mailbox, uid, partId); 0128 } 0129 return res; 0130 } 0131 0132 void CombinedCache::setMsgPart(const QString &mailbox, const uint uid, const QByteArray &partId, const QByteArray &data) 0133 { 0134 if (data.size() < 1024 * 1024) { 0135 sqlCache->setMsgPart(mailbox, uid, partId, data); 0136 } else { 0137 diskPartCache->setMsgPart(mailbox, uid, partId, data); 0138 } 0139 } 0140 0141 void CombinedCache::forgetMessagePart(const QString &mailbox, const uint uid, const QByteArray &partId) 0142 { 0143 sqlCache->forgetMessagePart(mailbox, uid, partId); 0144 diskPartCache->forgetMessagePart(mailbox, uid, partId); 0145 } 0146 0147 QVector<Imap::Responses::ThreadingNode> CombinedCache::messageThreading(const QString &mailbox) 0148 { 0149 return sqlCache->messageThreading(mailbox); 0150 } 0151 0152 void CombinedCache::setMessageThreading(const QString &mailbox, const QVector<Imap::Responses::ThreadingNode> &threading) 0153 { 0154 sqlCache->setMessageThreading(mailbox, threading); 0155 } 0156 0157 void CombinedCache::setRenewalThreshold(const int days) 0158 { 0159 sqlCache->setRenewalThreshold(days); 0160 } 0161 0162 } 0163 }