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
00242 void markForReindexing();
00243
00244
00245
00251 virtual bool listDirectory();
00252
00253 virtual void listNamespaces();
00254
00256 KMFolder* trashFolder() const;
00257
00263 int userRights() const { return mUserRights; }
00264 KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; }
00265
00267 void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState state );
00268
00278 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00279 void setQuotaInfo( const QuotaInfo & );
00280
00282 typedef QValueVector<KMail::ACLListEntry> ACLList;
00283 const ACLList& aclList() const { return mACLList; }
00284 KMail::ACLJobs::ACLFetchState aclListState() const { return mACLListState; };
00285
00287 void setACLList( const ACLList& arr );
00288
00289
00290 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00291 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00292
00293 QString annotationFolderType() const { return mAnnotationFolderType; }
00294
00295
00296 void updateAnnotationFolderType();
00297
00306 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00307
00308 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00310 void setIncidencesFor( IncidencesFor incfor );
00311
00313 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00315 void setSharedSeenFlags( bool b );
00316
00318 virtual bool isMoveable() const;
00319
00324 QStringList namespacesToList() { return mNamespacesToList; }
00325 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00326
00331 const QString& imapPathForCreation() { return mImapPathCreation; }
00332 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00333
00335 bool isCloseToQuota() const;
00336
00338 int permanentFlags() const { return mPermanentFlags; }
00339
00340
00341 QString folderAttributes() const { return mFolderAttributes; }
00342
00343 virtual bool mailCheckInProgress() const;
00344
00345 bool isInInitialState() const { return mSyncState == SYNC_STATE_INITIAL; }
00346
00347 protected slots:
00348 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00349 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00350 void slotGetLastMessagesResult(KMail::FolderJob *);
00351 void slotProgress(unsigned long done, unsigned long total);
00352 void slotPutProgress( unsigned long, unsigned long );
00353
00354
00355 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00356 void slotSubFolderCloseToQuotaChanged();
00357
00358
00359 void slotConnectionResult( int errorCode, const QString& errorMsg );
00360
00361 void slotCheckUidValidityResult( KMail::FolderJob* job );
00362 void slotPermanentFlags( int flags );
00363 void slotTestAnnotationResult(KIO::Job *job);
00364 void slotGetAnnotationResult( KIO::Job* );
00365 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00366 void slotSetAnnotationResult(KIO::Job *job);
00367 void slotReceivedUserRights( KMFolder* );
00368 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00369
00370 void slotMultiSetACLResult(KIO::Job *);
00371 void slotACLChanged( const QString&, int );
00372 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00373 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00374 void slotDeleteMessagesResult(KMail::FolderJob *);
00375 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00376 void slotStorageQuotaResult( const QuotaInfo& );
00377 void slotQuotaResult( KIO::Job* job );
00378
00379 protected:
00380
00381
00382 bool deleteMessages();
00383 void listMessages();
00384 void uploadNewMessages();
00385 void uploadFlags();
00386 void uploadSeenFlags();
00387 void createNewFolders();
00388
00389 void listDirectory2();
00390 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00391
00392
00395 virtual QValueList<unsigned long> findNewMessages();
00398 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00399
00401 virtual bool canRemoveFolder() const;
00402
00404 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00405 QString partSpecifier, const AttachmentStrategy *as ) const;
00406 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00407 FolderJob::JobType jt, KMFolder *folder ) const;
00408
00409 virtual void timerEvent( QTimerEvent* );
00410
00411
00412 void newState( int progress, const QString& syncStatus );
00413
00415 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00416
00417
00418
00419 public slots:
00423 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00424
00428 void slotTroubleshoot();
00429
00434 void slotListResult( const QStringList&, const QStringList&,
00435 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00436
00441 void slotCheckNamespace( const QStringList&, const QStringList&,
00442 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00443
00444 private slots:
00445 void serverSyncInternal();
00446 void slotIncreaseProgress();
00447 void slotUpdateLastUid();
00448 void slotFolderDeletionOnServerFinished();
00449 void slotRescueDone( KMCommand* command );
00450 void slotRenameFolderFinished();
00451
00452 signals:
00453 void folderComplete(KMFolderCachedImap *folder, bool success);
00454 void listComplete( KMFolderCachedImap* );
00455
00459 void closeToQuotaChanged();
00460
00461 private:
00462 void setReadOnly( bool readOnly );
00463 QString state2String( int state ) const;
00464 void rememberDeletion( int );
00469 KMCommand* rescueUnsyncedMessages();
00471 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00472
00477 void disconnectSubFolderSignals();
00478
00484 void syncNextSubFolder( bool secondSync );
00485
00489 void buildSubFolderList();
00490
00492 enum {
00493 SYNC_STATE_INITIAL,
00494 SYNC_STATE_TEST_ANNOTATIONS,
00495 SYNC_STATE_PUT_MESSAGES,
00496 SYNC_STATE_UPLOAD_FLAGS,
00497 SYNC_STATE_CREATE_SUBFOLDERS,
00498 SYNC_STATE_LIST_NAMESPACES,
00499 SYNC_STATE_LIST_SUBFOLDERS,
00500 SYNC_STATE_LIST_SUBFOLDERS2,
00501 SYNC_STATE_DELETE_SUBFOLDERS,
00502 SYNC_STATE_LIST_MESSAGES,
00503 SYNC_STATE_DELETE_MESSAGES,
00504 SYNC_STATE_EXPUNGE_MESSAGES,
00505 SYNC_STATE_GET_MESSAGES,
00506 SYNC_STATE_HANDLE_INBOX,
00507 SYNC_STATE_GET_USERRIGHTS,
00508 SYNC_STATE_GET_ANNOTATIONS,
00509 SYNC_STATE_SET_ANNOTATIONS,
00510 SYNC_STATE_GET_ACLS,
00511 SYNC_STATE_SET_ACLS,
00512 SYNC_STATE_GET_QUOTA,
00513 SYNC_STATE_FIND_SUBFOLDERS,
00514 SYNC_STATE_SYNC_SUBFOLDERS,
00515 SYNC_STATE_CHECK_UIDVALIDITY,
00516 SYNC_STATE_RENAME_FOLDER,
00517 SYNC_STATE_CLOSE,
00518 SYNC_STATE_GET_SUBFOLDER_QUOTA
00519 } mSyncState;
00520
00521 int mProgress;
00522 int mStatusFlagsJobs;
00523
00524 QString mUidValidity;
00525 QString mImapPath;
00526 imapState mContentState, mSubfolderState;
00527 QStringList mSubfolderNames, mSubfolderPaths,
00528 mSubfolderMimeTypes, mSubfolderAttributes;
00529 QString mFolderAttributes;
00530 QString mAnnotationFolderType;
00531 IncidencesFor mIncidencesFor;
00532 bool mSharedSeenFlags;
00533
00534 bool mHasInbox;
00535 bool mIsSelected;
00536 bool mCheckFlags;
00537 bool mReadOnly;
00538 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00539
00540 QIntDict<int> uidsOnServer;
00541 QValueList<ulong> uidsForDeletionOnServer;
00542 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00543 QValueList<ulong> mUidsForDownload;
00544 QStringList foldersForDeletionOnServer;
00545
00546 QValueList< QGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync;
00547 KMFolderCachedImap* mCurrentSubfolder;
00548
00552 QMap<ulong,int> uidMap;
00553 bool uidMapDirty;
00554 void reloadUidMap();
00555 int uidWriteTimer;
00556
00566 ulong mLastUid;
00571 ulong mTentativeHighestUid;
00572
00576 bool mFoundAnIMAPDigest;
00577
00578 int mUserRights, mOldUserRights;
00579 KMail::ACLJobs::ACLFetchState mUserRightsState;
00580 ACLList mACLList;
00581 KMail::ACLJobs::ACLFetchState mACLListState;
00582
00583 bool mSilentUpload;
00584 bool mFolderRemoved;
00585
00586 bool mRecurse;
00587 bool mQuotaOnly;
00588
00590 bool mAnnotationFolderTypeChanged;
00592 bool mIncidencesForChanged;
00594 bool mSharedSeenFlagsChanged;
00595
00602 std::set<ulong> mUIDsOfLocallyChangedStatuses;
00603
00608 bool mStatusChangedLocally;
00609
00610 QStringList mNamespacesToList;
00611 int mNamespacesToCheck;
00612 bool mPersonalNamespacesCheckDone;
00613 QString mImapPathCreation;
00614
00615 QuotaInfo mQuotaInfo;
00616
00619 bool mSomeSubFolderCloseToQuotaChanged;
00620
00621 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00622 bool mAlarmsBlocked;
00623
00624 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00625 int mRescueCommandCount;
00626
00627 QValueList< QGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders;
00628 int mPermanentFlags;
00629 };
00630
00631 #endif