Add automatic resource handling and imap folder invalidation

svn path=/trunk/kdenetwork/kmail/; revision=197420
wilder-work
Bo Thorsen 24 years ago
parent 4adb85f340
commit ffacfdcc9e
  1. 101
      kmaccount.cpp
  2. 22
      kmaccount.h
  3. 20
      kmacctmgr.cpp
  4. 4
      kmacctmgr.h

@ -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<QPair< QDateTime, QDateTime> >::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<QDateTime,QDateTime>& iv )
{
mIntervals.append( iv );
}
/*!
Returns the intervals in which this resource is busy
*/
QValueList<QPair<QDateTime, QDateTime> > 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<QPair<QDateTime, QDateTime> >::iterator it = mIntervals.begin(); it != mIntervals.end(); ++it ) {
if( (*it).second < now )
mIntervals.erase( it );
}
}
void KMAccount::setIntervals( const QValueList<QPair<QDateTime, QDateTime> >& 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() );

@ -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<QDateTime,QDateTime>& );
QValueList<QPair<QDateTime, QDateTime> > intervals() const;
void clearIntervals();
void clearOldIntervals();
void setIntervals( const QValueList<QPair<QDateTime, QDateTime> >& );
signals:
virtual void finishedCheck(bool newMail);
virtual void newMailsProcessed(int numberOfNewMails);
@ -208,12 +226,16 @@ protected:
QGuardedPtr<KMAcctFolder> mFolder;
QTimer *mTimer, mReceiptTimer;
int mInterval;
bool mResource;
bool mExclude;
bool mCheckingMail;
bool mPrecommandSuccess;
QValueList<KMMessage*> mReceipts;
QPtrList<KMFolderJob> mJobList;
// for resource handling
QValueList<QPair<QDateTime, QDateTime> > mIntervals;
private:
/**
* avoid compiler warning about hidden virtual

@ -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<KMAccount> it(mAcctList) ; it.current() ; ++it )
singleInvalidateIMAPFolders(it.current());
}
//-----------------------------------------------------------------------------
QStringList KMAcctMgr::getAccounts(bool noImap) {

@ -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);

Loading…
Cancel
Save