From 915906de671c49d921e976bd9f53ef8982d96e2c Mon Sep 17 00:00:00 2001 From: Till Adam Date: Wed, 29 Dec 2004 15:13:16 +0000 Subject: [PATCH] Do status searches in imap folders on the index, without downloading all the mails. The info is only to be found in the index anyhow. svn path=/trunk/kdepim/; revision=374018 --- searchjob.cpp | 70 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/searchjob.cpp b/searchjob.cpp index 4d1dfa723..61a831fb1 100644 --- a/searchjob.cpp +++ b/searchjob.cpp @@ -178,49 +178,63 @@ void SearchJob::slotSearchFolderComplete() disconnect ( mFolder, SIGNAL( folderComplete( KMFolderImap*, bool ) ), this, SLOT( slotSearchFolderComplete()) ); - if ( mLocalSearchPattern->isEmpty() ) - { + if ( mLocalSearchPattern->isEmpty() ) { // search for the serial number of the UIDs // data contains all found uids separated by blank QValueList serNums; QStringList searchHits = QStringList::split( " ", mImapSearchData ); - for ( int i = 0; i < mFolder->count(); ++i ) - { + for ( int i = 0; i < mFolder->count(); ++i ) { KMMsgBase * base = mFolder->getMsgBase( i ); - if ( searchHits.contains( QString::number( base->UID() ) ) ) - { + if ( searchHits.contains( QString::number( base->UID() ) ) ) { Q_UINT32 serNum = kmkernel->msgDict()->getMsgSerNum( mFolder->folder(), i ); serNums.append( serNum ); } } emit searchDone( serNums, mSearchPattern ); - } else - { + } else { // we have search patterns that can not be handled by the server - // so we need to download all messages and check - QString question = i18n("To execute your search all messages of the folder %1 " - "have to be downloaded from the server. This may take some time. " - "Do you want to continue your search?").arg( mFolder->label() ); - if ( KMessageBox::warningContinueCancel( 0, question, - i18n("Continue Search"), i18n("&Search"), - "continuedownloadingforsearch" ) != KMessageBox::Continue ) - { - QValueList serNums; - emit searchDone( serNums, mSearchPattern ); + mRemainingMsgs = mFolder->count(); + if ( mRemainingMsgs == 0 ) { + emit searchDone( mSearchSerNums, mSearchPattern ); return; } - mRemainingMsgs = mFolder->count(); - for ( int i = 0; i < mFolder->count(); ++i ) - { + + // Let's see if all we need is status, that we can do locally. Optimization. + bool needToDownload = false; + for ( QPtrListIterator it( *mLocalSearchPattern ) ; it.current() ; ++it ) { + if ( (*it)->field() != "" ) { + needToDownload = true; + break; + } + } + + if ( needToDownload ) { + // so we need to download all messages and check + QString question = i18n("To execute your search all messages of the folder %1 " + "have to be downloaded from the server. This may take some time. " + "Do you want to continue your search?").arg( mFolder->label() ); + if ( KMessageBox::warningContinueCancel( 0, question, + i18n("Continue Search"), i18n("&Search"), + "continuedownloadingforsearch" ) != KMessageBox::Continue ) + { + QValueList serNums; + emit searchDone( serNums, mSearchPattern ); + return; + } + } + unsigned int numMsgs = mRemainingMsgs; + for ( unsigned int i = 0; i < numMsgs ; ++i ) { KMMessage * msg = mFolder->getMsg( i ); - ImapJob *job = new ImapJob( msg ); - job->setParentFolder( mFolder ); - connect( job, SIGNAL(messageRetrieved(KMMessage*)), - this, SLOT(slotSearchMessageArrived(KMMessage*)) ); - job->start(); + if ( needToDownload ) { + ImapJob *job = new ImapJob( msg ); + job->setParentFolder( mFolder ); + connect( job, SIGNAL(messageRetrieved(KMMessage*)), + this, SLOT(slotSearchMessageArrived(KMMessage*)) ); + job->start(); + } else { + slotSearchMessageArrived( msg ); + } } - if ( mRemainingMsgs == 0 ) - emit searchDone( mSearchSerNums, mSearchPattern ); } }