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 );
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() { 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 return addMsgInternal(msg, false, index_return);
00208 }
00209
00210
00211 virtual void removeMsg(int i, bool imapQuiet = false);
00212 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00213 { FolderStorage::removeMsg(msgList, imapQuiet); }
00214
00216 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00217 bool canDeleteMessages() const;
00218
00219
00223 void sendFolderComplete(bool success)
00224 { emit folderComplete(this, success); }
00225
00229 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00230 bool silentUpload() { return mSilentUpload; }
00231
00232 virtual int createIndexFromContents() {
00233 const int result = KMFolderMaildir::createIndexFromContents();
00234 reloadUidMap();
00235 return result;
00236 }
00237
00238 int createIndexFromContentsRecursive();
00239
00240
00241
00247 virtual bool listDirectory();
00248
00249 virtual void listNamespaces();
00250
00252 KMFolder* trashFolder() const;
00253
00258 int userRights() const { return mUserRights; }
00259
00261 void setUserRights( unsigned int userRights );
00262
00272 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00273 void setQuotaInfo( const QuotaInfo & );
00274
00276 typedef QValueVector<KMail::ACLListEntry> ACLList;
00277 const ACLList& aclList() const { return mACLList; }
00278
00280 void setACLList( const ACLList& arr );
00281
00282
00283 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00284 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00285
00286 QString annotationFolderType() const { return mAnnotationFolderType; }
00287
00288
00289 void updateAnnotationFolderType();
00290
00299 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00300
00301 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00303 void setIncidencesFor( IncidencesFor incfor );
00304
00306 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00308 void setSharedSeenFlags( bool b );
00309
00311 virtual bool isMoveable() const;
00312
00317 QStringList namespacesToList() { return mNamespacesToList; }
00318 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00319
00324 const QString& imapPathForCreation() { return mImapPathCreation; }
00325 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00326
00328 bool isCloseToQuota() const;
00329
00331 int permanentFlags() const { return mPermanentFlags; }
00332
00333
00334 QString folderAttributes() const { return mFolderAttributes; }
00335
00336 protected slots:
00337 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00338 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00339 void slotGetLastMessagesResult(KMail::FolderJob *);
00340 void slotProgress(unsigned long done, unsigned long total);
00341 void slotPutProgress( unsigned long, unsigned long );
00342
00343
00344 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00345
00346
00347 void slotConnectionResult( int errorCode, const QString& errorMsg );
00348
00349 void slotCheckUidValidityResult( KMail::FolderJob* job );
00350 void slotPermanentFlags( int flags );
00351 void slotTestAnnotationResult(KIO::Job *job);
00352 void slotGetAnnotationResult( KIO::Job* );
00353 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00354 void slotSetAnnotationResult(KIO::Job *job);
00355 void slotReceivedUserRights( KMFolder* );
00356 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00357
00358 void slotMultiSetACLResult(KIO::Job *);
00359 void slotACLChanged( const QString&, int );
00360 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00361 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00362 void slotDeleteMessagesResult(KMail::FolderJob *);
00363 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00364 void slotStorageQuotaResult( const QuotaInfo& );
00365 void slotQuotaResult( KIO::Job* job );
00366
00367 protected:
00368
00369
00370 bool deleteMessages();
00371 void listMessages();
00372 void uploadNewMessages();
00373 void uploadFlags();
00374 void uploadSeenFlags();
00375 void createNewFolders();
00376
00377 void listDirectory2();
00378 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00379
00380
00383 virtual QValueList<unsigned long> findNewMessages();
00386 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00387
00389 virtual bool canRemoveFolder() const;
00390
00392 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00393 QString partSpecifier, const AttachmentStrategy *as ) const;
00394 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00395 FolderJob::JobType jt, KMFolder *folder ) const;
00396
00397 virtual void timerEvent( QTimerEvent* );
00398
00399
00400 void newState( int progress, const QString& syncStatus );
00401
00403 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00404
00405
00406
00407 public slots:
00411 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00412
00416 void slotTroubleshoot();
00417
00422 void slotListResult( const QStringList&, const QStringList&,
00423 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00424
00429 void slotCheckNamespace( const QStringList&, const QStringList&,
00430 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00431
00432 private slots:
00433 void serverSyncInternal();
00434 void slotIncreaseProgress();
00435 void slotUpdateLastUid();
00436 void slotFolderDeletionOnServerFinished();
00437 void slotRescueDone( KMCommand* command );
00438 void slotRenameFolderFinished();
00439
00440 signals:
00441 void folderComplete(KMFolderCachedImap *folder, bool success);
00442 void listComplete( KMFolderCachedImap* );
00443
00447 void syncState( int state, int number );
00448
00449 private:
00450 void setReadOnly( bool readOnly );
00451 QString state2String( int state ) const;
00452 void rememberDeletion( int );
00457 KMCommand* rescueUnsyncedMessages();
00459 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00460
00462 enum {
00463 SYNC_STATE_INITIAL,
00464 SYNC_STATE_TEST_ANNOTATIONS,
00465 SYNC_STATE_PUT_MESSAGES,
00466 SYNC_STATE_UPLOAD_FLAGS,
00467 SYNC_STATE_CREATE_SUBFOLDERS,
00468 SYNC_STATE_LIST_NAMESPACES,
00469 SYNC_STATE_LIST_SUBFOLDERS,
00470 SYNC_STATE_LIST_SUBFOLDERS2,
00471 SYNC_STATE_DELETE_SUBFOLDERS,
00472 SYNC_STATE_LIST_MESSAGES,
00473 SYNC_STATE_DELETE_MESSAGES,
00474 SYNC_STATE_EXPUNGE_MESSAGES,
00475 SYNC_STATE_GET_MESSAGES,
00476 SYNC_STATE_HANDLE_INBOX,
00477 SYNC_STATE_GET_USERRIGHTS,
00478 SYNC_STATE_GET_ANNOTATIONS,
00479 SYNC_STATE_SET_ANNOTATIONS,
00480 SYNC_STATE_GET_ACLS,
00481 SYNC_STATE_SET_ACLS,
00482 SYNC_STATE_GET_QUOTA,
00483 SYNC_STATE_FIND_SUBFOLDERS,
00484 SYNC_STATE_SYNC_SUBFOLDERS,
00485 SYNC_STATE_CHECK_UIDVALIDITY,
00486 SYNC_STATE_RENAME_FOLDER
00487 } mSyncState;
00488
00489 int mProgress;
00490 int mStatusFlagsJobs;
00491
00492 QString mUidValidity;
00493 QString mImapPath;
00494 imapState mContentState, mSubfolderState;
00495 QStringList mSubfolderNames, mSubfolderPaths,
00496 mSubfolderMimeTypes, mSubfolderAttributes;
00497 QString mFolderAttributes;
00498 QString mAnnotationFolderType;
00499 IncidencesFor mIncidencesFor;
00500 bool mSharedSeenFlags;
00501
00502 bool mHasInbox;
00503 bool mIsSelected;
00504 bool mCheckFlags;
00505 bool mReadOnly;
00506 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00507
00508 QIntDict<int> uidsOnServer;
00509 QValueList<ulong> uidsForDeletionOnServer;
00510 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00511 QValueList<ulong> mUidsForDownload;
00512 QStringList foldersForDeletionOnServer;
00513
00514 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00515 KMFolderCachedImap* mCurrentSubfolder;
00516
00520 QMap<ulong,int> uidMap;
00521 bool uidMapDirty;
00522 void reloadUidMap();
00523 int uidWriteTimer;
00524
00534 ulong mLastUid;
00539 ulong mTentativeHighestUid;
00540
00544 bool mFoundAnIMAPDigest;
00545
00546 int mUserRights, mOldUserRights;
00547 ACLList mACLList;
00548
00549 bool mSilentUpload;
00550 bool mFolderRemoved;
00551
00552 bool mRecurse;
00553
00555 bool mAnnotationFolderTypeChanged;
00557 bool mIncidencesForChanged;
00559 bool mSharedSeenFlagsChanged;
00560
00567 std::set<ulong> mUIDsOfLocallyChangedStatuses;
00568
00573 bool mStatusChangedLocally;
00574
00575 QStringList mNamespacesToList;
00576 int mNamespacesToCheck;
00577 bool mPersonalNamespacesCheckDone;
00578 QString mImapPathCreation;
00579
00580 QuotaInfo mQuotaInfo;
00581 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00582 bool mAlarmsBlocked;
00583
00584 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00585 int mRescueCommandCount;
00586
00587 int mPermanentFlags;
00588 };
00589
00590 #endif