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 using KMail::FolderJob;
00051 using KMail::QuotaInfo;
00052 class KMCommand;
00053
00054 class QComboBox;
00055 class QRadioButton;
00056
00057 namespace KMail {
00058 class AttachmentStrategy;
00059 class ImapAccountBase;
00060 struct ACLListEntry;
00061 }
00062 using KMail::AttachmentStrategy;
00063
00064 class DImapTroubleShootDialog : public KDialogBase
00065 {
00066 Q_OBJECT
00067 public:
00068 enum SelectedOperation {
00069 None = -1,
00070 ReindexCurrent = 0,
00071 ReindexRecursive = 1,
00072 ReindexAll = 2,
00073 RefreshCache
00074 };
00075
00076 DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00077
00078 static int run();
00079
00080 private slots:
00081 void slotDone();
00082
00083 private:
00084 QRadioButton *mIndexButton, *mCacheButton;
00085 QComboBox *mIndexScope;
00086 int rc;
00087 };
00088
00089 class KMFolderCachedImap : public KMFolderMaildir
00090 {
00091 Q_OBJECT
00092
00093 public:
00094 static QString cacheLocation() {
00095 return locateLocal("data", "kmail/dimap" );
00096 }
00097
00101 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00102 virtual ~KMFolderCachedImap();
00103
00105 void reallyDoClose(const char* owner);
00106
00108 void initializeFrom( KMFolderCachedImap* parent );
00109
00110 virtual void readConfig();
00111 virtual void writeConfig();
00112
00113 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00114
00116 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00117
00119 virtual int create();
00120
00122 virtual void remove();
00123
00125 virtual void serverSync( bool recurse );
00126
00128 void resetSyncState( );
00129
00133 void setAlarmsBlocked( bool blocked );
00135 bool alarmsBlocked() const;
00136
00137 void checkUidValidity();
00138
00139 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00140
00141 virtual imapState getContentState() { return mContentState; }
00142 virtual void setContentState(imapState state) { mContentState = state; }
00143
00144 virtual imapState getSubfolderState() { return mSubfolderState; }
00145 virtual void setSubfolderState(imapState state);
00146
00148 void setImapPath(const QString &path);
00149 QString imapPath() const { return mImapPath; }
00150
00152 void setLastUid( ulong uid );
00153 ulong lastUid();
00154
00156 KMMsgBase* findByUID( ulong uid );
00157
00159 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00160 QString uidValidity() const { return mUidValidity; }
00161
00164 void clearUidMap() { uidMap.clear(); }
00165
00167 void setAccount(KMAcctCachedImap *acct);
00168 KMAcctCachedImap* account() const;
00169
00171 QString uidCacheLocation() const;
00172
00174 int readUidCache();
00175
00177 int writeUidCache();
00178
00180 int progress() const { return mProgress; }
00181
00182
00183 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00184
00185
00186 virtual KMMessage* take(int idx);
00187
00188 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00189
00190 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00191 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00192 return addMsgInternal(msg, false, index_return);
00193 }
00194
00195
00196 virtual void removeMsg(int i, bool imapQuiet = false);
00197 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00198 { FolderStorage::removeMsg(msgList, imapQuiet); }
00199
00201 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00202 bool canDeleteMessages() const;
00203
00204
00208 void sendFolderComplete(bool success)
00209 { emit folderComplete(this, success); }
00210
00214 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00215 bool silentUpload() { return mSilentUpload; }
00216
00217 virtual int createIndexFromContents()
00218 { return KMFolderMaildir::createIndexFromContents(); }
00219
00220 int createIndexFromContentsRecursive();
00221
00222
00223
00229 virtual bool listDirectory();
00230
00231 virtual void listNamespaces();
00232
00234 KMFolder* trashFolder() const;
00235
00240 int userRights() const { return mUserRights; }
00241
00243 void setUserRights( unsigned int userRights );
00244
00254 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00255 void setQuotaInfo( const QuotaInfo & );
00256
00258 typedef QValueVector<KMail::ACLListEntry> ACLList;
00259 const ACLList& aclList() const { return mACLList; }
00260
00262 void setACLList( const ACLList& arr );
00263
00264
00265 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00266 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00267
00268 QString annotationFolderType() const { return mAnnotationFolderType; }
00269
00270
00271 void updateAnnotationFolderType();
00272
00281 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00282
00283 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00285 void setIncidencesFor( IncidencesFor incfor );
00286
00288 virtual bool isMoveable() const;
00289
00294 QStringList namespacesToList() { return mNamespacesToList; }
00295 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00296
00301 const QString& imapPathForCreation() { return mImapPathCreation; }
00302 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00303
00305 bool isCloseToQuota() const;
00306
00308 int permanentFlags() const { return mPermanentFlags; }
00309
00310
00311 QString folderAttributes() const { return mFolderAttributes; }
00312
00313 protected slots:
00314 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00315 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00316 void slotGetLastMessagesResult(KMail::FolderJob *);
00317 void slotProgress(unsigned long done, unsigned long total);
00318 void slotPutProgress( unsigned long, unsigned long );
00319
00320
00321 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00322
00323
00324 void slotConnectionResult( int errorCode, const QString& errorMsg );
00325
00326 void slotCheckUidValidityResult( KMail::FolderJob* job );
00327 void slotPermanentFlags( int flags );
00328 void slotTestAnnotationResult(KIO::Job *job);
00329 void slotGetAnnotationResult( KIO::Job* );
00330 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00331 void slotSetAnnotationResult(KIO::Job *job);
00332 void slotReceivedUserRights( KMFolder* );
00333 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00334
00335 void slotMultiSetACLResult(KIO::Job *);
00336 void slotACLChanged( const QString&, int );
00337 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00338 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00339 void slotDeleteMessagesResult(KMail::FolderJob *);
00340 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00341 void slotStorageQuotaResult( const QuotaInfo& );
00342 void slotQuotaResult( KIO::Job* job );
00343
00344 protected:
00345
00346
00347 bool deleteMessages();
00348 void listMessages();
00349 void uploadNewMessages();
00350 void uploadFlags();
00351 void uploadSeenFlags();
00352 void createNewFolders();
00353
00354 void listDirectory2();
00355 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00356
00357
00360 virtual QValueList<unsigned long> findNewMessages();
00363 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00364
00366 virtual bool canRemoveFolder() const;
00367
00369 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00370 QString partSpecifier, const AttachmentStrategy *as ) const;
00371 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00372 FolderJob::JobType jt, KMFolder *folder ) const;
00373
00374 virtual void timerEvent( QTimerEvent* );
00375
00376
00377 void newState( int progress, const QString& syncStatus );
00378
00380 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00381
00382
00383
00384 public slots:
00388 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00389
00393 void slotTroubleshoot();
00394
00399 void slotListResult( const QStringList&, const QStringList&,
00400 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00401
00406 void slotCheckNamespace( const QStringList&, const QStringList&,
00407 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00408
00409 private slots:
00410 void serverSyncInternal();
00411 void slotIncreaseProgress();
00412 void slotUpdateLastUid();
00413 void slotFolderDeletionOnServerFinished();
00414 void slotRescueDone( KMCommand* command );
00415
00416 signals:
00417 void folderComplete(KMFolderCachedImap *folder, bool success);
00418 void listComplete( KMFolderCachedImap* );
00419
00423 void syncState( int state, int number );
00424
00425 private:
00426 void setReadOnly( bool readOnly );
00427 QString state2String( int state ) const;
00428 void rememberDeletion( int );
00433 KMCommand* rescueUnsyncedMessages();
00435 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00436
00438 enum {
00439 SYNC_STATE_INITIAL,
00440 SYNC_STATE_TEST_ANNOTATIONS,
00441 SYNC_STATE_PUT_MESSAGES,
00442 SYNC_STATE_UPLOAD_FLAGS,
00443 SYNC_STATE_CREATE_SUBFOLDERS,
00444 SYNC_STATE_LIST_NAMESPACES,
00445 SYNC_STATE_LIST_SUBFOLDERS,
00446 SYNC_STATE_LIST_SUBFOLDERS2,
00447 SYNC_STATE_DELETE_SUBFOLDERS,
00448 SYNC_STATE_LIST_MESSAGES,
00449 SYNC_STATE_DELETE_MESSAGES,
00450 SYNC_STATE_EXPUNGE_MESSAGES,
00451 SYNC_STATE_GET_MESSAGES,
00452 SYNC_STATE_HANDLE_INBOX,
00453 SYNC_STATE_GET_USERRIGHTS,
00454 SYNC_STATE_GET_ANNOTATIONS,
00455 SYNC_STATE_SET_ANNOTATIONS,
00456 SYNC_STATE_GET_ACLS,
00457 SYNC_STATE_SET_ACLS,
00458 SYNC_STATE_GET_QUOTA,
00459 SYNC_STATE_FIND_SUBFOLDERS,
00460 SYNC_STATE_SYNC_SUBFOLDERS,
00461 SYNC_STATE_CHECK_UIDVALIDITY,
00462 SYNC_STATE_RENAME_FOLDER
00463 } mSyncState;
00464
00465 int mProgress;
00466 int mStatusFlagsJobs;
00467
00468 QString mUidValidity;
00469 QString mImapPath;
00470 imapState mContentState, mSubfolderState;
00471 QStringList mSubfolderNames, mSubfolderPaths,
00472 mSubfolderMimeTypes, mSubfolderAttributes;
00473 QString mFolderAttributes;
00474 QString mAnnotationFolderType;
00475 IncidencesFor mIncidencesFor;
00476
00477 bool mHasInbox;
00478 bool mIsSelected;
00479 bool mCheckFlags;
00480 bool mReadOnly;
00481 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00482
00483 QIntDict<int> uidsOnServer;
00484 QValueList<ulong> uidsForDeletionOnServer;
00485 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00486 QValueList<ulong> mUidsForDownload;
00487 QStringList foldersForDeletionOnServer;
00488
00489 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00490 KMFolderCachedImap* mCurrentSubfolder;
00491
00495 QMap<ulong,int> uidMap;
00496 bool uidMapDirty;
00497 void reloadUidMap();
00498 int uidWriteTimer;
00499
00509 ulong mLastUid;
00514 ulong mTentativeHighestUid;
00515
00519 bool mFoundAnIMAPDigest;
00520
00521 int mUserRights, mOldUserRights;
00522 ACLList mACLList;
00523
00524 bool mSilentUpload;
00525 bool mFolderRemoved;
00526
00527 bool mRecurse;
00532 bool mStatusChangedLocally;
00534 bool mAnnotationFolderTypeChanged;
00536 bool mIncidencesForChanged;
00537
00538 QStringList mNamespacesToList;
00539 int mNamespacesToCheck;
00540 bool mPersonalNamespacesCheckDone;
00541 QString mImapPathCreation;
00542
00543 QuotaInfo mQuotaInfo;
00544 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00545 bool mAlarmsBlocked;
00546
00547 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00548 int mRescueCommandCount;
00549
00550 int mPermanentFlags;
00551 };
00552
00553 #endif