36 #include "kmacctcachedimap.h"
37 using KMail::SieveConfig;
39 #include "kmfoldertree.h"
40 #include "kmfoldermgr.h"
41 #include "kmfiltermgr.h"
42 #include "kmfoldercachedimap.h"
43 #include "kmmainwin.h"
44 #include "accountmanager.h"
46 #include "progressmanager.h"
48 #include <tdeio/passdlg.h>
49 #include <tdeio/scheduler.h>
50 #include <tdeio/slave.h>
52 #include <kstandarddirs.h>
53 #include <tdeapplication.h>
54 #include <tdeconfig.h>
56 #include <tqstylesheet.h>
59 const TQString& aAccountName, uint
id )
60 :
KMail::ImapAccountBase( aOwner, aAccountName, id ), mFolder( 0 ),
61 mAnnotationCheckPassed(false),
62 mGroupwareType( GroupwareKolab ),
63 mSentCustomLoginCommand(false)
71 KMAcctCachedImap::~KMAcctCachedImap()
73 killAllJobsInternal(
true );
78 TQString KMAcctCachedImap::type()
const
83 void KMAcctCachedImap::init() {
84 ImapAccountBase::init();
88 void KMAcctCachedImap::pseudoAssign(
const KMAccount * a ) {
92 mFolder->setContentState(KMFolderCachedImap::imapNoInformation);
93 mFolder->setSubfolderState(KMFolderCachedImap::imapNoInformation);
95 ImapAccountBase::pseudoAssign( a );
99 void KMAcctCachedImap::setImapFolder(KMFolderCachedImap *aFolder)
102 mFolder->setImapPath(
"/" );
103 mFolder->setAccount(
this );
108 void KMAcctCachedImap::setAutoExpunge(
bool )
111 mAutoExpunge =
false;
115 void KMAcctCachedImap::killAllJobs(
bool disconnectSlave )
118 TQValueList<KMFolderCachedImap*> folderList = killAllJobsInternal( disconnectSlave );
119 for( TQValueList<KMFolderCachedImap*>::Iterator it = folderList.begin(); it != folderList.end(); ++it ) {
120 KMFolderCachedImap *fld = *it;
121 fld->resetSyncState();
122 fld->setContentState(KMFolderCachedImap::imapNoInformation);
123 fld->setSubfolderState(KMFolderCachedImap::imapNoInformation);
124 fld->sendFolderComplete(
false);
130 TQValueList<KMFolderCachedImap*> KMAcctCachedImap::killAllJobsInternal(
bool disconnectSlave )
134 TQValueList<KMFolderCachedImap*> folderList;
135 TQMap<TDEIO::Job*, jobData>::Iterator it = mapJobData.begin();
136 for (; it != mapJobData.end(); ++it) {
138 folderList << static_cast<KMFolderCachedImap*>((*it).parent->storage());
140 if ( !it.key()->error() && mSlave ) {
148 for( TQPtrListIterator<CachedImapJob> it( mJobList ); it.current(); ++it )
149 it.current()->setPassiveDestructor(
true );
150 KMAccount::deleteFolderJobs();
152 if ( disconnectSlave && mSlave ) {
153 TDEIO::Scheduler::disconnectSlave( mSlave );
160 void KMAcctCachedImap::cancelMailCheck()
163 TQValueList<KMFolderCachedImap*> folderList;
164 TQMap<TDEIO::Job*, jobData>::Iterator it = mapJobData.begin();
165 for (; it != mapJobData.end(); ++it) {
166 if ( (*it).cancellable && (*it).parent )
167 folderList << static_cast<KMFolderCachedImap*>((*it).parent->storage());
170 ImapAccountBase::cancelMailCheck();
173 for( TQValueList<KMFolderCachedImap*>::Iterator it = folderList.begin(); it != folderList.end(); ++it ) {
174 KMFolderCachedImap *fld = *it;
175 fld->resetSyncState();
176 fld->setContentState(KMFolderCachedImap::imapNoInformation);
177 fld->setSubfolderState(KMFolderCachedImap::imapNoInformation);
178 fld->sendFolderComplete(
false);
183 void KMAcctCachedImap::slotCheckQueuedFolders()
185 mMailCheckFolders.clear();
186 mMailCheckFolders.append( mFoldersQueuedForChecking.front() );
187 mFoldersQueuedForChecking.pop_front();
188 if ( mFoldersQueuedForChecking.isEmpty() )
189 disconnect(
this, TQ_SIGNAL( finishedCheck(
bool, CheckStatus ) ),
190 this, TQ_SLOT( slotCheckQueuedFolders() ) );
192 kmkernel->acctMgr()->singleCheckMail(
this,
true);
193 mMailCheckFolders.clear();
196 void KMAcctCachedImap::processNewMail(
bool )
200 if ( mMailCheckFolders.isEmpty() )
201 processNewMail( mFolder,
true );
203 KMFolder* f = mMailCheckFolders.front();
204 mMailCheckFolders.pop_front();
209 processNewMail(
static_cast<KMFolderCachedImap *
>( f->storage() ), !checkingSingleFolder() );
214 void KMAcctCachedImap::processNewMail( KMFolderCachedImap* folder,
220 mAutoExpunge =
false;
221 mCountLastUnread = 0;
222 mUnreadBeforeCheck.clear();
227 if ( folder == mFolder && !namespaces().isEmpty() ) {
228 TQStringList nsToList = namespaces()[PersonalNS];
229 TQStringList otherNSToCheck = namespaces()[OtherUsersNS];
230 otherNSToCheck += namespaces()[SharedNS];
231 for ( TQStringList::Iterator it = otherNSToCheck.begin();
232 it != otherNSToCheck.end(); ++it ) {
233 if ( (*it).isEmpty() ) {
239 folder->setNamespacesToList( nsToList );
242 Q_ASSERT( !mMailCheckProgressItem );
243 mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
244 "MailCheck" + TQString::number(
id() ),
245 TQStyleSheet::escape( folder->label() ),
248 useSSL() || useTLS() );
249 connect( mMailCheckProgressItem, TQ_SIGNAL( progressItemCanceled( KPIM::ProgressItem* ) ),
250 this, TQ_SLOT( slotProgressItemCanceled( KPIM::ProgressItem* ) ) );
252 folder->setAccount(
this);
253 connect(folder, TQ_SIGNAL(folderComplete(KMFolderCachedImap*,
bool)),
254 this, TQ_SLOT(postProcessNewMail(KMFolderCachedImap*,
bool)));
255 folder->serverSync( recurse );
258 void KMAcctCachedImap::postProcessNewMail( KMFolderCachedImap* folder,
bool )
260 mNoopTimer.start( 60000 );
261 disconnect(folder, TQ_SIGNAL(folderComplete(KMFolderCachedImap*,
bool)),
262 this, TQ_SLOT(postProcessNewMail(KMFolderCachedImap*,
bool)));
263 mMailCheckProgressItem->setComplete();
264 mMailCheckProgressItem = 0;
266 if ( folder == mFolder ) {
274 mDeletedFolders.clear();
276 mPreviouslyDeletedFolders.clear();
279 KMail::ImapAccountBase::postProcessNewMail();
282 void KMAcctCachedImap::addUnreadMsgCount(
const KMFolderCachedImap *folder,
285 if ( folder->imapPath() !=
"/INBOX/" ) {
288 const TQString folderId = folder->folder()->idString();
289 int newInFolder = countUnread;
290 if ( mUnreadBeforeCheck.find( folderId ) != mUnreadBeforeCheck.end() )
291 newInFolder -= mUnreadBeforeCheck[folderId];
292 if ( newInFolder > 0 )
293 addToNewInFolder( folderId, newInFolder );
295 mCountUnread += countUnread;
298 void KMAcctCachedImap::addLastUnreadMsgCount(
const KMFolderCachedImap *folder,
299 int countLastUnread )
301 mUnreadBeforeCheck[folder->folder()->idString()] = countLastUnread;
302 mCountLastUnread += countLastUnread;
311 void KMAcctCachedImap::readConfig( TDEConfig & config ) {
312 ImapAccountBase::readConfig( config );
314 mPreviouslyDeletedFolders = config.readListEntry(
"deleted-folders" );
315 mDeletedFolders.clear();
316 const TQStringList oldPaths = config.readListEntry(
"renamed-folders-paths" );
317 const TQStringList newNames = config.readListEntry(
"renamed-folders-names" );
318 TQStringList::const_iterator it = oldPaths.begin();
319 TQStringList::const_iterator nameit = newNames.begin();
320 for( ; it != oldPaths.end() && nameit != newNames.end(); ++it, ++nameit ) {
321 addRenamedFolder( *it, TQString(), *nameit );
323 mGroupwareType = (GroupwareType)config.readNumEntry(
"groupwareType", GroupwareKolab );
326 void KMAcctCachedImap::writeConfig( TDEConfig & config ) {
327 ImapAccountBase::writeConfig( config );
328 config.writeEntry(
"deleted-folders", mDeletedFolders + mPreviouslyDeletedFolders );
329 config.writeEntry(
"renamed-folders-paths", mRenamedFolders.keys() );
330 const TQValueList<RenamedFolder> values = mRenamedFolders.values();
331 TQStringList lstNames;
332 TQValueList<RenamedFolder>::const_iterator it = values.begin();
333 for ( ; it != values.end() ; ++it )
334 lstNames.append( (*it).mNewName );
335 config.writeEntry(
"renamed-folders-names", lstNames );
336 config.writeEntry(
"groupwareType", mGroupwareType );
339 void KMAcctCachedImap::invalidateIMAPFolders()
341 invalidateIMAPFolders( mFolder );
344 void KMAcctCachedImap::invalidateIMAPFolders( KMFolderCachedImap* folder )
346 if( !folder || !folder->folder() )
349 folder->setAccount(
this);
351 TQStringList strList;
352 TQValueList<TQGuardedPtr<KMFolder> > folderList;
353 kmkernel->dimapFolderMgr()->createFolderList( &strList, &folderList,
354 folder->folder()->child(), TQString(),
356 TQValueList<TQGuardedPtr<KMFolder> >::Iterator it;
357 mCountLastUnread = 0;
358 mUnreadBeforeCheck.clear();
360 for( it = folderList.begin(); it != folderList.end(); ++it ) {
362 if( f && f->
folderType() == KMFolderTypeCachedImap ) {
363 KMFolderCachedImap *cfolder =
static_cast<KMFolderCachedImap*
>(f->storage());
365 cfolder->setUidValidity(
"INVALID");
366 cfolder->writeUidCache();
369 folder->setUidValidity(
"INVALID");
370 folder->writeUidCache();
372 processNewMailInFolder( folder->folder(), Recursive );
376 void KMAcctCachedImap::addDeletedFolder(
KMFolder* folder )
378 if ( !folder || folder->
folderType() != KMFolderTypeCachedImap )
380 KMFolderCachedImap* storage =
static_cast<KMFolderCachedImap*
>(folder->storage());
381 addDeletedFolder( storage->imapPath() );
382 kdDebug(5006) << k_funcinfo << storage->imapPath() << endl;
385 if( folder->
child() ) {
386 KMFolderNode *node = folder->
child()->first();
388 if( !node->isDir() ) {
389 addDeletedFolder(
static_cast<KMFolder*
>( node ) );
391 node = folder->
child()->next();
396 void KMAcctCachedImap::addDeletedFolder(
const TQString& imapPath )
398 mDeletedFolders << imapPath;
401 TQStringList KMAcctCachedImap::deletedFolderPaths(
const TQString& subFolderPath )
const
404 for ( TQStringList::const_iterator it = mDeletedFolders.begin(); it != mDeletedFolders.end(); ++it ) {
405 if ( (*it).startsWith( subFolderPath ) )
409 for ( TQStringList::const_iterator it = mPreviouslyDeletedFolders.begin(); it != mPreviouslyDeletedFolders.end(); ++it ) {
410 if ( (*it).startsWith( subFolderPath ) )
413 kdDebug(5006) <<
"KMAcctCachedImap::deletedFolderPaths for " << subFolderPath <<
" returning: " << lst << endl;
414 Q_ASSERT( !lst.isEmpty() );
418 bool KMAcctCachedImap::isDeletedFolder(
const TQString& subFolderPath )
const
420 return mDeletedFolders.find( subFolderPath ) != mDeletedFolders.end();
423 bool KMAcctCachedImap::isPreviouslyDeletedFolder(
const TQString& subFolderPath )
const
425 return mPreviouslyDeletedFolders.find( subFolderPath ) != mPreviouslyDeletedFolders.end();
428 void KMAcctCachedImap::removeDeletedFolder(
const TQString& subFolderPath )
430 mDeletedFolders.remove( subFolderPath );
431 mPreviouslyDeletedFolders.remove( subFolderPath );
434 void KMAcctCachedImap::addRenamedFolder(
const TQString& subFolderPath,
const TQString& oldLabel,
const TQString& newName )
436 mRenamedFolders.insert( subFolderPath, RenamedFolder( oldLabel, newName ) );
439 void KMAcctCachedImap::removeRenamedFolder(
const TQString& subFolderPath )
441 mRenamedFolders.remove( subFolderPath );
444 void KMAcctCachedImap::slotProgressItemCanceled( ProgressItem* )
446 bool abortConnection = !mSlaveConnected;
447 killAllJobs( abortConnection );
448 if ( abortConnection ) {
450 emit connectionResult( TDEIO::ERR_USER_CANCELED, TQString() );
460 TQString KMAcctCachedImap::renamedFolder(
const TQString& imapPath )
const
462 TQMap<TQString, RenamedFolder>::ConstIterator renit = mRenamedFolders.
find( imapPath );
463 if ( renit != mRenamedFolders.end() )
464 return (*renit).mNewName;
468 #include "kmacctcachedimap.moc"
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
virtual int find(const KMMsgBase *msg) const =0
Returns the index of the given message or -1 if not found.
KMFolderDir * child() const
Returns the folder directory associated with this node or 0 if no such directory exists.
KMFolderType folderType() const
Returns the type of this folder.
The account manager is responsible for creating accounts of various types via the factory method crea...