23 #include "kmfoldersearch.h"
24 #include "kmfolderimap.h"
25 #include "kmfoldermgr.h"
26 #include "kmsearchpattern.h"
27 #include "kmmsgdict.h"
29 #include "jobscheduler.h"
32 #include <tdelocale.h>
33 #include <tdeconfig.h>
40 #include <sys/types.h>
47 #ifdef HAVE_BYTESWAP_H
57 #define kmail_swap_32(x) bswap_32(x)
59 #define kmail_swap_32(x) \
60 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
61 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
66 #define IDS_SEARCH_VERSION 1000
68 #define IDS_SEARCH_HEADER "# KMail-Search-IDs V%d\n*"
69 #define IDS_SEARCH_HEADER_LEN 30
72 KMSearch::KMSearch(TQObject * parent,
const char * name)
73 :TQObject(parent, name)
75 mRemainingFolders = -1;
77 mRunByIndex = mRunning =
false;
83 mProcessNextBatchTimer =
new TQTimer(0,
"mProcessNextBatchTimer");
84 connect(mProcessNextBatchTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotProcessNextBatch()));
89 delete mProcessNextBatchTimer;
90 delete mSearchPattern;
93 bool KMSearch::write(TQString location)
const
95 TDEConfig config(location);
96 config.setGroup(
"Search Folder");
98 mSearchPattern->writeConfig(&config);
100 config.writeEntry(
"Base",
"");
102 config.writeEntry(
"Base", mRoot->idString());
103 config.writeEntry(
"Recursive", recursive());
107 bool KMSearch::read(TQString location)
109 TDEConfig config( location );
110 config.setGroup(
"Search Folder" );
111 if ( !mSearchPattern )
113 mSearchPattern->readConfig( &config );
114 TQString rootString = config.readEntry(
"Base" );
115 mRoot = kmkernel->findFolderById( rootString );
116 mRecursive = config.readBoolEntry(
"Recursive" );
124 if ( mSearchPattern != searchPattern ) {
125 delete mSearchPattern;
126 mSearchPattern = searchPattern;
130 bool KMSearch::inScope(
KMFolder* folder)
const
132 if ( mRoot.isNull() || folder == mRoot )
139 while ( ancestorDir ) {
140 if ( ancestorDir == rootDir )
142 ancestorDir = ancestorDir->parent();
147 void KMSearch::start()
150 TQValueListIterator<TQGuardedPtr<KMFolder> > fit;
151 for (fit = mOpenedFolders.begin(); fit != mOpenedFolders.end(); ++fit) {
154 (*fit)->close(
"kmsearch" );
156 mOpenedFolders.clear();
162 if ( !mSearchPattern ) {
172 if ( kmkernel->msgIndex() && kmkernel->msgIndex()->startQuery(
this ) ) {
177 mFolders.append( mRoot );
183 TQValueListConstIterator<TQGuardedPtr<KMFolder> > it;
184 for ( it = mFolders.begin(); it != mFolders.end(); ++it )
189 dir = folder->
child();
191 dir = &kmkernel->folderMgr()->dir();
194 TQPtrListIterator<KMFolderNode> it(*dir);
195 while ( (node = it.current()) ) {
197 if ( !node->isDir() ) {
200 mFolders.append( kmf );
206 mRemainingFolders = mFolders.
count();
207 mLastFolder = TQString();
208 mProcessNextBatchTimer->start( 0,
true );
211 void KMSearch::stop()
216 if ( kmkernel->msgIndex() )
217 kmkernel->msgIndex()->stopQuery(
this );
219 mIncompleteFolders.clear();
220 TQValueListConstIterator<TQGuardedPtr<KMFolder> > jt;
221 for ( jt = mOpenedFolders.begin(); jt != mOpenedFolders.end(); ++jt ) {
227 if ( folder->
folderType() == KMFolderTypeImap ) {
228 KMAcctImap *account =
229 static_cast<KMFolderImap*
>( folder->storage() )->account();
230 account->ignoreJobsForFolder( folder );
232 folder->storage()->
search( 0 );
233 mSearchCount += folder->
count();
234 folder->
close(
"kmsearch");
237 mRemainingFolders = -1;
238 mOpenedFolders.clear();
240 mLastFolder = TQString();
241 mRunByIndex = mRunning =
false;
242 emit finished(
false);
245 void KMSearch::indexFinished() {
250 void KMSearch::slotProcessNextBatch()
255 if ( mFolders.count() != 0 )
257 KMFolder *folder = *( mFolders.begin() );
258 mFolders.erase( mFolders.begin() );
261 mLastFolder = folder->
label();
262 folder->
open(
"kmsearch");
263 mOpenedFolders.append( folder );
264 connect( folder->storage(),
268 folder->storage()->
search( mSearchPattern );
271 mProcessNextBatchTimer->start( 0,
true );
276 void KMSearch::slotSearchFolderResult(
KMFolder* folder,
277 TQValueList<TQ_UINT32> serNums,
281 if ( pattern != mSearchPattern )
283 kdDebug(5006) << k_funcinfo << folder->
label() <<
" found " << serNums.count() << endl;
284 mLastFolder = folder->
label();
285 TQValueListIterator<TQ_UINT32> it;
286 for ( it = serNums.begin(); it != serNums.end(); ++it )
293 disconnect( folder->storage(),
294 TQ_SIGNAL( searchResult(
KMFolder*, TQValueList<TQ_UINT32>,
297 TQ_SLOT( slotSearchFolderResult(
KMFolder*, TQValueList<TQ_UINT32>,
300 mSearchCount += folder->
count();
301 folder->
close(
"kmsearch");
302 mOpenedFolders.remove( folder );
303 if ( mRemainingFolders <= 0 )
305 mRemainingFolders = 0;
307 mLastFolder = TQString();
308 mRemainingFolders = -1;
310 emit finished(
true );
316 KMFolderSearch::KMFolderSearch(
KMFolder* folder,
const char* name)
328 connect(kmkernel->folderMgr(), TQ_SIGNAL(msgAdded(
KMFolder*, TQ_UINT32)),
329 this, TQ_SLOT(examineAddedMessage(
KMFolder*, TQ_UINT32)));
330 connect(kmkernel->folderMgr(), TQ_SIGNAL(msgRemoved(
KMFolder*, TQ_UINT32)),
331 this, TQ_SLOT(examineRemovedMessage(
KMFolder*, TQ_UINT32)));
332 connect(kmkernel->folderMgr(), TQ_SIGNAL(msgChanged(
KMFolder*, TQ_UINT32,
int)),
333 this, TQ_SLOT(examineChangedMessage(
KMFolder*, TQ_UINT32,
int)));
334 connect(kmkernel->folderMgr(), TQ_SIGNAL(folderInvalidated(
KMFolder*)),
335 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
336 connect(kmkernel->folderMgr(), TQ_SIGNAL(folderAdded(
KMFolder*)),
337 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
338 connect(kmkernel->folderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
339 this, TQ_SLOT(examineRemovedFolder(
KMFolder*)));
340 connect(kmkernel->folderMgr(), TQ_SIGNAL(msgHeaderChanged(
KMFolder*,
int)),
341 this, TQ_SLOT(propagateHeaderChanged(
KMFolder*,
int)));
343 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(msgAdded(
KMFolder*, TQ_UINT32)),
344 this, TQ_SLOT(examineAddedMessage(
KMFolder*, TQ_UINT32)));
345 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(msgRemoved(
KMFolder*, TQ_UINT32)),
346 this, TQ_SLOT(examineRemovedMessage(
KMFolder*, TQ_UINT32)));
347 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(msgChanged(
KMFolder*, TQ_UINT32,
int)),
348 this, TQ_SLOT(examineChangedMessage(
KMFolder*, TQ_UINT32,
int)));
349 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(folderInvalidated(
KMFolder*)),
350 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
351 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(folderAdded(
KMFolder*)),
352 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
353 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
354 this, TQ_SLOT(examineRemovedFolder(
KMFolder*)));
355 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(msgHeaderChanged(
KMFolder*,
int)),
356 this, TQ_SLOT(propagateHeaderChanged(
KMFolder*,
int)));
358 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(msgAdded(
KMFolder*, TQ_UINT32)),
359 this, TQ_SLOT(examineAddedMessage(
KMFolder*, TQ_UINT32)));
360 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(msgRemoved(
KMFolder*, TQ_UINT32)),
361 this, TQ_SLOT(examineRemovedMessage(
KMFolder*, TQ_UINT32)));
362 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(msgChanged(
KMFolder*, TQ_UINT32,
int)),
363 this, TQ_SLOT(examineChangedMessage(
KMFolder*, TQ_UINT32,
int)));
364 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(folderInvalidated(
KMFolder*)),
365 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
366 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(folderAdded(
KMFolder*)),
367 this, TQ_SLOT(examineInvalidatedFolder(
KMFolder*)));
368 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
369 this, TQ_SLOT(examineRemovedFolder(
KMFolder*)));
370 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(msgHeaderChanged(
KMFolder*,
int)),
371 this, TQ_SLOT(propagateHeaderChanged(
KMFolder*,
int)));
373 mExecuteSearchTimer =
new TQTimer(0,
"mExecuteSearchTimer");
374 connect(mExecuteSearchTimer, TQ_SIGNAL(timeout()),
375 this, TQ_SLOT(executeSearch()));
378 KMFolderSearch::~KMFolderSearch()
380 delete mExecuteSearchTimer;
384 close(
"~foldersearch", TRUE);
387 void KMFolderSearch::setSearch(KMSearch *search)
394 unlink(TQFile::encodeName(indexLocation()));
397 if (mSearch != search) {
402 TQObject::connect(search, TQ_SIGNAL(found(TQ_UINT32)),
403 TQ_SLOT(addSerNum(TQ_UINT32)));
404 TQObject::connect(search, TQ_SIGNAL(finished(
bool)),
405 TQ_SLOT(searchFinished(
bool)));
409 mSearch->write(location());
413 emit numUnreadMsgsChanged( folder() );
418 open(
"foldersearch");
421 void KMFolderSearch::executeSearch()
434 void KMFolderSearch::searchFinished(
bool success)
438 close(
"foldersearch");
441 void KMFolderSearch::addSerNum(TQ_UINT32 serNum)
450 if (!aFolder || (idx == -1)) {
451 kdDebug(5006) <<
"Not adding message with serNum " << serNum
452 <<
": folder is " << aFolder <<
", index is " << idx << endl;
455 if(mFolders.findIndex(aFolder) == -1) {
456 aFolder->
open(
"foldersearch");
457 mFolders.append(aFolder);
461 unlink(TQFile::encodeName(indexLocation()));
464 mSerNums.append(serNum);
466 if (mb && (mb->isUnread() || mb->isNew())) {
467 if (mUnreadMsgs == -1)
470 emit numUnreadMsgsChanged( folder() );
472 emitMsgAddedSignals(mSerNums.count()-1);
475 void KMFolderSearch::removeSerNum(TQ_UINT32 serNum)
477 TQValueVector<TQ_UINT32>::const_iterator it;
479 for(it = mSerNums.begin(); it != mSerNums.end(); ++it, ++i)
480 if ((*it) == serNum) {
484 assert(aFolder && (idx != -1));
485 emit msgRemoved(folder(), serNum);
490 unlink(TQFile::encodeName(indexLocation()));
502 bool KMFolderSearch::readSearch()
504 mSearch =
new KMSearch;
505 TQObject::connect(mSearch, TQ_SIGNAL(found(TQ_UINT32)), TQ_SLOT(addSerNum(TQ_UINT32)));
506 TQObject::connect(mSearch, TQ_SIGNAL(finished(
bool)), TQ_SLOT(searchFinished(
bool)));
507 return mSearch->read(location());
510 int KMFolderSearch::open(
const char *)
513 kmkernel->jobScheduler()->notifyOpeningFolder( folder() );
518 if (!mSearch && !readSearch())
522 if (!mSearch || !search()->running())
530 int KMFolderSearch::canAccess()
532 assert(!folder()->name().isEmpty());
534 if (access(TQFile::encodeName(location()), R_OK | W_OK | X_OK) != 0)
539 void KMFolderSearch::sync()
543 mSearch->write(location());
548 void KMFolderSearch::reallyDoClose(
const char* owner)
551 if (mAutoCreateIndex) {
553 mSearch->write(location());
555 if (mSearch && search()->running())
561 TQValueListIterator<TQGuardedPtr<KMFolder> > fit;
562 for (fit = mFolders.begin(); fit != mFolders.end(); ++fit) {
565 (*fit)->close(
"foldersearch");
579 int KMFolderSearch::create()
582 int rc = unlink(TQFile::encodeName(location()));
587 assert(!folder()->name().isEmpty());
588 assert(mOpenCount == 0);
590 kdDebug(5006) <<
"Creating folder " << location() << endl;
591 if (access(TQFile::encodeName(location()), F_OK) == 0) {
592 kdDebug(5006) <<
"KMFolderSearch::create call to access function failed."
597 old_umask = umask(077);
598 FILE *mStream = fopen(TQFile::encodeName(location()),
"w+");
600 if (!mStream)
return errno;
605 mSearch =
new KMSearch();
606 TQObject::connect(mSearch, TQ_SIGNAL(found(TQ_UINT32)), TQ_SLOT(addSerNum(TQ_UINT32)));
607 TQObject::connect(mSearch, TQ_SIGNAL(finished(
bool)), TQ_SLOT(searchFinished(
bool)));
609 mSearch->write(location());
617 int KMFolderSearch::compact(
bool )
619 needsCompact =
false;
623 bool KMFolderSearch::isReadOnly()
const
628 FolderJob* KMFolderSearch::doCreateJob(
KMMessage*, FolderJob::JobType,
629 KMFolder*, TQString,
const AttachmentStrategy* )
const
636 FolderJob* KMFolderSearch::doCreateJob(TQPtrList<KMMessage>&,
const TQString&,
637 FolderJob::JobType,
KMFolder*)
const
644 const KMMsgBase* KMFolderSearch::getMsgBase(
int idx)
const
648 if (idx < 0 || (TQ_UINT32)idx >= mSerNums.count())
651 assert(folder && (folderIdx != -1));
655 KMMsgBase* KMFolderSearch::getMsgBase(
int idx)
659 if (idx < 0 || (TQ_UINT32)idx >= mSerNums.count())
662 if (!folder || folderIdx == -1)
668 KMMessage* KMFolderSearch::getMsg(
int idx)
672 if (idx < 0 || (TQ_UINT32)idx >= mSerNums.count())
675 assert(folder && (folderIdx != -1));
682 KMFolderSearch::ignoreJobsForMessage(
KMMessage* msg )
691 if (msg->parent()->folderType() == KMFolderTypeImap) {
692 KMAcctImap *account =
693 static_cast<KMFolderImap*
>( msg->storage() )->account();
696 account->ignoreJobsForMessage( msg );
701 int KMFolderSearch::find(
const KMMsgBase* msg)
const
704 TQ_UINT32 serNum = msg->getMsgSerNum();
705 TQValueVector<TQ_UINT32>::const_iterator it;
706 for(it = mSerNums.begin(); it != mSerNums.end(); ++it) {
714 TQString KMFolderSearch::indexLocation()
const
716 TQString sLocation(folder()->path());
718 if (!sLocation.isEmpty()) sLocation +=
'/';
720 sLocation += dotEscape(fileName());
721 sLocation +=
".index";
722 sLocation +=
".search";
727 int KMFolderSearch::updateIndex()
729 if (mSearch && search()->running())
730 unlink(TQFile::encodeName(indexLocation()));
737 int KMFolderSearch::writeIndex(
bool )
741 TQString filename = indexLocation();
742 int old_umask = umask(077);
743 TQString tempName = filename +
".temp";
744 unlink(TQFile::encodeName(tempName));
748 utime(TQFile::encodeName(location()), 0);
750 FILE *tmpIndexStream = fopen(TQFile::encodeName(tempName),
"w");
753 if (!tmpIndexStream) {
754 kdDebug(5006) <<
"Cannot write '" << filename
755 << strerror(errno) <<
" (" << errno <<
")" << endl;
756 truncate(TQFile::encodeName(filename), 0);
759 fprintf(tmpIndexStream, IDS_SEARCH_HEADER, IDS_SEARCH_VERSION);
760 TQ_UINT32 byteOrder = 0x12345678;
761 fwrite(&byteOrder,
sizeof(byteOrder), 1, tmpIndexStream);
763 TQ_UINT32 count = mSerNums.count();
764 if (!fwrite(&count,
sizeof(count), 1, tmpIndexStream)) {
765 fclose(tmpIndexStream);
766 truncate(TQFile::encodeName(filename), 0);
770 TQValueVector<TQ_UINT32>::iterator it;
771 for(it = mSerNums.begin(); it != mSerNums.end(); ++it) {
772 TQ_UINT32 serNum = *it;
773 if (!fwrite(&serNum,
sizeof(serNum), 1, tmpIndexStream))
776 if (ferror(tmpIndexStream))
return ferror(tmpIndexStream);
777 if (fflush(tmpIndexStream) != 0)
return errno;
778 if (fsync(fileno(tmpIndexStream)) != 0)
return errno;
779 if (fclose(tmpIndexStream) != 0)
return errno;
781 ::rename(TQFile::encodeName(tempName), TQFile::encodeName(indexLocation()));
788 DwString KMFolderSearch::getDwString(
int idx)
790 return getMsgBase(idx)->parent()->getDwString( idx );
793 KMMessage* KMFolderSearch::readMsg(
int idx)
798 assert(folder && (folderIdx != -1));
799 return folder->
getMsg( folderIdx );
802 bool KMFolderSearch::readIndex()
805 TQString filename = indexLocation();
806 mIdsStream = fopen(TQFile::encodeName(filename),
"r+");
811 fscanf(mIdsStream, IDS_SEARCH_HEADER, &version);
812 if (version != IDS_SEARCH_VERSION) {
818 TQ_UINT32 byte_order;
819 if (!fread(&byte_order,
sizeof(byte_order), 1, mIdsStream)) {
824 swapByteOrder = (byte_order == 0x78563412);
827 if (!fread(&count,
sizeof(count), 1, mIdsStream)) {
833 count = kmail_swap_32(count);
836 mSerNums.reserve(count);
837 for (
unsigned int index = 0; index < count; index++) {
841 bool readOk = fread(&serNum,
sizeof(serNum), 1, mIdsStream);
849 serNum = kmail_swap_32(serNum);
852 if (!folder || (folderIdx == -1)) {
858 mSerNums.push_back(serNum);
859 if(mFolders.findIndex(folder) == -1) {
862 folder->
open(
"foldersearch");
863 mFolders.append(folder);
865 KMMsgBase *mb = folder->
getMsgBase(folderIdx);
868 if (mb->isNew() || mb->isUnread()) {
869 if (mUnreadMsgs == -1) ++mUnreadMsgs;
873 mTotalMsgs = mSerNums.count();
880 int KMFolderSearch::removeContents()
882 unlink(TQFile::encodeName(location()));
883 unlink(TQFile::encodeName(indexLocation()));
888 int KMFolderSearch::expungeContents()
890 setSearch(
new KMSearch());
894 int KMFolderSearch::count(
bool cache)
const
897 return mSerNums.count();
900 KMMsgBase* KMFolderSearch::takeIndexEntry(
int idx)
902 assert(idx >= 0 && idx < (
int)mSerNums.count());
903 KMMsgBase *msgBase = getMsgBase(idx);
904 TQValueVector<TQ_UINT32>::iterator it = mSerNums.begin();
905 mSerNums.erase(&it[idx]);
909 KMMsgInfo* KMFolderSearch::setIndexEntry(
int idx,
KMMessage *msg)
911 assert(idx >= 0 && idx < (
int)mSerNums.count());
913 return msg->storage()->setIndexEntry(msg->parent()->find(msg), msg);
916 void KMFolderSearch::clearIndex(
bool,
bool)
919 TQValueListIterator<TQGuardedPtr<KMFolder> > fit;
920 for (fit = mFolders.begin(); fit != mFolders.end(); ++fit) {
923 (*fit)->close(
"foldersearch");
930 void KMFolderSearch::truncateIndex()
932 truncate(TQFile::encodeName(indexLocation()), IDS_SEARCH_HEADER_LEN);
935 void KMFolderSearch::examineAddedMessage(
KMFolder *aFolder, TQ_UINT32 serNum)
937 if (!search() && !readSearch())
939 if (!search()->inScope(aFolder))
942 open(
"foldersearch");
946 if (!search()->searchPattern())
952 assert(folder && (idx != -1));
953 assert(folder == aFolder);
957 if ( mFoldersCurrentlyBeingSearched.contains( folder ) ) {
958 unsigned int count = mFoldersCurrentlyBeingSearched[folder];
959 mFoldersCurrentlyBeingSearched.replace( folder, count+1 );
961 connect( folder->storage(),
964 TQ_SLOT( slotSearchExamineMsgDone(
KMFolder*, TQ_UINT32,
966 mFoldersCurrentlyBeingSearched.insert( folder, 1 );
968 folder->storage()->
search( search()->searchPattern(), serNum );
971 void KMFolderSearch::slotSearchExamineMsgDone(
KMFolder* folder,
976 if ( search()->searchPattern() != pattern )
return;
977 kdDebug(5006) << folder->
label() <<
": serNum " << serNum
978 <<
" matches?" << matches << endl;
981 Q_ASSERT( mFoldersCurrentlyBeingSearched.contains( folder ) );
983 unsigned int count = mFoldersCurrentlyBeingSearched[folder];
985 disconnect( folder->storage(),
986 TQ_SIGNAL( searchDone(
KMFolder*, TQ_UINT32,
989 TQ_SLOT( slotSearchExamineMsgDone(
KMFolder*, TQ_UINT32,
991 mFoldersCurrentlyBeingSearched.remove( folder );
993 mFoldersCurrentlyBeingSearched.replace( folder, count-1 );
997 TQValueVector<TQ_UINT32>::const_iterator it;
998 it = tqFind( mSerNums.begin(), mSerNums.end(), serNum );
999 if (it != mSerNums.end()) {
1000 removeSerNum( serNum );
1009 TQValueVector<TQ_UINT32>::const_iterator it;
1010 it = tqFind( mSerNums.begin(), mSerNums.end(), serNum );
1011 if (it == mSerNums.end()) {
1012 addSerNum( serNum );
1017 void KMFolderSearch::examineRemovedMessage(
KMFolder *folder, TQ_UINT32 serNum)
1019 if (!search() && !readSearch())
1021 if (!search()->inScope(folder))
1024 open(
"foldersearch");
1028 if (mSearch->running()) {
1029 mExecuteSearchTimer->start(0,
true);
1031 removeSerNum(serNum);
1035 void KMFolderSearch::examineChangedMessage(
KMFolder *aFolder, TQ_UINT32 serNum,
int delta)
1037 if (!search() && !readSearch())
1039 if (!search()->inScope(aFolder))
1042 open(
"foldersearch");
1045 TQValueVector<TQ_UINT32>::const_iterator it;
1046 it = tqFind( mSerNums.begin(), mSerNums.end(), serNum );
1047 if (it != mSerNums.end()) {
1048 mUnreadMsgs += delta;
1049 emit numUnreadMsgsChanged( folder() );
1050 emit msgChanged( folder(), serNum, delta );
1054 void KMFolderSearch::examineInvalidatedFolder(
KMFolder *folder)
1056 if (!search() && !readSearch())
1058 if (!search()->inScope(folder))
1061 close(
"foldersearch");
1062 mTempOpened =
false;
1070 unlink(TQFile::encodeName(indexLocation()));
1078 open(
"foldersearch");
1081 mExecuteSearchTimer->start(0,
true);
1084 void KMFolderSearch::examineRemovedFolder(
KMFolder *folder)
1086 examineInvalidatedFolder(folder);
1087 if (mSearch->root() == folder) {
1093 void KMFolderSearch::propagateHeaderChanged(
KMFolder *aFolder,
int idx)
1096 if (!search() && !readSearch())
1098 if (!search()->inScope(aFolder))
1101 open(
"foldersearch");
1106 TQValueVector<TQ_UINT32>::const_iterator it;
1107 for(it = mSerNums.begin(); it != mSerNums.end(); ++it) {
1108 if ((*it) == serNum) {
1109 emit msgHeaderChanged(folder(), pos);
1118 if ( mFoldersCurrentlyBeingSearched.contains( aFolder ) ) {
1119 unsigned int count = mFoldersCurrentlyBeingSearched[aFolder];
1120 mFoldersCurrentlyBeingSearched.replace( aFolder, count+1 );
1122 connect( aFolder->storage(),
1125 TQ_SLOT( slotSearchExamineMsgDone(
KMFolder*, TQ_UINT32,
1127 mFoldersCurrentlyBeingSearched.insert( aFolder, 1 );
1129 aFolder->storage()->
search( search()->searchPattern(), serNum );
1132 void KMFolderSearch::tryReleasingFolder(
KMFolder* folder)
1136 if ( mTempOpened && mOpenCount == 1 )
1138 examineInvalidatedFolder( folder );
1142 #include "kmfoldersearch.moc"
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
virtual void ignoreJobsForMessage(KMMessage *)
Removes and deletes all jobs associated with the particular message.
virtual void search(const KMSearchPattern *)
Search for messages The end is signaled with searchDone()
virtual int addMsg(TQPtrList< KMMessage > &, TQValueList< int > &index_return)
Adds the given messages to the folder.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
RAII for KMFolder::open() / close().
virtual TQString label() const
Returns the label of the folder for visualization.
KMFolderDir * child() const
Returns the folder directory associated with this node or 0 if no such directory exists.
void close(const char *owner, bool force=false)
Close folder.
KMMessage * getMsg(int idx)
Read message at given index.
const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
KMFolderType folderType() const
Returns the type of this folder.
int count(bool cache=false) const
Number of messages in this folder.
int open(const char *owner)
Open folder for access.
bool transferInProgress() const
Return, if the message should not be deleted.
unsigned long getMsgSerNum(KMFolder *folder, int index) const
Find the message serial number for the message located at index index in folder folder.
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
static const KMMsgDict * instance()
Access the globally unique MessageDict.
This class is an abstraction of a search over messages.