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 void slotChanged();
00083 private:
00084 QRadioButton *mIndexButton, *mCacheButton;
00085 QComboBox *mIndexScope;
00086 QButtonGroup *mButtonGroup;
00087 int rc;
00088 };
00089
00090 class KMFolderCachedImap : public KMFolderMaildir
00091 {
00092 Q_OBJECT
00093
00094 public:
00095 static QString cacheLocation() {
00096 return locateLocal("data", "kmail/dimap" );
00097 }
00098
00102 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00103 virtual ~KMFolderCachedImap();
00104
00106 void reallyDoClose(const char* owner);
00107
00109 void initializeFrom( KMFolderCachedImap* parent );
00110
00111 virtual void readConfig();
00112 virtual void writeConfig();
00113
00114 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00115
00117 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00118
00120 virtual int create();
00121
00123 virtual void remove();
00124
00126 virtual void serverSync( bool recurse );
00127
00129 void resetSyncState( );
00130
00134 void setAlarmsBlocked( bool blocked );
00136 bool alarmsBlocked() const;
00137
00138 void checkUidValidity();
00139
00140 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00141
00142 virtual imapState getContentState() { return mContentState; }
00143 virtual void setContentState(imapState state) { mContentState = state; }
00144
00145 virtual imapState getSubfolderState() { return mSubfolderState; }
00146 virtual void setSubfolderState(imapState state);
00147
00149 void setImapPath(const QString &path);
00150 QString imapPath() const { return mImapPath; }
00151
00153 void setLastUid( ulong uid );
00154 ulong lastUid();
00155
00157 KMMsgBase* findByUID( ulong uid );
00158
00160 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00161 QString uidValidity() const { return mUidValidity; }
00162
00165 void clearUidMap() { uidMap.clear(); }
00166
00168 void setAccount(KMAcctCachedImap *acct);
00169 KMAcctCachedImap* account() const;
00170
00172 QString uidCacheLocation() const;
00173
00175 int readUidCache();
00176
00178 int writeUidCache();
00179
00181 int progress() const { return mProgress; }
00182
00183
00184 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00185
00186
00187 virtual KMMessage* take(int idx);
00188
00189 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00190
00191 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00192 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00193 return addMsgInternal(msg, false, index_return);
00194 }
00195
00196
00197 virtual void removeMsg(int i, bool imapQuiet = false);
00198 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00199 { FolderStorage::removeMsg(msgList, imapQuiet); }
00200
00202 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00203 bool canDeleteMessages() const;
00204
00205
00209 void sendFolderComplete(bool success)
00210 { emit folderComplete(this, success); }
00211
00215 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00216 bool silentUpload() { return mSilentUpload; }
00217
00218 virtual int createIndexFromContents() {
00219 const int result = KMFolderMaildir::createIndexFromContents();
00220 reloadUidMap();
00221 return result;
00222 }
00223
00224 int createIndexFromContentsRecursive();
00225
00226
00227
00233 virtual bool listDirectory();
00234
00235 virtual void listNamespaces();
00236
00238 KMFolder* trashFolder() const;
00239
00244 int userRights() const { return mUserRights; }
00245
00247 void setUserRights( unsigned int userRights );
00248
00258 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00259 void setQuotaInfo( const QuotaInfo & );
00260
00262 typedef QValueVector<KMail::ACLListEntry> ACLList;
00263 const ACLList& aclList() const { return mACLList; }
00264
00266 void setACLList( const ACLList& arr );
00267
00268
00269 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00270 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00271
00272 QString annotationFolderType() const { return mAnnotationFolderType; }
00273
00274
00275 void updateAnnotationFolderType();
00276
00285 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00286
00287 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00289 void setIncidencesFor( IncidencesFor incfor );
00290
00292 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00294 void setSharedSeenFlags( bool b );
00295
00297 virtual bool isMoveable() const;
00298
00303 QStringList namespacesToList() { return mNamespacesToList; }
00304 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00305
00310 const QString& imapPathForCreation() { return mImapPathCreation; }
00311 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00312
00314 bool isCloseToQuota() const;
00315
00317 int permanentFlags() const { return mPermanentFlags; }
00318
00319
00320 QString folderAttributes() const { return mFolderAttributes; }
00321
00322 protected slots:
00323 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00324 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00325 void slotGetLastMessagesResult(KMail::FolderJob *);
00326 void slotProgress(unsigned long done, unsigned long total);
00327 void slotPutProgress( unsigned long, unsigned long );
00328
00329
00330 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00331
00332
00333 void slotConnectionResult( int errorCode, const QString& errorMsg );
00334
00335 void slotCheckUidValidityResult( KMail::FolderJob* job );
00336 void slotPermanentFlags( int flags );
00337 void slotTestAnnotationResult(KIO::Job *job);
00338 void slotGetAnnotationResult( KIO::Job* );
00339 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00340 void slotSetAnnotationResult(KIO::Job *job);
00341 void slotReceivedUserRights( KMFolder* );
00342 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00343
00344 void slotMultiSetACLResult(KIO::Job *);
00345 void slotACLChanged( const QString&, int );
00346 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00347 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00348 void slotDeleteMessagesResult(KMail::FolderJob *);
00349 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00350 void slotStorageQuotaResult( const QuotaInfo& );
00351 void slotQuotaResult( KIO::Job* job );
00352
00353 protected:
00354
00355
00356 bool deleteMessages();
00357 void listMessages();
00358 void uploadNewMessages();
00359 void uploadFlags();
00360 void uploadSeenFlags();
00361 void createNewFolders();
00362
00363 void listDirectory2();
00364 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00365
00366
00369 virtual QValueList<unsigned long> findNewMessages();
00372 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00373
00375 virtual bool canRemoveFolder() const;
00376
00378 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00379 QString partSpecifier, const AttachmentStrategy *as ) const;
00380 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00381 FolderJob::JobType jt, KMFolder *folder ) const;
00382
00383 virtual void timerEvent( QTimerEvent* );
00384
00385
00386 void newState( int progress, const QString& syncStatus );
00387
00389 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00390
00391
00392
00393 public slots:
00397 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00398
00402 void slotTroubleshoot();
00403
00408 void slotListResult( const QStringList&, const QStringList&,
00409 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00410
00415 void slotCheckNamespace( const QStringList&, const QStringList&,
00416 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00417
00418 private slots:
00419 void serverSyncInternal();
00420 void slotIncreaseProgress();
00421 void slotUpdateLastUid();
00422 void slotFolderDeletionOnServerFinished();
00423 void slotRescueDone( KMCommand* command );
00424
00425 signals:
00426 void folderComplete(KMFolderCachedImap *folder, bool success);
00427 void listComplete( KMFolderCachedImap* );
00428
00432 void syncState( int state, int number );
00433
00434 private:
00435 void setReadOnly( bool readOnly );
00436 QString state2String( int state ) const;
00437 void rememberDeletion( int );
00442 KMCommand* rescueUnsyncedMessages();
00444 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00445
00447 enum {
00448 SYNC_STATE_INITIAL,
00449 SYNC_STATE_TEST_ANNOTATIONS,
00450 SYNC_STATE_PUT_MESSAGES,
00451 SYNC_STATE_UPLOAD_FLAGS,
00452 SYNC_STATE_CREATE_SUBFOLDERS,
00453 SYNC_STATE_LIST_NAMESPACES,
00454 SYNC_STATE_LIST_SUBFOLDERS,
00455 SYNC_STATE_LIST_SUBFOLDERS2,
00456 SYNC_STATE_DELETE_SUBFOLDERS,
00457 SYNC_STATE_LIST_MESSAGES,
00458 SYNC_STATE_DELETE_MESSAGES,
00459 SYNC_STATE_EXPUNGE_MESSAGES,
00460 SYNC_STATE_GET_MESSAGES,
00461 SYNC_STATE_HANDLE_INBOX,
00462 SYNC_STATE_GET_USERRIGHTS,
00463 SYNC_STATE_GET_ANNOTATIONS,
00464 SYNC_STATE_SET_ANNOTATIONS,
00465 SYNC_STATE_GET_ACLS,
00466 SYNC_STATE_SET_ACLS,
00467 SYNC_STATE_GET_QUOTA,
00468 SYNC_STATE_FIND_SUBFOLDERS,
00469 SYNC_STATE_SYNC_SUBFOLDERS,
00470 SYNC_STATE_CHECK_UIDVALIDITY,
00471 SYNC_STATE_RENAME_FOLDER
00472 } mSyncState;
00473
00474 int mProgress;
00475 int mStatusFlagsJobs;
00476
00477 QString mUidValidity;
00478 QString mImapPath;
00479 imapState mContentState, mSubfolderState;
00480 QStringList mSubfolderNames, mSubfolderPaths,
00481 mSubfolderMimeTypes, mSubfolderAttributes;
00482 QString mFolderAttributes;
00483 QString mAnnotationFolderType;
00484 IncidencesFor mIncidencesFor;
00485 bool mSharedSeenFlags;
00486
00487 bool mHasInbox;
00488 bool mIsSelected;
00489 bool mCheckFlags;
00490 bool mReadOnly;
00491 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00492
00493 QIntDict<int> uidsOnServer;
00494 QValueList<ulong> uidsForDeletionOnServer;
00495 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00496 QValueList<ulong> mUidsForDownload;
00497 QStringList foldersForDeletionOnServer;
00498
00499 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00500 KMFolderCachedImap* mCurrentSubfolder;
00501
00505 QMap<ulong,int> uidMap;
00506 bool uidMapDirty;
00507 void reloadUidMap();
00508 int uidWriteTimer;
00509
00519 ulong mLastUid;
00524 ulong mTentativeHighestUid;
00525
00529 bool mFoundAnIMAPDigest;
00530
00531 int mUserRights, mOldUserRights;
00532 ACLList mACLList;
00533
00534 bool mSilentUpload;
00535 bool mFolderRemoved;
00536
00537 bool mRecurse;
00538
00540 bool mAnnotationFolderTypeChanged;
00542 bool mIncidencesForChanged;
00544 bool mSharedSeenFlagsChanged;
00545
00552 QValueList<ulong> mUIDsOfLocallyChangedStatuses;
00553
00558 bool mStatusChangedLocally;
00559
00560 QStringList mNamespacesToList;
00561 int mNamespacesToCheck;
00562 bool mPersonalNamespacesCheckDone;
00563 QString mImapPathCreation;
00564
00565 QuotaInfo mQuotaInfo;
00566 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00567 bool mAlarmsBlocked;
00568
00569 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00570 int mRescueCommandCount;
00571
00572 int mPermanentFlags;
00573 };
00574
00575 #endif