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
00203
00207 void sendFolderComplete(bool success)
00208 { emit folderComplete(this, success); }
00209
00213 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00214 bool silentUpload() { return mSilentUpload; }
00215
00216 virtual int createIndexFromContents() {
00217 const int result = KMFolderMaildir::createIndexFromContents();
00218 reloadUidMap();
00219 return result;
00220 }
00221
00222 int createIndexFromContentsRecursive();
00223
00224
00225
00231 virtual bool listDirectory();
00232
00233 virtual void listNamespaces();
00234
00236 KMFolder* trashFolder() const;
00237
00242 int userRights() const { return mUserRights; }
00243
00245 void setUserRights( unsigned int userRights );
00246
00256 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00257 void setQuotaInfo( const QuotaInfo & );
00258
00260 typedef QValueVector<KMail::ACLListEntry> ACLList;
00261 const ACLList& aclList() const { return mACLList; }
00262
00264 void setACLList( const ACLList& arr );
00265
00266
00267 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00268 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00269
00270 QString annotationFolderType() const { return mAnnotationFolderType; }
00271
00272
00273 void updateAnnotationFolderType();
00274
00283 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00284
00285 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00287 void setIncidencesFor( IncidencesFor incfor );
00288
00290 virtual bool isMoveable() const;
00291
00296 QStringList namespacesToList() { return mNamespacesToList; }
00297 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00298
00303 const QString& imapPathForCreation() { return mImapPathCreation; }
00304 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00305
00307 bool isCloseToQuota() const;
00308
00310 int permanentFlags() const { return mPermanentFlags; }
00311
00312
00313 QString folderAttributes() const { return mFolderAttributes; }
00314
00315 protected slots:
00316 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00317 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00318 void slotGetLastMessagesResult(KMail::FolderJob *);
00319 void slotProgress(unsigned long done, unsigned long total);
00320 void slotPutProgress( unsigned long, unsigned long );
00321
00322
00323 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00324
00325
00326 void slotConnectionResult( int errorCode, const QString& errorMsg );
00327
00328 void slotCheckUidValidityResult( KMail::FolderJob* job );
00329 void slotPermanentFlags( int flags );
00330 void slotTestAnnotationResult(KIO::Job *job);
00331 void slotGetAnnotationResult( KIO::Job* );
00332 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00333 void slotSetAnnotationResult(KIO::Job *job);
00334 void slotReceivedUserRights( KMFolder* );
00335 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00336
00337 void slotMultiSetACLResult(KIO::Job *);
00338 void slotACLChanged( const QString&, int );
00339 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00340 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00341 void slotDeleteMessagesResult(KMail::FolderJob *);
00342 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00343 void slotStorageQuotaResult( const QuotaInfo& );
00344 void slotQuotaResult( KIO::Job* job );
00345
00346 protected:
00347
00348
00349 bool deleteMessages();
00350 void listMessages();
00351 void uploadNewMessages();
00352 void uploadFlags();
00353 void uploadSeenFlags();
00354 void createNewFolders();
00355
00356 void listDirectory2();
00357 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00358
00359
00362 virtual QValueList<unsigned long> findNewMessages();
00365 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00366
00368 virtual bool canRemoveFolder() const;
00369
00371 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00372 QString partSpecifier, const AttachmentStrategy *as ) const;
00373 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00374 FolderJob::JobType jt, KMFolder *folder ) const;
00375
00376 virtual void timerEvent( QTimerEvent* );
00377
00378
00379 void newState( int progress, const QString& syncStatus );
00380
00382 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00383
00384
00385
00386 public slots:
00390 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00391
00395 void slotTroubleshoot();
00396
00401 void slotListResult( const QStringList&, const QStringList&,
00402 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00403
00408 void slotCheckNamespace( const QStringList&, const QStringList&,
00409 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00410
00411 private slots:
00412 void serverSyncInternal();
00413 void slotIncreaseProgress();
00414 void slotUpdateLastUid();
00415 void slotFolderDeletionOnServerFinished();
00416 void slotRescueDone( KMCommand* command );
00417
00418 signals:
00419 void folderComplete(KMFolderCachedImap *folder, bool success);
00420 void listComplete( KMFolderCachedImap* );
00421
00425 void syncState( int state, int number );
00426
00427 private:
00428 void setReadOnly( bool readOnly );
00429 QString state2String( int state ) const;
00430 void rememberDeletion( int );
00435 KMCommand* rescueUnsyncedMessages();
00437 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00438
00440 enum {
00441 SYNC_STATE_INITIAL,
00442 SYNC_STATE_TEST_ANNOTATIONS,
00443 SYNC_STATE_PUT_MESSAGES,
00444 SYNC_STATE_UPLOAD_FLAGS,
00445 SYNC_STATE_CREATE_SUBFOLDERS,
00446 SYNC_STATE_LIST_NAMESPACES,
00447 SYNC_STATE_LIST_SUBFOLDERS,
00448 SYNC_STATE_LIST_SUBFOLDERS2,
00449 SYNC_STATE_DELETE_SUBFOLDERS,
00450 SYNC_STATE_LIST_MESSAGES,
00451 SYNC_STATE_DELETE_MESSAGES,
00452 SYNC_STATE_EXPUNGE_MESSAGES,
00453 SYNC_STATE_GET_MESSAGES,
00454 SYNC_STATE_HANDLE_INBOX,
00455 SYNC_STATE_GET_USERRIGHTS,
00456 SYNC_STATE_GET_ANNOTATIONS,
00457 SYNC_STATE_SET_ANNOTATIONS,
00458 SYNC_STATE_GET_ACLS,
00459 SYNC_STATE_SET_ACLS,
00460 SYNC_STATE_GET_QUOTA,
00461 SYNC_STATE_FIND_SUBFOLDERS,
00462 SYNC_STATE_SYNC_SUBFOLDERS,
00463 SYNC_STATE_CHECK_UIDVALIDITY,
00464 SYNC_STATE_RENAME_FOLDER
00465 } mSyncState;
00466
00467 int mProgress;
00468 int mStatusFlagsJobs;
00469
00470 QString mUidValidity;
00471 QString mImapPath;
00472 imapState mContentState, mSubfolderState;
00473 QStringList mSubfolderNames, mSubfolderPaths,
00474 mSubfolderMimeTypes, mSubfolderAttributes;
00475 QString mFolderAttributes;
00476 QString mAnnotationFolderType;
00477 IncidencesFor mIncidencesFor;
00478
00479 bool mHasInbox;
00480 bool mIsSelected;
00481 bool mCheckFlags;
00482 bool mReadOnly;
00483 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00484
00485 QIntDict<int> uidsOnServer;
00486 QValueList<ulong> uidsForDeletionOnServer;
00487 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00488 QValueList<ulong> mUidsForDownload;
00489 QStringList foldersForDeletionOnServer;
00490
00491 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00492 KMFolderCachedImap* mCurrentSubfolder;
00493
00497 QMap<ulong,int> uidMap;
00498 bool uidMapDirty;
00499 void reloadUidMap();
00500 int uidWriteTimer;
00501
00511 ulong mLastUid;
00516 ulong mTentativeHighestUid;
00517
00521 bool mFoundAnIMAPDigest;
00522
00523 int mUserRights, mOldUserRights;
00524 ACLList mACLList;
00525
00526 bool mSilentUpload;
00527 bool mFolderRemoved;
00528
00529 bool mRecurse;
00534 bool mStatusChangedLocally;
00536 bool mAnnotationFolderTypeChanged;
00538 bool mIncidencesForChanged;
00539
00540 QStringList mNamespacesToList;
00541 int mNamespacesToCheck;
00542 bool mPersonalNamespacesCheckDone;
00543 QString mImapPathCreation;
00544
00545 QuotaInfo mQuotaInfo;
00546 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00547 bool mAlarmsBlocked;
00548
00549 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00550 int mRescueCommandCount;
00551
00552 int mPermanentFlags;
00553 };
00554
00555 #endif