37 #include "cachedimapjob.h"
38 #include "imapaccountbase.h"
40 #include "kmfoldermgr.h"
42 #include "kmfoldercachedimap.h"
43 #include "kmailicalifaceimpl.h"
44 #include "kmacctcachedimap.h"
45 #include "kmmsgdict.h"
46 #include "maildirjob.h"
50 #include <tdeio/scheduler.h>
51 #include <tdeio/job.h>
53 #include <tdelocale.h>
60 CachedImapJob::CachedImapJob(
const TQValueList<MsgForDownload>& msgs,
61 JobType type, KMFolderCachedImap* folder )
62 : FolderJob( type ), mFolder( folder ), mMsgsForDownload( msgs ),
63 mTotalBytes(0), mMsg(0), mParentFolder( 0 )
65 TQValueList<MsgForDownload>::ConstIterator it = msgs.begin();
66 for ( ; it != msgs.end() ; ++it )
67 mTotalBytes += (*it).size;
71 CachedImapJob::CachedImapJob(
const TQPtrList<KMMessage>& msgs, JobType type,
72 KMFolderCachedImap* folder )
73 : FolderJob( msgs, TQString(), type, folder?folder->folder():0 ), mFolder( folder ),
74 mTotalBytes( msgs.count() ),
75 mMsg( 0 ), mParentFolder( 0 )
79 CachedImapJob::CachedImapJob(
const TQValueList<unsigned long>& msgs,
80 JobType type, KMFolderCachedImap* folder )
81 : FolderJob( TQPtrList<
KMMessage>(), TQString(), type, folder?folder->folder():0 ),
82 mFolder( folder ), mSerNumMsgList( msgs ), mTotalBytes( msgs.count() ), mMsg( 0 ),
88 CachedImapJob::CachedImapJob(
const TQValueList<KMFolderCachedImap*>& fList,
89 JobType type, KMFolderCachedImap* folder )
90 : FolderJob( type ), mFolder( folder ), mFolderList( fList ), mMsg( 0 ),
96 CachedImapJob::CachedImapJob(
const TQString& string1, JobType type,
97 KMFolderCachedImap* folder )
98 : FolderJob( type ), mFolder(folder), mMsg( 0 ), mString( string1 ),
102 assert( type != tDeleteMessage );
106 CachedImapJob::CachedImapJob(
const TQStringList& foldersOrMsgs, JobType type,
107 KMFolderCachedImap* folder )
108 : FolderJob( type ), mFolder( folder ), mFoldersOrMessages( foldersOrMsgs ),
109 mMsg( 0 ), mParentFolder( 0 )
115 CachedImapJob::CachedImapJob( JobType type, KMFolderCachedImap* folder )
116 : FolderJob( type ), mFolder( folder ), mMsg( 0 ), mParentFolder ( 0 )
121 CachedImapJob::~CachedImapJob()
123 mAccount->mJobList.remove(
this);
126 void CachedImapJob::execute()
131 if( !mMsgList.isEmpty() ) {
132 mFolder =
static_cast<KMFolderCachedImap*
>(mMsgList.first()->storage());
136 mAccount = mFolder->account();
137 assert( mAccount != 0 );
138 if( mAccount->makeConnection() != ImapAccountBase::Connected ) {
140 kdDebug(5006) <<
"mAccount->makeConnection() failed" << endl;
141 mPassiveDestructor =
true;
145 mPassiveDestructor =
false;
148 mAccount->mJobList.append(
this);
156 if ( mAccount->groupwareType() == KMAcctCachedImap::GroupwareScalix ) {
157 if ( !mAccount->sentCustomLoginCommand() ) {
158 TQByteArray packedArgs;
159 TQDataStream stream( packedArgs, IO_WriteOnly );
161 const TQString command = TQString(
"X-SCALIX-ID " );
162 const TQString argument = TQString(
"(\"name\" \"Evolution\" \"version\" \"2.10.0\")" );
164 stream << (int)
'X' <<
'N' << command << argument;
166 const KURL url = mAccount->getUrl();
168 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
169 jd.items << mFolder->label();
170 TDEIO::SimpleJob *simpleJob = TDEIO::special( url.url(), packedArgs,
false );
171 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
172 mAccount->insertJob(simpleJob, jd);
174 mAccount->setSentCustomLoginCommand(
true );
179 case tGetMessage: slotGetNextMessage();
break;
180 case tPutMessage: slotPutNextMessage();
break;
181 case tDeleteMessage: slotDeleteNextMessages();
break;
182 case tExpungeFolder: expungeFolder();
break;
183 case tAddSubfolders: slotAddNextSubfolder();
break;
184 case tDeleteFolders: slotDeleteNextFolder();
break;
185 case tCheckUidValidity: checkUidValidity();
break;
186 case tRenameFolder: renameFolder(mString);
break;
187 case tListMessages: listMessages();
break;
193 void CachedImapJob::listMessages()
195 KURL url = mAccount->getUrl();
196 url.setPath( mFolder->imapPath() +
";UID=1:*;SECTION=FLAGS RFC822.SIZE");
198 TDEIO::SimpleJob *job = TDEIO::get(url,
false,
false);
199 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), job );
200 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
201 jd.cancellable =
true;
202 mAccount->insertJob( job, jd );
203 connect( job, TQ_SIGNAL( result(TDEIO::Job *) ),
204 this, TQ_SLOT( slotListMessagesResult( TDEIO::Job* ) ) );
206 connect( job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
207 mFolder, TQ_SLOT( slotGetMessagesData( TDEIO::Job* ,
const TQByteArray& ) ) );
210 void CachedImapJob::slotDeleteNextMessages( TDEIO::Job* job )
213 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
214 if ( it == mAccount->jobsEnd() ) {
220 mAccount->handleJobError( job, i18n(
"Error while deleting messages on the server: " ) +
'\n' );
224 mAccount->removeJob(it);
227 if( mFoldersOrMessages.isEmpty() ) {
233 TQString uids = mFoldersOrMessages.front(); mFoldersOrMessages.pop_front();
235 KURL url = mAccount->getUrl();
236 url.setPath( mFolder->imapPath() +
237 TQString::fromLatin1(
";UID=%1").arg(uids) );
239 TDEIO::SimpleJob *simpleJob = TDEIO::file_delete( url,
false );
240 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), simpleJob );
241 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
242 mAccount->insertJob( simpleJob, jd );
243 connect( simpleJob, TQ_SIGNAL( result(TDEIO::Job *) ),
244 this, TQ_SLOT( slotDeleteNextMessages(TDEIO::Job *) ) );
247 void CachedImapJob::expungeFolder()
249 KURL url = mAccount->getUrl();
251 url.setPath( mFolder->imapPath() + TQString::fromLatin1(
";UID=*") );
253 TDEIO::SimpleJob *job = TDEIO::file_delete( url,
false );
254 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), job );
255 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
256 mAccount->insertJob( job, jd );
257 connect( job, TQ_SIGNAL( result(TDEIO::Job *) ),
258 this, TQ_SLOT( slotExpungeResult(TDEIO::Job *) ) );
261 void CachedImapJob::slotExpungeResult( TDEIO::Job * job )
263 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
264 if ( it == mAccount->jobsEnd() ) {
270 mErrorCode = job->error();
271 mAccount->handleJobError( job, i18n(
"Error while deleting messages on the server: " ) +
'\n' );
274 mAccount->removeJob(it);
279 void CachedImapJob::slotGetNextMessage(TDEIO::Job * job)
282 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
283 if ( it == mAccount->jobsEnd() ) {
289 mErrorCode = job->error();
290 mAccount->handleJobError( job, i18n(
"Error while retrieving message on the server: " ) +
'\n' );
296 if ((*it).data.size() > 0) {
297 ulong uid = mMsg->UID();
298 size = mMsg->msgSizeServer();
301 size_t dataSize = (*it).data.size();
302 dataSize = Util::crlf2lf( (*it).data.data(), dataSize );
303 (*it).data.resize( dataSize );
305 mMsg->setComplete(
true );
306 mMsg->fromByteArray( (*it).data );
308 mMsg->setMsgSizeServer(size);
309 mMsg->setTransferInProgress(
false );
311 mFolder->addMsgInternal( mMsg,
true, &index );
313 if ( kmkernel->iCalIface().isResourceFolder( mFolder->folder() ) ) {
314 mFolder->setStatus( index, KMMsgStatusRead,
false );
317 emit messageRetrieved( mMsg );
318 if ( index > 0 ) mFolder->unGetMsg( index );
320 emit messageRetrieved( 0 );
325 emit progress( mSentBytes, mTotalBytes );
326 mAccount->removeJob(it);
328 mFolder->quiet(
true );
330 if( mMsgsForDownload.isEmpty() ) {
331 mFolder->quiet(
false );
336 MsgForDownload mfd = mMsgsForDownload.front(); mMsgsForDownload.pop_front();
339 mMsg->setUID(mfd.uid);
340 mMsg->setMsgSizeServer(mfd.size);
342 KMFolderImap::flagsToStatus(mMsg, mfd.flags,
true, GlobalSettings::allowLocalFlags() ? mFolder->permanentFlags() : INT_MAX);
343 KURL url = mAccount->getUrl();
344 url.setPath(mFolder->imapPath() + TQString(
";UID=%1;SECTION=BODY.PEEK[]").arg(mfd.uid));
346 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
347 jd.cancellable =
true;
348 mMsg->setTransferInProgress(
true);
349 TDEIO::SimpleJob *simpleJob = TDEIO::get(url,
false,
false);
350 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
351 mAccount->insertJob(simpleJob, jd);
352 connect(simpleJob, TQ_SIGNAL(processedSize(TDEIO::Job *, TDEIO::filesize_t)),
353 this, TQ_SLOT(slotProcessedSize(TDEIO::Job *, TDEIO::filesize_t)));
354 connect(simpleJob, TQ_SIGNAL(result(TDEIO::Job *)),
355 this, TQ_SLOT(slotGetNextMessage(TDEIO::Job *)));
356 connect(simpleJob, TQ_SIGNAL(data(TDEIO::Job *,
const TQByteArray &)),
357 mFolder, TQ_SLOT(slotSimpleData(TDEIO::Job *,
const TQByteArray &)));
360 void CachedImapJob::slotProcessedSize(TDEIO::Job *, TDEIO::filesize_t processed)
362 emit progress( mSentBytes + processed, mTotalBytes );
365 void CachedImapJob::slotPutNextMessage()
370 if( !mMsgList.isEmpty() ) {
371 mMsg = mMsgList.first();
372 mMsgList.removeFirst();
376 while( mMsg == 0 && !mSerNumMsgList.isEmpty() ) {
377 unsigned long serNum = mSerNumMsgList.first();
378 mSerNumMsgList.pop_front();
384 if( mFolder->folder() != aFolder )
387 mMsg = mFolder->getMsg( i );
396 KURL url = mAccount->getUrl();
397 TQString flags = KMFolderImap::statusToFlags( mMsg->status(), mFolder->permanentFlags() );
398 url.setPath( mFolder->imapPath() +
";SECTION=" + flags );
400 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
403 TQCString cstr(mMsg->asString());
404 int a = cstr.find(
"\nX-UID: ");
405 int b = cstr.find(
'\n', a);
406 if (a != -1 && b != -1 && cstr.find(
"\n\n") > a) cstr.remove(a, b-a);
407 TQCString mData(cstr.length() + cstr.contains(
'\n'));
409 for(
char *ch = cstr.data(); *ch; ch++ ) {
414 mData.at(i) = *ch; i++;
417 jd.msgList.append( mMsg );
419 mMsg->setTransferInProgress(
true);
420 TDEIO::SimpleJob *simpleJob = TDEIO::put(url, 0,
false,
false,
false);
421 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
422 mAccount->insertJob(simpleJob, jd);
423 connect( simpleJob, TQ_SIGNAL( result(TDEIO::Job *) ),
424 TQ_SLOT( slotPutMessageResult(TDEIO::Job *) ) );
425 connect( simpleJob, TQ_SIGNAL( dataReq(TDEIO::Job *, TQByteArray &) ),
426 TQ_SLOT( slotPutMessageDataReq(TDEIO::Job *, TQByteArray &) ) );
427 connect( simpleJob, TQ_SIGNAL( data(TDEIO::Job *,
const TQByteArray &) ),
428 mFolder, TQ_SLOT( slotSimpleData(TDEIO::Job *,
const TQByteArray &) ) );
429 connect( simpleJob, TQ_SIGNAL(infoMessage(TDEIO::Job *,
const TQString &)),
430 TQ_SLOT(slotPutMessageInfoData(TDEIO::Job *,
const TQString &)) );
436 void CachedImapJob::slotPutMessageDataReq(TDEIO::Job *job, TQByteArray &data)
438 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
439 if ( it == mAccount->jobsEnd() ) {
443 if ((*it).data.size() - (*it).offset > 0x8000) {
444 data.duplicate((*it).data.data() + (*it).offset, 0x8000);
445 (*it).offset += 0x8000;
446 }
else if ((*it).data.size() - (*it).offset > 0) {
447 data.duplicate((*it).data.data() + (*it).offset,
448 (*it).data.size() - (*it).offset);
449 (*it).offset = (*it).data.size();
455 void CachedImapJob::slotPutMessageInfoData( TDEIO::Job *job,
const TQString &data )
457 KMFolderCachedImap *imapFolder =
static_cast<KMFolderCachedImap*
>( mDestFolder->storage() );
459 KMAcctCachedImap *account = imapFolder->account();
460 ImapAccountBase::JobIterator it = account->findJob( job );
461 if ( it == account->jobsEnd() ) {
465 if ( data.find(
"UID" ) != -1 && mMsg ) {
466 int uid = ( data.right( data.length() - 4 ) ).toInt();
467 kdDebug( 5006 ) << k_funcinfo <<
"Server told us uid is: " << uid << endl;
475 void CachedImapJob::slotPutMessageResult(TDEIO::Job *job)
477 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
478 if ( it == mAccount->jobsEnd() ) {
483 if ( job->error() ) {
484 bool cont = mAccount->handlePutError( job, *it, mFolder->folder() );
489 slotPutNextMessage();
494 emit messageStored( mMsg );
498 emit progress( mSentBytes, mTotalBytes );
501 if( ( i = mFolder->find(mMsg) ) != -1 ) {
507 if ( mMsg->UID() == 0 ) {
508 mFolder->removeMsg(i);
511 bool b = kmkernel->iCalIface().isResourceQuiet();
512 kmkernel->iCalIface().setResourceQuiet(
true );
514 mFolder->takeTemporarily( i );
515 mFolder->addMsgKeepUID( mMsg );
516 mMsg->setTransferInProgress(
false );
518 kmkernel->iCalIface().setResourceQuiet( b );
522 mAccount->removeJob( it );
523 slotPutNextMessage();
527 void CachedImapJob::slotAddNextSubfolder( TDEIO::Job * job )
530 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
531 if ( it == mAccount->jobsEnd() ) {
537 bool silentUpload =
static_cast<KMFolderCachedImap*
>((*it).parent->storage())->silentUpload();
538 static_cast<KMFolderCachedImap*
>((*it).parent->storage())->setSilentUpload(
false );
540 if ( job->error() && !silentUpload ) {
541 TQString myError =
"<p><b>" + i18n(
"Error while uploading folder")
542 +
"</b></p><p>" + i18n(
"Could not make the folder <b>%1</b> on the server.").arg((*it).items[0])
543 +
"</p><p>" + i18n(
"This could be because you do not have permission to do this, or because the folder is already present on the server; the error message from the server communication is here:") +
"</p>";
544 mAccount->handleJobError( job, myError );
551 KMFolderCachedImap* storage =
static_cast<KMFolderCachedImap*
>( (*it).current->storage() );
552 KMFolderCachedImap* parentStorage =
static_cast<KMFolderCachedImap*
>( (*it).parent->storage() );
554 Q_ASSERT( parentStorage );
555 if ( storage->imapPath().isEmpty() ) {
556 TQString path = mAccount->createImapPath( parentStorage->imapPath(), storage->folder()->name() );
557 if ( !storage->imapPathForCreation().isEmpty() )
558 path = storage->imapPathForCreation();
559 storage->setImapPath( path );
560 storage->writeConfig();
563 mAccount->removeJob( it );
566 if (mFolderList.isEmpty()) {
572 KMFolderCachedImap *folder = mFolderList.front();
573 mFolderList.pop_front();
574 KURL url = mAccount->getUrl();
575 TQString path = mAccount->createImapPath( mFolder->imapPath(),
576 folder->folder()->name() );
577 if ( !folder->imapPathForCreation().isEmpty() ) {
579 path = folder->imapPathForCreation();
583 if ( mAccount->groupwareType() != KMAcctCachedImap::GroupwareScalix ) {
587 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
588 jd.items << folder->label();
589 jd.current = folder->folder();
590 TDEIO::SimpleJob *simpleJob = TDEIO::mkdir(url);
591 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
592 mAccount->insertJob(simpleJob, jd);
593 connect( simpleJob, TQ_SIGNAL(result(TDEIO::Job *)),
594 this, TQ_SLOT(slotAddNextSubfolder(TDEIO::Job *)) );
596 TQByteArray packedArgs;
597 TQDataStream stream( packedArgs, IO_WriteOnly );
599 const TQString command = TQString(
"X-CREATE-SPECIAL" );
600 const TQString argument = TQString(
"%1 %2" ).arg( Scalix::Utils::contentsTypeToScalixId( folder->contentsType() ) )
603 stream << (int)
'X' <<
'N' << command << argument;
605 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
606 jd.items << folder->label();
607 jd.current = folder->folder();
608 TDEIO::SimpleJob *simpleJob = TDEIO::special( url.url(), packedArgs,
false );
609 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
610 mAccount->insertJob(simpleJob, jd);
611 connect( simpleJob, TQ_SIGNAL(result(TDEIO::Job *)),
612 this, TQ_SLOT(slotAddNextSubfolder(TDEIO::Job *)) );
617 void CachedImapJob::slotDeleteNextFolder( TDEIO::Job *job )
620 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
621 if ( it == mAccount->jobsEnd() ) {
626 mAccount->removeDeletedFolder( (*it).path );
629 mAccount->handleJobError( job, i18n(
"Error while deleting folder %1 on the server: " ).arg( (*it).path ) +
'\n' );
633 mAccount->removeJob(it);
636 if( mFoldersOrMessages.isEmpty() ) {
642 TQString folderPath = mFoldersOrMessages.front();
643 mFoldersOrMessages.pop_front();
644 KURL url = mAccount->getUrl();
645 url.setPath(folderPath);
646 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
647 jd.path = url.path();
648 TDEIO::SimpleJob *simpleJob = TDEIO::file_delete(url,
false);
649 TDEIO::Scheduler::assignJobToSlave(mAccount->slave(), simpleJob);
650 mAccount->insertJob(simpleJob, jd);
651 connect( simpleJob, TQ_SIGNAL( result(TDEIO::Job *) ),
652 TQ_SLOT( slotDeleteNextFolder(TDEIO::Job *) ) );
655 void CachedImapJob::checkUidValidity()
657 KURL url = mAccount->getUrl();
658 url.setPath( mFolder->imapPath() +
";UID=0:0" );
660 ImapAccountBase::jobData jd( url.url(), mFolder->folder() );
661 jd.cancellable =
true;
663 TDEIO::SimpleJob *job = TDEIO::get( url,
false,
false );
664 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), job );
665 mAccount->insertJob( job, jd );
666 connect( job, TQ_SIGNAL(result(TDEIO::Job *)),
667 TQ_SLOT(slotCheckUidValidityResult(TDEIO::Job *)) );
668 connect( job, TQ_SIGNAL(data(TDEIO::Job *,
const TQByteArray &)),
669 mFolder, TQ_SLOT(slotSimpleData(TDEIO::Job *,
const TQByteArray &)));
672 void CachedImapJob::slotCheckUidValidityResult(TDEIO::Job * job)
674 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
675 if ( it == mAccount->jobsEnd() ) {
681 mErrorCode = job->error();
682 mAccount->handleJobError( job, i18n(
"Error while reading folder %1 on the server: " ).arg( (*it).parent->label() ) +
'\n' );
688 TQCString cstr((*it).data.data(), (*it).data.size() + 1);
689 int a = cstr.find(
"X-uidValidity: ");
693 kdDebug(5006) <<
"No uidvalidity available for folder "
694 << mFolder->name() << endl;
697 int b = cstr.find(
"\r\n", a);
698 if ( (b - a - 15) >= 0 ) {
699 TQString uidv = cstr.mid(a + 15, b - a - 15);
702 if( !mFolder->uidValidity().isEmpty() && mFolder->uidValidity() != uidv ) {
706 mFolder->setLastUid( 0 );
707 mFolder->clearUidMap();
710 kdDebug(5006) <<
"No uidvalidity available for folder "
711 << mFolder->name() << endl;
714 a = cstr.find(
"X-PermanentFlags: " );
716 kdDebug(5006) <<
"no PERMANENTFLAGS response? assumming custom flags are not available" << endl;
718 int b = cstr.find(
"\r\n", a );
719 if ( (b - a - 18) >= 0 ) {
720 int flags = cstr.mid( a + 18, b - a - 18 ).toInt();
721 emit permanentFlags( flags );
723 kdDebug(5006) <<
"PERMANENTFLAGS response broken, assumming custom flags are not available" << endl;
727 mAccount->removeJob(it);
732 void CachedImapJob::renameFolder(
const TQString &newName )
737 KURL urlSrc = mAccount->getUrl();
738 mOldImapPath = mFolder->imapPath();
739 urlSrc.setPath( mOldImapPath );
742 KURL urlDst = mAccount->getUrl();
743 mNewImapPath = mFolder->imapPath();
745 mNewImapPath.truncate( mNewImapPath.length() - mFolder->folder()->name().length() - 1);
746 mNewImapPath += newName +
'/';
747 urlDst.setPath( mNewImapPath );
749 ImapAccountBase::jobData jd( newName, mFolder->folder() );
750 jd.path = mNewImapPath;
752 TDEIO::SimpleJob *simpleJob = TDEIO::rename( urlSrc, urlDst,
false );
753 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), simpleJob );
754 mAccount->insertJob( simpleJob, jd );
755 connect( simpleJob, TQ_SIGNAL(result(TDEIO::Job *)),
756 TQ_SLOT(slotRenameFolderResult(TDEIO::Job *)) );
759 static void renameChildFolders(
KMFolderDir* dir,
const TQString& oldPath,
760 const TQString& newPath )
763 KMFolderNode *node = dir->first();
765 if( !node->isDir() ) {
766 KMFolderCachedImap* imapFolder =
767 static_cast<KMFolderCachedImap*
>(
static_cast<KMFolder*
>(node)->storage());
768 if ( !imapFolder->imapPath().isEmpty() )
770 if( imapFolder->imapPath().find( oldPath ) == 0 ) {
771 TQString p = imapFolder->imapPath();
772 p = p.mid( oldPath.length() );
773 p.prepend( newPath );
774 imapFolder->setImapPath( p );
775 renameChildFolders( imapFolder->folder()->child(), oldPath, newPath );
783 void CachedImapJob::revertLabelChange()
785 TQMap<TQString, KMAcctCachedImap::RenamedFolder>::ConstIterator renit = mAccount->renamedFolders().find( mFolder->imapPath() );
786 Q_ASSERT( renit != mAccount->renamedFolders().end() );
787 if ( renit != mAccount->renamedFolders().end() ) {
788 mFolder->folder()->setLabel( (*renit).mOldLabel );
789 mAccount->removeRenamedFolder( mFolder->imapPath() );
790 kmkernel->dimapFolderMgr()->contentsChanged();
794 void CachedImapJob::renameOnDisk()
796 TQString oldName = mFolder->name();
797 TQString oldPath = mFolder->imapPath();
798 mAccount->removeRenamedFolder( oldPath );
799 mFolder->setImapPath( mNewImapPath );
800 mFolder->FolderStorage::rename( mNewName );
802 if( oldPath.endsWith(
"/" ) ) oldPath.truncate( oldPath.length() -1 );
803 TQString newPath = mFolder->imapPath();
804 if( newPath.endsWith(
"/" ) ) newPath.truncate( newPath.length() -1 );
805 renameChildFolders( mFolder->folder()->child(), oldPath, newPath );
806 kmkernel->dimapFolderMgr()->contentsChanged();
809 void CachedImapJob::slotSubscribtionChange1Failed(
const TQString &errorMessage )
811 KMessageBox::sorry( 0, i18n(
"Error while trying to subscribe to the renamed folder %1.\n"
812 "Renaming itself was successful, but the renamed folder might disappear "
813 "from the folder list after the next sync since it is unsubscribed on the server.\n"
814 "You can try to manually subscribe to the folder yourself.\n\n"
816 .arg( mFolder->label() ).arg( errorMessage ) );
820 void CachedImapJob::slotSubscribtionChange2Failed(
const TQString &errorMessage )
822 kdWarning(5006) << k_funcinfo << errorMessage << endl;
827 void CachedImapJob::slotSubscribtionChange1Done(
const TQString&,
bool )
829 disconnect( mAccount, TQ_SIGNAL( subscriptionChanged(
const TQString&,
bool ) ),
830 this, TQ_SLOT( slotSubscribtionChange1Done(
const TQString&,
bool ) ) );
831 connect( mAccount, TQ_SIGNAL( subscriptionChanged(
const TQString&,
bool ) ),
832 this, TQ_SLOT( slotSubscribtionChange2Done(
const TQString&,
bool ) ) );
833 disconnect( mAccount, TQ_SIGNAL( subscriptionChangeFailed(
const TQString& ) ),
834 this, TQ_SLOT( slotSubscribtionChange1Failed(
const TQString& ) ) );
835 connect( mAccount, TQ_SIGNAL( subscriptionChangeFailed(
const TQString& ) ),
836 this, TQ_SLOT( slotSubscribtionChange2Failed(
const TQString& ) ) );
838 mAccount->changeSubscription(
false, mOldImapPath,
true );
841 void CachedImapJob::slotSubscribtionChange2Done(
const TQString&,
bool )
847 void CachedImapJob::slotRenameFolderResult( TDEIO::Job *job )
849 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
850 if ( it == mAccount->jobsEnd() ) {
857 const TQString errorMessage = i18n(
"Error while trying to rename folder %1" ).arg( mFolder->label() );
858 mAccount->handleJobError( job, errorMessage );
862 mAccount->removeJob( it );
868 connect( mAccount, TQ_SIGNAL( subscriptionChangeFailed(
const TQString& ) ),
869 this, TQ_SLOT( slotSubscribtionChange1Failed(
const TQString& ) ) );
870 connect( mAccount, TQ_SIGNAL( subscriptionChanged(
const TQString&,
bool ) ),
871 this, TQ_SLOT( slotSubscribtionChange1Done(
const TQString&,
bool ) ) );
872 mAccount->changeSubscription(
true, mNewImapPath,
true );
876 void CachedImapJob::slotListMessagesResult( TDEIO::Job * job )
878 KMAcctCachedImap::JobIterator it = mAccount->findJob(job);
879 if ( it == mAccount->jobsEnd() ) {
885 mErrorCode = job->error();
886 mAccount->handleJobError( job, i18n(
"Error while deleting messages on the server: " ) +
'\n' );
889 mAccount->removeJob(it);
895 void CachedImapJob::setParentFolder(
const KMFolderCachedImap* parent )
897 mParentFolder =
const_cast<KMFolderCachedImap*
>( parent );
902 #include "cachedimapjob.moc"
KMail list that manages the contents of one directory that may contain folders and/or other directori...
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.