From 9ff395049f3b9b58f59e47e463a62ec3907b1f53 Mon Sep 17 00:00:00 2001 From: Michael Haeckel Date: Sat, 5 Jan 2002 19:57:21 +0000 Subject: [PATCH] Better support for read only folders. The locally stored messages status is no longer overwritten by the flags on the server and checking for new mails only reports the really new mails. svn path=/trunk/kdenetwork/kmail/; revision=130054 --- kmfolder.cpp | 3 +++ kmfolder.h | 2 +- kmfolderimap.cpp | 44 +++++++++++++++++++++++++++++++++----------- kmfolderimap.h | 1 + 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/kmfolder.cpp b/kmfolder.cpp index 5c212fd8c..45a6cf6a6 100644 --- a/kmfolder.cpp +++ b/kmfolder.cpp @@ -74,6 +74,7 @@ KMFolder :: KMFolder(KMFolderDir* aParent, const QString& aName) : mAcctList = NULL; mDirty = FALSE; mUnreadMsgs = -1; + mGuessedUnreadMsgs = -1; needsCompact = FALSE; mChild = 0; mConvertToUtf8 = FALSE; @@ -1050,6 +1051,8 @@ QString KMFolder::label() const //----------------------------------------------------------------------------- int KMFolder::countUnread() { + if (mGuessedUnreadMsgs > -1) + return mGuessedUnreadMsgs; if (mUnreadMsgs > -1) return mUnreadMsgs; diff --git a/kmfolder.h b/kmfolder.h index 38ff56a39..d169c624a 100644 --- a/kmfolder.h +++ b/kmfolder.h @@ -528,7 +528,7 @@ protected: QString mIdentity; /** number of unread messages, -1 if not yet set */ - int mUnreadMsgs; + int mUnreadMsgs, mGuessedUnreadMsgs; bool mWriteConfigEnabled; /** sven: true if on destruct folder needs to be compacted. */ bool needsCompact; diff --git a/kmfolderimap.cpp b/kmfolderimap.cpp index 15d2408ca..e27214048 100644 --- a/kmfolderimap.cpp +++ b/kmfolderimap.cpp @@ -54,6 +54,7 @@ KMFolderImap::KMFolderImap(KMFolderDir* aParent, const QString& aName) mLabel = i18n("inbox"); } mNoContent = config->readBoolEntry("NoContent", FALSE); + mReadOnly = config->readBoolEntry("ReadOnly", FALSE); } KMFolderImap::~KMFolderImap() @@ -63,6 +64,7 @@ KMFolderImap::~KMFolderImap() config->writeEntry("UidValidity", mUidValidity); config->writeEntry("ImapPath", mImapPath); config->writeEntry("NoContent", mNoContent); + config->writeEntry("ReadOnly", mReadOnly); if (kernel->undoStack()) kernel->undoStack()->folderDestroyed(this); } @@ -541,11 +543,15 @@ kdDebug(5006) << "KMFolderImap::checkValidity" << endl; ulong KMFolderImap::lastUid() { if (mLastUid) return mLastUid; - if (count() < 1) return 0; - bool unget = !isMessage(count() - 1); - KMMessage *msg = getMsg(count() - 1); - mLastUid = msg->headerField("X-UID").toULong(); - if (unget) unGetMsg(count() - 1); + open(); + if (count() > 0) + { + bool unget = !isMessage(count() - 1); + KMMessage *msg = getMsg(count() - 1); + mLastUid = msg->headerField("X-UID").toULong(); + if (unget) unGetMsg(count() - 1); + } + close(); return mLastUid; } @@ -567,9 +573,14 @@ kdDebug(5006) << "KMFolderImap::slotCheckValidityResult" << endl; } else { QCString cstr((*it).data.data(), (*it).data.size() + 1); int a = cstr.find("X-uidValidity: "); - int b = cstr.find("\r\n", a); - QString uidv; - if ( (b - a - 15) >= 0 ) uidv = cstr.mid(a + 15, b - a - 15); + int b = cstr.find("\r\n", a); + QString uidv; + if ( (b - a - 15) >= 0 ) uidv = cstr.mid(a + 15, b - a - 15); + a = cstr.find("X-Access: "); + b = cstr.find("\r\n", a); + QString access; + if ( (b - a - 10) >= 0 ) access = cstr.mid(a + 10, b - a - 10); + mReadOnly = access == "Read only"; QString startUid; if (uidValidity() != uidv) { @@ -587,6 +598,7 @@ kdDebug(5006) << "KMFolderImap::slotCheckValidityResult" << endl; //----------------------------------------------------------------------------- void KMFolderImap::getFolder() { + mGuessedUnreadMsgs = -1; if (mNoContent) return; mImapState = imapInProgress; checkValidity(); @@ -673,7 +685,8 @@ void KMFolderImap::slotListFolderResult(KIO::Job * job) if (mailUid < serverUid) removeMsg(idx, TRUE); else if (mailUid == serverUid) { - getMsgBase(idx)->setStatus(flagsToStatus(serverFlags, false)); + if (!mReadOnly) + getMsgBase(idx)->setStatus(flagsToStatus(serverFlags, false)); idx++; uid = (*it).items.remove(uid); } @@ -1422,7 +1435,10 @@ void KMFolderImap::slotSetStatusResult(KIO::Job * job) void KMFolderImap::processNewMail(bool) { KURL url = mAccount->getUrl(); - url.setPath(imapPath() + ";SECTION=UNSEEN"); + if (mReadOnly) + url.setPath(imapPath() + ";SECTION=UIDNEXT"); + else + url.setPath(imapPath() + ";SECTION=UNSEEN"); if (!mAccount->makeConnection()) return; KIO::SimpleJob *job = KIO::stat(url, FALSE); KIO::Scheduler::assignJobToSlave(mAccount->slave(), job); @@ -1452,7 +1468,13 @@ void KMFolderImap::slotStatResult(KIO::Job * job) { if ((*it).m_uds == KIO::UDS_SIZE) { - mUnreadMsgs = (*it).m_long; + if (mReadOnly) + { + mGuessedUnreadMsgs = countUnread() + (*it).m_long - lastUid() - 1; + if (mGuessedUnreadMsgs < 0) mGuessedUnreadMsgs = 0; + } else { + mGuessedUnreadMsgs = (*it).m_long; + } emit numUnreadMsgsChanged( this ); } } diff --git a/kmfolderimap.h b/kmfolderimap.h index 5c2a5d6b1..64c1ff28d 100644 --- a/kmfolderimap.h +++ b/kmfolderimap.h @@ -316,6 +316,7 @@ protected: bool mHasInbox; bool mIsSelected; bool mCheckFlags; + bool mReadOnly; QGuardedPtr mAccount; };