From ffacfdcc9e09b7bd39911c87898b4a6e57f9a7bb Mon Sep 17 00:00:00 2001 From: Bo Thorsen Date: Sat, 4 Jan 2003 16:10:38 +0000 Subject: [PATCH] Add automatic resource handling and imap folder invalidation svn path=/trunk/kdenetwork/kmail/; revision=197420 --- kmaccount.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ kmaccount.h | 22 +++++++++++ kmacctmgr.cpp | 20 ++++++++++ kmacctmgr.h | 4 ++ 4 files changed, 147 insertions(+) diff --git a/kmaccount.cpp b/kmaccount.cpp index cb4348ef4..54e48ea73 100644 --- a/kmaccount.cpp +++ b/kmaccount.cpp @@ -75,6 +75,7 @@ KMAccount::KMAccount(KMAcctMgr* aOwner, const QString& aName) mFolder(0), mTimer(0), mInterval(0), + mResource(false), mExclude(false), mCheckingMail(false), mPrecommandSuccess(true) @@ -86,6 +87,7 @@ KMAccount::KMAccount(KMAcctMgr* aOwner, const QString& aName) void KMAccount::init() { mTrash = kernel->trashFolder()->idString(); + mResource = false; mExclude = false; mInterval = 0; } @@ -134,6 +136,7 @@ void KMAccount::readConfig(KConfig& config) folderName = config.readEntry("Folder", ""); setCheckInterval(config.readNumEntry("check-interval", 0)); setTrash(config.readEntry("trash", kernel->trashFolder()->idString())); + setResource(config.readBoolEntry("resource", false) ); setCheckExclude(config.readBoolEntry("check-exclude", false)); setPrecommand(config.readEntry("precommand")); @@ -141,6 +144,16 @@ void KMAccount::readConfig(KConfig& config) { setFolder(kernel->folderMgr()->findIdString(folderName), true); } + + if( mResource ) { + int numResourceEntries = config.readNumEntry( "numResourceEntries", 0 ); + int count = 0; + for( int i = 0; i < numResourceEntries; i++, count++ ) { + QDateTime start = config.readDateTimeEntry( QString( "resource%1-start" ).arg( i ) ); + QDateTime end = config.readDateTimeEntry( QString( "resource%1-end" ).arg( i ) ); + mIntervals.append( qMakePair(start,end) ); + } + } } @@ -151,9 +164,22 @@ void KMAccount::writeConfig(KConfig& config) config.writeEntry("Name", mName); config.writeEntry("Folder", mFolder ? mFolder->idString() : QString::null); config.writeEntry("check-interval", mInterval); + config.writeEntry("resource", mResource); config.writeEntry("check-exclude", mExclude); config.writeEntry("precommand", mPrecommand); config.writeEntry("trash", mTrash); + + // Write the resource management data + if( mResource ) { + config.writeEntry("numResourceEntries", mIntervals.count() ); + int count = 0; + for( QValueList >::Iterator it = mIntervals.begin(); it != mIntervals.end(); ++it, count++ ) { + config.writeEntry( QString( "resource%1-start" ).arg( count ), + (*it).first ); + config.writeEntry( QString( "resource%1-end" ).arg( count ), + (*it).second ); + } + } } @@ -202,6 +228,16 @@ if( fileD0.open( IO_WriteOnly ) ) { } */ // 0==message moved; 1==processing ok, no move; 2==critical error, abort! + + // Automatic resource handling: Give the Groupware code a chance to + // answer this message automatically, but only if this is a resource + // account. + if( resource() ) { + if( kernel->groupware().incomingResourceMessage( this, aMsg ) ) + // If it was a resource message, we have already answered it. + aMsg->setStatus( KMMsgStatusReplied ); + } + processResult = kernel->filterMgr()->process(aMsg,KMFilterMgr::Inbound); if (processResult == 2) { perror("Critical error: Unable to collect mail (out of space?)"); @@ -278,6 +314,13 @@ void KMAccount::setCheckExclude(bool aExclude) } +//----------------------------------------------------------------------------- +void KMAccount::setResource(bool aResource) +{ + mResource = aResource; +} + + //----------------------------------------------------------------------------- void KMAccount::installTimer() { @@ -384,11 +427,69 @@ QString KMAccount::importPassword(const QString &aStr) return encryptStr(result); } + +/*! + Registers a new allocated interval in which the resource represented + by this account is busy. +*/ + +void KMAccount::addInterval( const QPair& iv ) +{ + mIntervals.append( iv ); +} + + +/*! + Returns the intervals in which this resource is busy +*/ +QValueList > KMAccount::intervals() const +{ + return mIntervals; +} + + +/*! + Resets all intervals in which this resource is busy. +*/ + +void KMAccount::clearIntervals() +{ + mIntervals.clear(); +} + + +/*! + Resets all intervals in which this resource is busy and which are + entirely in the past. +*/ +void KMAccount::clearOldIntervals() +{ + QDateTime now = QDateTime::currentDateTime(); + for( QValueList >::iterator it = mIntervals.begin(); it != mIntervals.end(); ++it ) { + if( (*it).second < now ) + mIntervals.erase( it ); + } +} + + +void KMAccount::setIntervals( const QValueList >& newIntervals ) +{ + mIntervals = newIntervals; +} + + +void KMAccount::invalidateIMAPFolders() +{ + // Default: Don't do anything. The IMAP account will handle it +} + void KMAccount::pseudoAssign( const KMAccount * a ) { if ( !a ) return; setName( a->name() ); setCheckInterval( a->checkInterval() ); + setResource( a->resource() ); + setIntervals( a->intervals() ); setCheckExclude( a->checkExclude() ); setFolder( a->folder() ); setPrecommand( a->precommand() ); diff --git a/kmaccount.h b/kmaccount.h index 876ab595d..913698b50 100644 --- a/kmaccount.h +++ b/kmaccount.h @@ -144,6 +144,12 @@ public: virtual void setCheckExclude(bool aExclude); bool checkExclude(void) const { return mExclude; } + /** + * Set/get whether the account is for a semi-automatically managed resource. + */ + virtual void setResource(bool aResource); + bool resource(void) const { return mResource; } + /** * Pre command */ @@ -167,6 +173,18 @@ public: static QString importPassword(const QString &); + /** + * If this account is a disconnected IMAP account, invalidate it. + */ + virtual void invalidateIMAPFolders(); + + // stuff for resource-handling + void addInterval( const QPair& ); + QValueList > intervals() const; + void clearIntervals(); + void clearOldIntervals(); + void setIntervals( const QValueList >& ); + signals: virtual void finishedCheck(bool newMail); virtual void newMailsProcessed(int numberOfNewMails); @@ -208,12 +226,16 @@ protected: QGuardedPtr mFolder; QTimer *mTimer, mReceiptTimer; int mInterval; + bool mResource; bool mExclude; bool mCheckingMail; bool mPrecommandSuccess; QValueList mReceipts; QPtrList mJobList; + // for resource handling + QValueList > mIntervals; + private: /** * avoid compiler warning about hidden virtual diff --git a/kmacctmgr.cpp b/kmacctmgr.cpp index 292ba237c..6c0a55d56 100644 --- a/kmacctmgr.cpp +++ b/kmacctmgr.cpp @@ -292,6 +292,26 @@ void KMAcctMgr::checkMail(bool _interactive) } +//----------------------------------------------------------------------------- +void KMAcctMgr::singleInvalidateIMAPFolders(KMAccount *account) { + account->invalidateIMAPFolders(); +} + + +void KMAcctMgr::invalidateIMAPFolders() +{ + if (mAcctList.isEmpty()) { + KMessageBox::information(0,i18n("You need to add an account in the network " + "section of the settings in order to " + "receive mail.")); + return; + } + + for ( QPtrListIterator it(mAcctList) ; it.current() ; ++it ) + singleInvalidateIMAPFolders(it.current()); +} + + //----------------------------------------------------------------------------- QStringList KMAcctMgr::getAccounts(bool noImap) { diff --git a/kmacctmgr.h b/kmacctmgr.h index 6cf9b334f..6c41dc49c 100644 --- a/kmacctmgr.h +++ b/kmacctmgr.h @@ -54,10 +54,14 @@ public: /** Processes all accounts looking for new mail */ virtual void checkMail(bool _interactive = true); + /** Delete all IMAP folders and resync them */ + void invalidateIMAPFolders(); + QStringList getAccounts(bool noImap = false); public slots: virtual void singleCheckMail(KMAccount *, bool _interactive = true); + virtual void singleInvalidateIMAPFolders(KMAccount *); virtual void intCheckMail(int, bool _interactive = true); virtual void processNextCheck(bool _newMail);