kmfoldercachedimap.h
00001 /* 00002 * kmfoldercachedimap.cpp 00003 * 00004 * Copyright (c) 2002-2004 Bo Thorsen <bo@sonofthor.dk> 00005 * Copyright (c) 2002-2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; version 2 of the License 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * In addition, as a special exception, the copyright holders give 00021 * permission to link the code of this program with any edition of 00022 * the TQt library by Trolltech AS, Norway (or with modified versions 00023 * of TQt that use the same license as TQt), and distribute linked 00024 * combinations including the two. You must obey the GNU General 00025 * Public License in all respects for all of the code used other than 00026 * TQt. If you modify this file, you may extend this exception to 00027 * your version of the file, but you are not obligated to do so. If 00028 * you do not wish to do so, delete this exception statement from 00029 * your version. 00030 */ 00031 00032 #ifndef kmfoldercachedimap_h 00033 #define kmfoldercachedimap_h 00034 00035 #include <kdialogbase.h> 00036 #include <kstandarddirs.h> 00037 #include <tqvaluelist.h> 00038 #include <tqvaluevector.h> 00039 #include <tqptrlist.h> 00040 #include <tqdialog.h> 00041 00042 #include "kmfoldermaildir.h" 00043 #include "kmfolderimap.h" 00044 #include "kmacctcachedimap.h" 00045 #include "kmfoldertype.h" 00046 #include "folderjob.h" 00047 #include "cachedimapjob.h" 00048 #include "quotajobs.h" 00049 00050 #include <set> 00051 00052 using KMail::FolderJob; 00053 using KMail::QuotaInfo; 00054 class KMCommand; 00055 00056 class TQComboBox; 00057 class TQRadioButton; 00058 00059 namespace KMail { 00060 class AttachmentStrategy; 00061 class ImapAccountBase; 00062 struct ACLListEntry; 00063 } 00064 using KMail::AttachmentStrategy; 00065 00066 class DImapTroubleShootDialog : public KDialogBase 00067 { 00068 Q_OBJECT 00069 TQ_OBJECT 00070 public: 00071 enum SelectedOperation { 00072 None = -1, 00073 ReindexCurrent = 0, 00074 ReindexRecursive = 1, 00075 ReindexAll = 2, 00076 RefreshCache 00077 }; 00078 00079 DImapTroubleShootDialog( TQWidget* parent=0, const char* name=0 ); 00080 00081 static int run(); 00082 00083 private slots: 00084 void slotDone(); 00085 void slotChanged(); 00086 private: 00087 TQRadioButton *mIndexButton, *mCacheButton; 00088 TQComboBox *mIndexScope; 00089 TQButtonGroup *mButtonGroup; 00090 int rc; 00091 }; 00092 00093 class KMFolderCachedImap : public KMFolderMaildir 00094 { 00095 Q_OBJECT 00096 TQ_OBJECT 00097 00098 public: 00099 static TQString cacheLocation() { 00100 return locateLocal("data", "kmail/dimap" ); 00101 } 00102 00106 KMFolderCachedImap(KMFolder* folder, const char* name=0); 00107 virtual ~KMFolderCachedImap(); 00108 00110 void reallyDoClose(const char* owner); 00111 00113 void initializeFrom( KMFolderCachedImap* parent ); 00114 00115 virtual void readConfig(); 00116 virtual void writeConfig(); 00117 00118 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig(); 00119 00121 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; } 00122 00124 virtual int create(); 00125 00127 virtual void remove(); 00128 00130 virtual void serverSync( bool recurse, bool quotaOnly = false ); 00131 00133 void resetSyncState( ); 00134 00138 void setAlarmsBlocked( bool blocked ); 00140 bool alarmsBlocked() const; 00141 00142 void checkUidValidity(); 00143 00144 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 }; 00145 00146 virtual imapState getContentState() const { return mContentState; } 00147 virtual void setContentState(imapState state) { mContentState = state; } 00148 00149 virtual imapState getSubfolderState() { return mSubfolderState; } 00150 virtual void setSubfolderState(imapState state); 00151 00153 void setImapPath(const TQString &path); 00154 TQString imapPath() const { return mImapPath; } 00155 00157 void setLastUid( ulong uid ); 00158 ulong lastUid(); 00159 00161 KMMsgBase* findByUID( ulong uid ); 00162 00164 void setUidValidity(const TQString &validity) { mUidValidity = validity; } 00165 TQString uidValidity() const { return mUidValidity; } 00166 00169 void clearUidMap() { uidMap.clear(); } 00170 00172 void setAccount(KMAcctCachedImap *acct); 00173 KMAcctCachedImap* account() const; 00174 00176 TQString uidCacheLocation() const; 00177 00179 int readUidCache(); 00180 00182 int writeUidCache(); 00183 00185 int progress() const { return mProgress; } 00186 00187 /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */ 00188 virtual int rename(const TQString& aName, KMFolderDir *aParent=0); 00189 00195 virtual KMMessage* take(int idx); 00196 00202 void takeTemporarily( int idx ); 00203 00204 /* Reimplemented from KMFolderMaildir */ 00205 virtual int addMsg(KMMessage* msg, int* index_return = 0); 00206 /* internal version that doesn't remove the X-UID header */ 00207 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0); 00208 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) { 00209 return addMsgInternal(msg, false, index_return); 00210 } 00211 00212 /* Reimplemented from KMFolderMaildir */ 00213 virtual void removeMsg(int i, bool imapQuiet = false); 00214 virtual void removeMsg( const TQPtrList<KMMsgBase> & msgList, bool imapQuiet = false) 00215 { FolderStorage::removeMsg(msgList, imapQuiet); } 00216 00218 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; } 00219 bool canDeleteMessages() const; 00220 00221 00225 void sendFolderComplete(bool success) 00226 { emit folderComplete(this, success); } 00227 00231 void setSilentUpload( bool silent ) { mSilentUpload = silent; } 00232 bool silentUpload() { return mSilentUpload; } 00233 00234 virtual int createIndexFromContents() { 00235 const int result = KMFolderMaildir::createIndexFromContents(); 00236 reloadUidMap(); 00237 return result; 00238 } 00239 00240 int createIndexFromContentsRecursive(); 00241 00242 //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; } 00243 00249 virtual bool listDirectory(); 00250 00251 virtual void listNamespaces(); 00252 00254 KMFolder* trashFolder() const; 00255 00261 int userRights() const { return mUserRights; } 00262 KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; } 00263 00265 void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState state ); 00266 00276 const QuotaInfo quotaInfo() const { return mQuotaInfo; } 00277 void setQuotaInfo( const QuotaInfo & ); 00278 00280 typedef TQValueVector<KMail::ACLListEntry> ACLList; 00281 const ACLList& aclList() const { return mACLList; } 00282 KMail::ACLJobs::ACLFetchState aclListState() const { return mACLListState; }; 00283 00285 void setACLList( const ACLList& arr ); 00286 00287 // Reimplemented so the mStatusChangedLocally bool can be set 00288 virtual void setStatus( int id, KMMsgStatus status, bool toggle ); 00289 virtual void setStatus( TQValueList<int>& ids, KMMsgStatus status, bool toggle ); 00290 00291 TQString annotationFolderType() const { return mAnnotationFolderType; } 00292 00293 // For kmailicalifaceimpl only 00294 void updateAnnotationFolderType(); 00295 00304 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders }; 00305 00306 IncidencesFor incidencesFor() const { return mIncidencesFor; } 00308 void setIncidencesFor( IncidencesFor incfor ); 00309 00311 bool sharedSeenFlags() const { return mSharedSeenFlags; } 00313 void setSharedSeenFlags( bool b ); 00314 00316 virtual bool isMoveable() const; 00317 00322 TQStringList namespacesToList() { return mNamespacesToList; } 00323 void setNamespacesToList( TQStringList list ) { mNamespacesToList = list; } 00324 00329 const TQString& imapPathForCreation() { return mImapPathCreation; } 00330 void setImapPathForCreation( const TQString& path ) { mImapPathCreation = path; } 00331 00333 bool isCloseToQuota() const; 00334 00336 int permanentFlags() const { return mPermanentFlags; } 00337 00338 00339 TQString folderAttributes() const { return mFolderAttributes; } 00340 00341 virtual bool mailCheckInProgress() const; 00342 00343 protected slots: 00344 void slotGetMessagesData(KIO::Job * job, const TQByteArray & data); 00345 void getMessagesResult(KMail::FolderJob *, bool lastSet); 00346 void slotGetLastMessagesResult(KMail::FolderJob *); 00347 void slotProgress(unsigned long done, unsigned long total); 00348 void slotPutProgress( unsigned long, unsigned long ); 00349 00350 //virtual void slotCheckValidityResult(KIO::Job * job); 00351 void slotSubFolderComplete(KMFolderCachedImap*, bool); 00352 void slotSubFolderCloseToQuotaChanged(); 00353 00354 // Connected to the imap account 00355 void slotConnectionResult( int errorCode, const TQString& errorMsg ); 00356 00357 void slotCheckUidValidityResult( KMail::FolderJob* job ); 00358 void slotPermanentFlags( int flags ); 00359 void slotTestAnnotationResult(KIO::Job *job); 00360 void slotGetAnnotationResult( KIO::Job* ); 00361 void slotMultiUrlGetAnnotationResult( KIO::Job* ); 00362 void slotSetAnnotationResult(KIO::Job *job); 00363 void slotReceivedUserRights( KMFolder* ); 00364 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& ); 00365 00366 void slotMultiSetACLResult(KIO::Job *); 00367 void slotACLChanged( const TQString&, int ); 00368 void slotAnnotationResult(const TQString& entry, const TQString& value, bool found); 00369 void slotAnnotationChanged( const TQString& entry, const TQString& attribute, const TQString& value ); 00370 void slotDeleteMessagesResult(KMail::FolderJob *); 00371 void slotImapStatusChanged(KMFolder* folder, const TQString&, bool); 00372 void slotStorageQuotaResult( const QuotaInfo& ); 00373 void slotQuotaResult( KIO::Job* job ); 00374 00375 protected: 00376 /* returns true if there were messages to delete 00377 on the server */ 00378 bool deleteMessages(); 00379 void listMessages(); 00380 void uploadNewMessages(); 00381 void uploadFlags(); 00382 void uploadSeenFlags(); 00383 void createNewFolders(); 00384 00385 void listDirectory2(); 00386 void createFoldersNewOnServerAndFinishListing( const TQValueVector<int> foldersNewOnServer ); 00387 00388 00391 virtual TQValueList<unsigned long> findNewMessages(); 00394 virtual TQValueList<KMFolderCachedImap*> findNewFolders(); 00395 00397 virtual bool canRemoveFolder() const; 00398 00400 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder, 00401 TQString partSpecifier, const AttachmentStrategy *as ) const; 00402 virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets, 00403 FolderJob::JobType jt, KMFolder *folder ) const; 00404 00405 virtual void timerEvent( TQTimerEvent* ); 00406 00407 /* update progress status */ 00408 void newState( int progress, const TQString& syncStatus ); 00409 00411 KMFolderCachedImap* findParent( const TQString& path, const TQString& name ); 00412 00413 00414 00415 public slots: 00419 void slotSimpleData(KIO::Job * job, const TQByteArray & data); 00420 00424 void slotTroubleshoot(); 00425 00430 void slotListResult( const TQStringList&, const TQStringList&, 00431 const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& ); 00432 00437 void slotCheckNamespace( const TQStringList&, const TQStringList&, 00438 const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& ); 00439 00440 private slots: 00441 void serverSyncInternal(); 00442 void slotIncreaseProgress(); 00443 void slotUpdateLastUid(); 00444 void slotFolderDeletionOnServerFinished(); 00445 void slotRescueDone( KMCommand* command ); 00446 void slotRenameFolderFinished(); 00447 00448 signals: 00449 void folderComplete(KMFolderCachedImap *folder, bool success); 00450 void listComplete( KMFolderCachedImap* ); 00451 00455 void closeToQuotaChanged(); 00456 00457 private: 00458 void setReadOnly( bool readOnly ); 00459 TQString state2String( int state ) const; 00460 void rememberDeletion( int ); 00465 KMCommand* rescueUnsyncedMessages(); 00467 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true ); 00468 00473 void disconnectSubFolderSignals(); 00474 00480 void syncNextSubFolder( bool secondSync ); 00481 00485 void buildSubFolderList(); 00486 00488 enum { 00489 SYNC_STATE_INITIAL, 00490 SYNC_STATE_TEST_ANNOTATIONS, 00491 SYNC_STATE_PUT_MESSAGES, 00492 SYNC_STATE_UPLOAD_FLAGS, 00493 SYNC_STATE_CREATE_SUBFOLDERS, 00494 SYNC_STATE_LIST_NAMESPACES, 00495 SYNC_STATE_LIST_SUBFOLDERS, 00496 SYNC_STATE_LIST_SUBFOLDERS2, 00497 SYNC_STATE_DELETE_SUBFOLDERS, 00498 SYNC_STATE_LIST_MESSAGES, 00499 SYNC_STATE_DELETE_MESSAGES, 00500 SYNC_STATE_EXPUNGE_MESSAGES, 00501 SYNC_STATE_GET_MESSAGES, 00502 SYNC_STATE_HANDLE_INBOX, 00503 SYNC_STATE_GET_USERRIGHTS, 00504 SYNC_STATE_GET_ANNOTATIONS, 00505 SYNC_STATE_SET_ANNOTATIONS, 00506 SYNC_STATE_GET_ACLS, 00507 SYNC_STATE_SET_ACLS, 00508 SYNC_STATE_GET_QUOTA, 00509 SYNC_STATE_FIND_SUBFOLDERS, 00510 SYNC_STATE_SYNC_SUBFOLDERS, 00511 SYNC_STATE_CHECK_UIDVALIDITY, 00512 SYNC_STATE_RENAME_FOLDER, 00513 SYNC_STATE_CLOSE, 00514 SYNC_STATE_GET_SUBFOLDER_QUOTA 00515 } mSyncState; 00516 00517 int mProgress; 00518 int mStatusFlagsJobs; 00519 00520 TQString mUidValidity; 00521 TQString mImapPath; 00522 imapState mContentState, mSubfolderState; 00523 TQStringList mSubfolderNames, mSubfolderPaths, 00524 mSubfolderMimeTypes, mSubfolderAttributes; 00525 TQString mFolderAttributes; 00526 TQString mAnnotationFolderType; 00527 IncidencesFor mIncidencesFor; 00528 bool mSharedSeenFlags; 00529 00530 bool mHasInbox; 00531 bool mIsSelected; 00532 bool mCheckFlags; 00533 bool mReadOnly; 00534 mutable TQGuardedPtr<KMAcctCachedImap> mAccount; 00535 00536 TQIntDict<int> uidsOnServer; 00537 TQValueList<ulong> uidsForDeletionOnServer; 00538 TQValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload; 00539 TQValueList<ulong> mUidsForDownload; 00540 TQStringList foldersForDeletionOnServer; 00541 00542 TQValueList< TQGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync; 00543 KMFolderCachedImap* mCurrentSubfolder; 00544 00548 TQMap<ulong,int> uidMap; 00549 bool uidMapDirty; 00550 void reloadUidMap(); 00551 int uidWriteTimer; 00552 00562 ulong mLastUid; 00567 ulong mTentativeHighestUid; 00568 00572 bool mFoundAnIMAPDigest; 00573 00574 int mUserRights, mOldUserRights; 00575 KMail::ACLJobs::ACLFetchState mUserRightsState; 00576 ACLList mACLList; 00577 KMail::ACLJobs::ACLFetchState mACLListState; 00578 00579 bool mSilentUpload; 00580 bool mFolderRemoved; 00581 //bool mHoldSyncs; 00582 bool mRecurse; 00583 bool mQuotaOnly; 00584 00586 bool mAnnotationFolderTypeChanged; 00588 bool mIncidencesForChanged; 00590 bool mSharedSeenFlagsChanged; 00591 00598 std::set<ulong> mUIDsOfLocallyChangedStatuses; 00599 00604 bool mStatusChangedLocally; 00605 00606 TQStringList mNamespacesToList; 00607 int mNamespacesToCheck; 00608 bool mPersonalNamespacesCheckDone; 00609 TQString mImapPathCreation; 00610 00611 QuotaInfo mQuotaInfo; 00612 00615 bool mSomeSubFolderCloseToQuotaChanged; 00616 00617 TQMap<ulong,void*> mDeletedUIDsSinceLastSync; 00618 bool mAlarmsBlocked; 00619 00620 TQValueList<KMFolder*> mToBeDeletedAfterRescue; 00621 int mRescueCommandCount; 00622 00623 TQValueList< TQGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders; 00624 int mPermanentFlags; 00625 }; 00626 00627 #endif /*kmfoldercachedimap_h*/