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 const int result = KMFolderMaildir::createIndexFromContents();
00219 reloadUidMap();
00220 return result;
00221 }
00222
00223 int createIndexFromContentsRecursive();
00224
00225
00226
00232 virtual bool listDirectory();
00233
00234 virtual void listNamespaces();
00235
00237 KMFolder* trashFolder() const;
00238
00243 int userRights() const { return mUserRights; }
00244
00246 void setUserRights( unsigned int userRights );
00247
00257 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00258 void setQuotaInfo( const QuotaInfo & );
00259
00261 typedef QValueVector<KMail::ACLListEntry> ACLList;
00262 const ACLList& aclList() const { return mACLList; }
00263
00265 void setACLList( const ACLList& arr );
00266
00267
00268 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00269 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00270
00271 QString annotationFolderType() const { return mAnnotationFolderType; }
00272
00273
00274 void updateAnnotationFolderType();
00275
00284 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00285
00286 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00288 void setIncidencesFor( IncidencesFor incfor );
00289
00291 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00293 void setSharedSeenFlags( bool b );
00294
00296 virtual bool isMoveable() const;
00297
00302 QStringList namespacesToList() { return mNamespacesToList; }
00303 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00304
00309 const QString& imapPathForCreation() { return mImapPathCreation; }
00310 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00311
00313 bool isCloseToQuota() const;
00314
00316 int permanentFlags() const { return mPermanentFlags; }
00317
00318
00319 QString folderAttributes() const { return mFolderAttributes; }
00320
00321 protected slots:
00322 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00323 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00324 void slotGetLastMessagesResult(KMail::FolderJob *);
00325 void slotProgress(unsigned long done, unsigned long total);
00326 void slotPutProgress( unsigned long, unsigned long );
00327
00328
00329 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00330
00331
00332 void slotConnectionResult( int errorCode, const QString& errorMsg );
00333
00334 void slotCheckUidValidityResult( KMail::FolderJob* job );
00335 void slotPermanentFlags( int flags );
00336 void slotTestAnnotationResult(KIO::Job *job);
00337 void slotGetAnnotationResult( KIO::Job* );
00338 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00339 void slotSetAnnotationResult(KIO::Job *job);
00340 void slotReceivedUserRights( KMFolder* );
00341 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00342
00343 void slotMultiSetACLResult(KIO::Job *);
00344 void slotACLChanged( const QString&, int );
00345 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00346 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00347 void slotDeleteMessagesResult(KMail::FolderJob *);
00348 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00349 void slotStorageQuotaResult( const QuotaInfo& );
00350 void slotQuotaResult( KIO::Job* job );
00351
00352 protected:
00353
00354
00355 bool deleteMessages();
00356 void listMessages();
00357 void uploadNewMessages();
00358 void uploadFlags();
00359 void uploadSeenFlags();
00360 void createNewFolders();
00361
00362 void listDirectory2();
00363 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00364
00365
00368 virtual QValueList<unsigned long> findNewMessages();
00371 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00372
00374 virtual bool canRemoveFolder() const;
00375
00377 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00378 QString partSpecifier, const AttachmentStrategy *as ) const;
00379 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00380 FolderJob::JobType jt, KMFolder *folder ) const;
00381
00382 virtual void timerEvent( QTimerEvent* );
00383
00384
00385 void newState( int progress, const QString& syncStatus );
00386
00388 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00389
00390
00391
00392 public slots:
00396 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00397
00401 void slotTroubleshoot();
00402
00407 void slotListResult( const QStringList&, const QStringList&,
00408 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00409
00414 void slotCheckNamespace( const QStringList&, const QStringList&,
00415 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00416
00417 private slots:
00418 void serverSyncInternal();
00419 void slotIncreaseProgress();
00420 void slotUpdateLastUid();
00421 void slotFolderDeletionOnServerFinished();
00422 void slotRescueDone( KMCommand* command );
00423
00424 signals:
00425 void folderComplete(KMFolderCachedImap *folder, bool success);
00426 void listComplete( KMFolderCachedImap* );
00427
00431 void syncState( int state, int number );
00432
00433 private:
00434 void setReadOnly( bool readOnly );
00435 QString state2String( int state ) const;
00436 void rememberDeletion( int );
00441 KMCommand* rescueUnsyncedMessages();
00443 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00444
00446 enum {
00447 SYNC_STATE_INITIAL,
00448 SYNC_STATE_TEST_ANNOTATIONS,
00449 SYNC_STATE_PUT_MESSAGES,
00450 SYNC_STATE_UPLOAD_FLAGS,
00451 SYNC_STATE_CREATE_SUBFOLDERS,
00452 SYNC_STATE_LIST_NAMESPACES,
00453 SYNC_STATE_LIST_SUBFOLDERS,
00454 SYNC_STATE_LIST_SUBFOLDERS2,
00455 SYNC_STATE_DELETE_SUBFOLDERS,
00456 SYNC_STATE_LIST_MESSAGES,
00457 SYNC_STATE_DELETE_MESSAGES,
00458 SYNC_STATE_EXPUNGE_MESSAGES,
00459 SYNC_STATE_GET_MESSAGES,
00460 SYNC_STATE_HANDLE_INBOX,
00461 SYNC_STATE_GET_USERRIGHTS,
00462 SYNC_STATE_GET_ANNOTATIONS,
00463 SYNC_STATE_SET_ANNOTATIONS,
00464 SYNC_STATE_GET_ACLS,
00465 SYNC_STATE_SET_ACLS,
00466 SYNC_STATE_GET_QUOTA,
00467 SYNC_STATE_FIND_SUBFOLDERS,
00468 SYNC_STATE_SYNC_SUBFOLDERS,
00469 SYNC_STATE_CHECK_UIDVALIDITY,
00470 SYNC_STATE_RENAME_FOLDER
00471 } mSyncState;
00472
00473 int mProgress;
00474 int mStatusFlagsJobs;
00475
00476 QString mUidValidity;
00477 QString mImapPath;
00478 imapState mContentState, mSubfolderState;
00479 QStringList mSubfolderNames, mSubfolderPaths,
00480 mSubfolderMimeTypes, mSubfolderAttributes;
00481 QString mFolderAttributes;
00482 QString mAnnotationFolderType;
00483 IncidencesFor mIncidencesFor;
00484 bool mSharedSeenFlags;
00485
00486 bool mHasInbox;
00487 bool mIsSelected;
00488 bool mCheckFlags;
00489 bool mReadOnly;
00490 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00491
00492 QIntDict<int> uidsOnServer;
00493 QValueList<ulong> uidsForDeletionOnServer;
00494 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00495 QValueList<ulong> mUidsForDownload;
00496 QStringList foldersForDeletionOnServer;
00497
00498 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00499 KMFolderCachedImap* mCurrentSubfolder;
00500
00504 QMap<ulong,int> uidMap;
00505 bool uidMapDirty;
00506 void reloadUidMap();
00507 int uidWriteTimer;
00508
00518 ulong mLastUid;
00523 ulong mTentativeHighestUid;
00524
00528 bool mFoundAnIMAPDigest;
00529
00530 int mUserRights, mOldUserRights;
00531 ACLList mACLList;
00532
00533 bool mSilentUpload;
00534 bool mFolderRemoved;
00535
00536 bool mRecurse;
00541 bool mStatusChangedLocally;
00543 bool mAnnotationFolderTypeChanged;
00545 bool mIncidencesForChanged;
00547 bool mSharedSeenFlagsChanged;
00548
00549 QStringList mNamespacesToList;
00550 int mNamespacesToCheck;
00551 bool mPersonalNamespacesCheckDone;
00552 QString mImapPathCreation;
00553
00554 QuotaInfo mQuotaInfo;
00555 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00556 bool mAlarmsBlocked;
00557
00558 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00559 int mRescueCommandCount;
00560
00561 int mPermanentFlags;
00562 };
00563
00564 #endif