00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef kmfoldercachedimap_h
00033 #define kmfoldercachedimap_h
00034
00035 #include <kdialogbase.h>
00036 #include <kstandarddirs.h>
00037 #include <qvaluelist.h>
00038 #include <qvaluevector.h>
00039 #include <qptrlist.h>
00040 #include <qdialog.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 QComboBox;
00057 class QRadioButton;
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 public:
00070 enum SelectedOperation {
00071 None = -1,
00072 ReindexCurrent = 0,
00073 ReindexRecursive = 1,
00074 ReindexAll = 2,
00075 RefreshCache
00076 };
00077
00078 DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00079
00080 static int run();
00081
00082 private slots:
00083 void slotDone();
00084 void slotChanged();
00085 private:
00086 QRadioButton *mIndexButton, *mCacheButton;
00087 QComboBox *mIndexScope;
00088 QButtonGroup *mButtonGroup;
00089 int rc;
00090 };
00091
00092 class KMFolderCachedImap : public KMFolderMaildir
00093 {
00094 Q_OBJECT
00095
00096 public:
00097 static QString cacheLocation() {
00098 return locateLocal("data", "kmail/dimap" );
00099 }
00100
00104 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00105 virtual ~KMFolderCachedImap();
00106
00108 void reallyDoClose(const char* owner);
00109
00111 void initializeFrom( KMFolderCachedImap* parent );
00112
00113 virtual void readConfig();
00114 virtual void writeConfig();
00115
00116 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00117
00119 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00120
00122 virtual int create();
00123
00125 virtual void remove();
00126
00128 virtual void serverSync( bool recurse, bool quotaOnly = false );
00129
00131 void resetSyncState( );
00132
00136 void setAlarmsBlocked( bool blocked );
00138 bool alarmsBlocked() const;
00139
00140 void checkUidValidity();
00141
00142 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00143
00144 virtual imapState getContentState() const { return mContentState; }
00145 virtual void setContentState(imapState state) { mContentState = state; }
00146
00147 virtual imapState getSubfolderState() { return mSubfolderState; }
00148 virtual void setSubfolderState(imapState state);
00149
00151 void setImapPath(const QString &path);
00152 QString imapPath() const { return mImapPath; }
00153
00155 void setLastUid( ulong uid );
00156 ulong lastUid();
00157
00159 KMMsgBase* findByUID( ulong uid );
00160
00162 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00163 QString uidValidity() const { return mUidValidity; }
00164
00167 void clearUidMap() { uidMap.clear(); }
00168
00170 void setAccount(KMAcctCachedImap *acct);
00171 KMAcctCachedImap* account() const;
00172
00174 QString uidCacheLocation() const;
00175
00177 int readUidCache();
00178
00180 int writeUidCache();
00181
00183 int progress() const { return mProgress; }
00184
00185
00186 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00187
00193 virtual KMMessage* take(int idx);
00194
00200 void takeTemporarily( int idx );
00201
00202
00203 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00204
00205 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00206 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00207
00208 return addMsgInternal(msg, false, index_return);
00209 }
00210
00211
00212 virtual void removeMsg(int i, bool imapQuiet = false);
00213 virtual void removeMsg( const QPtrList<KMMsgBase> & msgList, bool imapQuiet = false)
00214 { FolderStorage::removeMsg(msgList, imapQuiet); }
00215
00217 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00218 bool canDeleteMessages() const;
00219
00220
00224 void sendFolderComplete(bool success)
00225 { emit folderComplete(this, success); }
00226
00230 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00231 bool silentUpload() { return mSilentUpload; }
00232
00233 virtual int createIndexFromContents() {
00234 const int result = KMFolderMaildir::createIndexFromContents();
00235 reloadUidMap();
00236 return result;
00237 }
00238
00239 int createIndexFromContentsRecursive();
00240
00241
00242
00248 virtual bool listDirectory();
00249
00250 virtual void listNamespaces();
00251
00253 KMFolder* trashFolder() const;
00254
00260 int userRights() const { return mUserRights; }
00261 KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; }
00262
00264 void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState state );
00265
00275 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00276 void setQuotaInfo( const QuotaInfo & );
00277
00279 typedef QValueVector<KMail::ACLListEntry> ACLList;
00280 const ACLList& aclList() const { return mACLList; }
00281 KMail::ACLJobs::ACLFetchState aclListState() const { return mACLListState; };
00282
00284 void setACLList( const ACLList& arr );
00285
00286
00287 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00288 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00289
00290 QString annotationFolderType() const { return mAnnotationFolderType; }
00291
00292
00293 void updateAnnotationFolderType();
00294
00303 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00304
00305 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00307 void setIncidencesFor( IncidencesFor incfor );
00308
00310 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00312 void setSharedSeenFlags( bool b );
00313
00315 virtual bool isMoveable() const;
00316
00321 QStringList namespacesToList() { return mNamespacesToList; }
00322 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00323
00328 const QString& imapPathForCreation() { return mImapPathCreation; }
00329 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00330
00332 bool isCloseToQuota() const;
00333
00335 int permanentFlags() const { return mPermanentFlags; }
00336
00337
00338 QString folderAttributes() const { return mFolderAttributes; }
00339
00340 virtual bool mailCheckInProgress() const;
00341
00342 bool isInInitialState() const { return mSyncState == SYNC_STATE_INITIAL; }
00343
00344 protected slots:
00345 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00346 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00347 void slotGetLastMessagesResult(KMail::FolderJob *);
00348 void slotProgress(unsigned long done, unsigned long total);
00349 void slotPutProgress( unsigned long, unsigned long );
00350
00351
00352 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00353 void slotSubFolderCloseToQuotaChanged();
00354
00355
00356 void slotConnectionResult( int errorCode, const QString& errorMsg );
00357
00358 void slotCheckUidValidityResult( KMail::FolderJob* job );
00359 void slotPermanentFlags( int flags );
00360 void slotTestAnnotationResult(KIO::Job *job);
00361 void slotGetAnnotationResult( KIO::Job* );
00362 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00363 void slotSetAnnotationResult(KIO::Job *job);
00364 void slotReceivedUserRights( KMFolder* );
00365 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00366
00367 void slotMultiSetACLResult(KIO::Job *);
00368 void slotACLChanged( const QString&, int );
00369 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00370 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00371 void slotDeleteMessagesResult(KMail::FolderJob *);
00372 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00373 void slotStorageQuotaResult( const QuotaInfo& );
00374 void slotQuotaResult( KIO::Job* job );
00375
00376 protected:
00377
00378
00379 bool deleteMessages();
00380 void listMessages();
00381 void uploadNewMessages();
00382 void uploadFlags();
00383 void uploadSeenFlags();
00384 void createNewFolders();
00385
00386 void listDirectory2();
00387 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00388
00389
00392 virtual QValueList<unsigned long> findNewMessages();
00395 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00396
00398 virtual bool canRemoveFolder() const;
00399
00401 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00402 QString partSpecifier, const AttachmentStrategy *as ) const;
00403 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00404 FolderJob::JobType jt, KMFolder *folder ) const;
00405
00406 virtual void timerEvent( QTimerEvent* );
00407
00408
00409 void newState( int progress, const QString& syncStatus );
00410
00412 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00413
00414
00415
00416 public slots:
00420 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00421
00425 void slotTroubleshoot();
00426
00431 void slotListResult( const QStringList&, const QStringList&,
00432 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00433
00438 void slotCheckNamespace( const QStringList&, const QStringList&,
00439 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00440
00441 private slots:
00442 void serverSyncInternal();
00443 void slotIncreaseProgress();
00444 void slotUpdateLastUid();
00445 void slotFolderDeletionOnServerFinished();
00446 void slotRescueDone( KMCommand* command );
00447 void slotRenameFolderFinished();
00448
00449 signals:
00450 void folderComplete(KMFolderCachedImap *folder, bool success);
00451 void listComplete( KMFolderCachedImap* );
00452
00456 void closeToQuotaChanged();
00457
00458 private:
00459 void setReadOnly( bool readOnly );
00460 QString state2String( int state ) const;
00461 void rememberDeletion( int );
00466 KMCommand* rescueUnsyncedMessages();
00468 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00469
00474 void disconnectSubFolderSignals();
00475
00481 void syncNextSubFolder( bool secondSync );
00482
00486 void buildSubFolderList();
00487
00489 enum {
00490 SYNC_STATE_INITIAL,
00491 SYNC_STATE_TEST_ANNOTATIONS,
00492 SYNC_STATE_PUT_MESSAGES,
00493 SYNC_STATE_UPLOAD_FLAGS,
00494 SYNC_STATE_CREATE_SUBFOLDERS,
00495 SYNC_STATE_LIST_NAMESPACES,
00496 SYNC_STATE_LIST_SUBFOLDERS,
00497 SYNC_STATE_LIST_SUBFOLDERS2,
00498 SYNC_STATE_DELETE_SUBFOLDERS,
00499 SYNC_STATE_LIST_MESSAGES,
00500 SYNC_STATE_DELETE_MESSAGES,
00501 SYNC_STATE_EXPUNGE_MESSAGES,
00502 SYNC_STATE_GET_MESSAGES,
00503 SYNC_STATE_HANDLE_INBOX,
00504 SYNC_STATE_GET_USERRIGHTS,
00505 SYNC_STATE_GET_ANNOTATIONS,
00506 SYNC_STATE_SET_ANNOTATIONS,
00507 SYNC_STATE_GET_ACLS,
00508 SYNC_STATE_SET_ACLS,
00509 SYNC_STATE_GET_QUOTA,
00510 SYNC_STATE_FIND_SUBFOLDERS,
00511 SYNC_STATE_SYNC_SUBFOLDERS,
00512 SYNC_STATE_CHECK_UIDVALIDITY,
00513 SYNC_STATE_RENAME_FOLDER,
00514 SYNC_STATE_CLOSE,
00515 SYNC_STATE_GET_SUBFOLDER_QUOTA
00516 } mSyncState;
00517
00518 int mProgress;
00519 int mStatusFlagsJobs;
00520
00521 QString mUidValidity;
00522 QString mImapPath;
00523 imapState mContentState, mSubfolderState;
00524 QStringList mSubfolderNames, mSubfolderPaths,
00525 mSubfolderMimeTypes, mSubfolderAttributes;
00526 QString mFolderAttributes;
00527 QString mAnnotationFolderType;
00528 IncidencesFor mIncidencesFor;
00529 bool mSharedSeenFlags;
00530
00531 bool mHasInbox;
00532 bool mIsSelected;
00533 bool mCheckFlags;
00534 bool mReadOnly;
00535 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00536
00537 QIntDict<int> uidsOnServer;
00538 QValueList<ulong> uidsForDeletionOnServer;
00539 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00540 QValueList<ulong> mUidsForDownload;
00541 QStringList foldersForDeletionOnServer;
00542
00543 QValueList< QGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync;
00544 KMFolderCachedImap* mCurrentSubfolder;
00545
00549 QMap<ulong,int> uidMap;
00550 bool uidMapDirty;
00551 void reloadUidMap();
00552 int uidWriteTimer;
00553
00563 ulong mLastUid;
00568 ulong mTentativeHighestUid;
00569
00573 bool mFoundAnIMAPDigest;
00574
00575 int mUserRights, mOldUserRights;
00576 KMail::ACLJobs::ACLFetchState mUserRightsState;
00577 ACLList mACLList;
00578 KMail::ACLJobs::ACLFetchState mACLListState;
00579
00580 bool mSilentUpload;
00581 bool mFolderRemoved;
00582
00583 bool mRecurse;
00584 bool mQuotaOnly;
00585
00587 bool mAnnotationFolderTypeChanged;
00589 bool mIncidencesForChanged;
00591 bool mSharedSeenFlagsChanged;
00592
00599 std::set<ulong> mUIDsOfLocallyChangedStatuses;
00600
00605 bool mStatusChangedLocally;
00606
00607 QStringList mNamespacesToList;
00608 int mNamespacesToCheck;
00609 bool mPersonalNamespacesCheckDone;
00610 QString mImapPathCreation;
00611
00612 QuotaInfo mQuotaInfo;
00613
00616 bool mSomeSubFolderCloseToQuotaChanged;
00617
00618 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00619 bool mAlarmsBlocked;
00620
00621 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00622 int mRescueCommandCount;
00623
00624 QValueList< QGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders;
00625 int mPermanentFlags;
00626 };
00627
00628 #endif