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
00188
00189 virtual KMMessage* take(int idx);
00190
00191 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00192
00193 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00194 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00195 return addMsgInternal(msg, false, index_return);
00196 }
00197
00198
00199 virtual void removeMsg(int i, bool imapQuiet = false);
00200 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00201 { FolderStorage::removeMsg(msgList, imapQuiet); }
00202
00204 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00205 bool canDeleteMessages() const;
00206
00207
00211 void sendFolderComplete(bool success)
00212 { emit folderComplete(this, success); }
00213
00217 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00218 bool silentUpload() { return mSilentUpload; }
00219
00220 virtual int createIndexFromContents() {
00221 const int result = KMFolderMaildir::createIndexFromContents();
00222 reloadUidMap();
00223 return result;
00224 }
00225
00226 int createIndexFromContentsRecursive();
00227
00228
00229
00235 virtual bool listDirectory();
00236
00237 virtual void listNamespaces();
00238
00240 KMFolder* trashFolder() const;
00241
00246 int userRights() const { return mUserRights; }
00247
00249 void setUserRights( unsigned int userRights );
00250
00260 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00261 void setQuotaInfo( const QuotaInfo & );
00262
00264 typedef QValueVector<KMail::ACLListEntry> ACLList;
00265 const ACLList& aclList() const { return mACLList; }
00266
00268 void setACLList( const ACLList& arr );
00269
00270
00271 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00272 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00273
00274 QString annotationFolderType() const { return mAnnotationFolderType; }
00275
00276
00277 void updateAnnotationFolderType();
00278
00287 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00288
00289 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00291 void setIncidencesFor( IncidencesFor incfor );
00292
00294 bool sharedSeenFlags() const { return mSharedSeenFlags; }
00296 void setSharedSeenFlags( bool b );
00297
00299 virtual bool isMoveable() const;
00300
00305 QStringList namespacesToList() { return mNamespacesToList; }
00306 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00307
00312 const QString& imapPathForCreation() { return mImapPathCreation; }
00313 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00314
00316 bool isCloseToQuota() const;
00317
00319 int permanentFlags() const { return mPermanentFlags; }
00320
00321
00322 QString folderAttributes() const { return mFolderAttributes; }
00323
00324 protected slots:
00325 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00326 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00327 void slotGetLastMessagesResult(KMail::FolderJob *);
00328 void slotProgress(unsigned long done, unsigned long total);
00329 void slotPutProgress( unsigned long, unsigned long );
00330
00331
00332 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00333
00334
00335 void slotConnectionResult( int errorCode, const QString& errorMsg );
00336
00337 void slotCheckUidValidityResult( KMail::FolderJob* job );
00338 void slotPermanentFlags( int flags );
00339 void slotTestAnnotationResult(KIO::Job *job);
00340 void slotGetAnnotationResult( KIO::Job* );
00341 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00342 void slotSetAnnotationResult(KIO::Job *job);
00343 void slotReceivedUserRights( KMFolder* );
00344 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00345
00346 void slotMultiSetACLResult(KIO::Job *);
00347 void slotACLChanged( const QString&, int );
00348 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00349 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00350 void slotDeleteMessagesResult(KMail::FolderJob *);
00351 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00352 void slotStorageQuotaResult( const QuotaInfo& );
00353 void slotQuotaResult( KIO::Job* job );
00354
00355 protected:
00356
00357
00358 bool deleteMessages();
00359 void listMessages();
00360 void uploadNewMessages();
00361 void uploadFlags();
00362 void uploadSeenFlags();
00363 void createNewFolders();
00364
00365 void listDirectory2();
00366 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00367
00368
00371 virtual QValueList<unsigned long> findNewMessages();
00374 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00375
00377 virtual bool canRemoveFolder() const;
00378
00380 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00381 QString partSpecifier, const AttachmentStrategy *as ) const;
00382 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00383 FolderJob::JobType jt, KMFolder *folder ) const;
00384
00385 virtual void timerEvent( QTimerEvent* );
00386
00387
00388 void newState( int progress, const QString& syncStatus );
00389
00391 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00392
00393
00394
00395 public slots:
00399 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00400
00404 void slotTroubleshoot();
00405
00410 void slotListResult( const QStringList&, const QStringList&,
00411 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00412
00417 void slotCheckNamespace( const QStringList&, const QStringList&,
00418 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00419
00420 private slots:
00421 void serverSyncInternal();
00422 void slotIncreaseProgress();
00423 void slotUpdateLastUid();
00424 void slotFolderDeletionOnServerFinished();
00425 void slotRescueDone( KMCommand* command );
00426
00427 signals:
00428 void folderComplete(KMFolderCachedImap *folder, bool success);
00429 void listComplete( KMFolderCachedImap* );
00430
00434 void syncState( int state, int number );
00435
00436 private:
00437 void setReadOnly( bool readOnly );
00438 QString state2String( int state ) const;
00439 void rememberDeletion( int );
00444 KMCommand* rescueUnsyncedMessages();
00446 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00447
00449 enum {
00450 SYNC_STATE_INITIAL,
00451 SYNC_STATE_TEST_ANNOTATIONS,
00452 SYNC_STATE_PUT_MESSAGES,
00453 SYNC_STATE_UPLOAD_FLAGS,
00454 SYNC_STATE_CREATE_SUBFOLDERS,
00455 SYNC_STATE_LIST_NAMESPACES,
00456 SYNC_STATE_LIST_SUBFOLDERS,
00457 SYNC_STATE_LIST_SUBFOLDERS2,
00458 SYNC_STATE_DELETE_SUBFOLDERS,
00459 SYNC_STATE_LIST_MESSAGES,
00460 SYNC_STATE_DELETE_MESSAGES,
00461 SYNC_STATE_EXPUNGE_MESSAGES,
00462 SYNC_STATE_GET_MESSAGES,
00463 SYNC_STATE_HANDLE_INBOX,
00464 SYNC_STATE_GET_USERRIGHTS,
00465 SYNC_STATE_GET_ANNOTATIONS,
00466 SYNC_STATE_SET_ANNOTATIONS,
00467 SYNC_STATE_GET_ACLS,
00468 SYNC_STATE_SET_ACLS,
00469 SYNC_STATE_GET_QUOTA,
00470 SYNC_STATE_FIND_SUBFOLDERS,
00471 SYNC_STATE_SYNC_SUBFOLDERS,
00472 SYNC_STATE_CHECK_UIDVALIDITY,
00473 SYNC_STATE_RENAME_FOLDER
00474 } mSyncState;
00475
00476 int mProgress;
00477 int mStatusFlagsJobs;
00478
00479 QString mUidValidity;
00480 QString mImapPath;
00481 imapState mContentState, mSubfolderState;
00482 QStringList mSubfolderNames, mSubfolderPaths,
00483 mSubfolderMimeTypes, mSubfolderAttributes;
00484 QString mFolderAttributes;
00485 QString mAnnotationFolderType;
00486 IncidencesFor mIncidencesFor;
00487 bool mSharedSeenFlags;
00488
00489 bool mHasInbox;
00490 bool mIsSelected;
00491 bool mCheckFlags;
00492 bool mReadOnly;
00493 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00494
00495 QIntDict<int> uidsOnServer;
00496 QValueList<ulong> uidsForDeletionOnServer;
00497 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00498 QValueList<ulong> mUidsForDownload;
00499 QStringList foldersForDeletionOnServer;
00500
00501 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00502 KMFolderCachedImap* mCurrentSubfolder;
00503
00507 QMap<ulong,int> uidMap;
00508 bool uidMapDirty;
00509 void reloadUidMap();
00510 int uidWriteTimer;
00511
00521 ulong mLastUid;
00526 ulong mTentativeHighestUid;
00527
00531 bool mFoundAnIMAPDigest;
00532
00533 int mUserRights, mOldUserRights;
00534 ACLList mACLList;
00535
00536 bool mSilentUpload;
00537 bool mFolderRemoved;
00538
00539 bool mRecurse;
00540
00542 bool mAnnotationFolderTypeChanged;
00544 bool mIncidencesForChanged;
00546 bool mSharedSeenFlagsChanged;
00547
00554 std::set<ulong> mUIDsOfLocallyChangedStatuses;
00555
00560 bool mStatusChangedLocally;
00561
00562 QStringList mNamespacesToList;
00563 int mNamespacesToCheck;
00564 bool mPersonalNamespacesCheckDone;
00565 QString mImapPathCreation;
00566
00567 QuotaInfo mQuotaInfo;
00568 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00569 bool mAlarmsBlocked;
00570
00571 QValueList<KMFolder*> mToBeDeletedAfterRescue;
00572 int mRescueCommandCount;
00573
00574 int mPermanentFlags;
00575 };
00576
00577 #endif